public AllDotNetMetricsApiResponse GetDotNetMetrics(GetAllDotNetMetricsApiRequest request)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Get,
                                                     $"http://localhost:5050/api/metrics/dotnet/agent/{request.Agent}/from/{request.FromTime:o}/to/{request.ToTime:o}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;
                using (var responseStream = response.Content.ReadAsStreamAsync().Result)
                {
                    using (var streamReader = new StreamReader(responseStream))
                    {
                        var content = streamReader.ReadToEnd();
                        var result  = JsonSerializer.Deserialize <AllDotNetMetricsApiResponse>(content, new JsonSerializerOptions()
                        {
                            PropertyNameCaseInsensitive = true
                        });
                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(null);
            }
        }
        public Task Execute(IJobExecutionContext context)
        {
            var allAgentsInfo = _agentsRepository.GetAllAgentsInfo();

            foreach (var agentInfo in allAgentsInfo)
            {
                var last    = _repository.GetLast(agentInfo.AgentId);
                var request = new GetAllDotNetMetricsApiRequest()
                {
                    AgentUrl = agentInfo.AgentUrl,
                    FromTime = last,
                    ToTime   = DateTimeOffset.UtcNow,
                };

                var response = _client.GetDonNetMetrics(request);

                if (response != null)
                {
                    if (response.Metrics[0].Time == last)
                    {
                        response.Metrics.RemoveAt(0);
                    }

                    foreach (var metric in response.Metrics)
                    {
                        var formatedMetric = _mapper.Map <DotNetMetric>(metric);
                        formatedMetric.AgentId = agentInfo.AgentId;
                        _repository.Create(formatedMetric);
                    }
                }
            }

            return(Task.CompletedTask);
        }
        public List <int> GetDotNetMetrics(GetAllDotNetMetricsApiRequest request)
        {
            string content = GetMetricsApiResponseString(request, "dotnetmetrics");

            if (content != null)
            {
                return(GetValues(content));
            }
            else
            {
                return(null);
            }
        }
        public AllDotNetMetricsResponse GetDotNetMetrics(GetAllDotNetMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.LocalDateTime.ToString("O");
            var toParameter   = request.ToTime.LocalDateTime.ToString("O");
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.ClientBaseAddress}api/metrics/dotnet/errors-count/from/{fromParameter}/to/{toParameter}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;

                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                return(JsonSerializer.DeserializeAsync <AllDotNetMetricsResponse>(responseStream,
                                                                                  new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }