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

                if (response == null)
                {
                    return;
                }

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

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