Exemplo n.º 1
0
        private async Task SyncronizeMetricsFromAgent(AgentInfo agentInfo)
        {
            try
            {
                var lastTime = _metricsRepository.GetMetricsLastDateFormAgent(agentInfo.AgentId).AddSeconds(1);
                var response = await _agentClient.GetMetrics(new RamMetricClientRequest
                {
                    BaseUrl  = agentInfo.AgentUrl,
                    FromTime = lastTime,
                    ToTime   = DateTimeOffset.Now
                });

                if (response == null)
                {
                    return;
                }

                foreach (var clientMetric in response.Metrics)
                {
                    var RamMetric = _mapper.Map <RamMetric>(clientMetric);
                    RamMetric.AgentId = agentInfo.AgentId;
                    _metricsRepository.Create(RamMetric);
                }

                _logger.LogDebug($"Sincronized {response.Metrics.Count} Ram Metrics from Agent ({agentInfo})");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }