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

                if (response == null)
                {
                    return;
                }

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

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