Ejemplo n.º 1
0
        public AllNetworkMetricsApiResponse GetAllNetworkMetrics(GetAllNetworkMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.ToString("s") + "Z";
            var toParameter   = request.ToTime.ToString("s") + "Z";
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.ClientBaseAddress}/api/metrics/network/from/{fromParameter}/to/{toParameter}");

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

                string jsonString = response.Content.ReadAsStringAsync()
                                    .Result
                                    .Replace("\\", "")
                                    .Trim(new char[1] {
                    '"'
                });

                var allNetworkMetricsApiResponse = JsonConvert.DeserializeObject <AllNetworkMetricsApiResponse>(jsonString);

                return(allNetworkMetricsApiResponse);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public AllNetworkMetricsApiResponse GetNetworkMetrics(GetAllNetworkMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.ToString("yyyy-MM-dd HH:mm:ss");
            var toParameter   = request.ToTime.ToString("yyyy-MM-dd HH:mm:ss");
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.ClientBaseAddress.TrimEnd('/')}/api/metrics/network/from/{fromParameter}/to/{toParameter}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;
                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                return(JsonSerializer.DeserializeAsync <AllNetworkMetricsApiResponse>(responseStream).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public AllNetworkMetricsApiResponse GetAllNetworkMetrics(GetAllNetworkMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.UtcDateTime.ToString("O");
            var toParameter   = request.ToTime.UtcDateTime.ToString("O");
            var uri           = request.ClientBaseAddress;
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{uri}api/metrics/network/from/{fromParameter}/to/{toParameter}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;
                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                using var streamReader   = new StreamReader(responseStream);
                var content = streamReader.ReadToEnd();
                return(JsonConvert.DeserializeObject <AllNetworkMetricsApiResponse>(content));
            }
            catch (Exception ex)
            {
                _loggerDotNet.LogError(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 4
0
        public AllNetworkMetricApiResponse GetAllNetworkMetrics(GetAllNetworkMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.ToString("O");
            var toParameter   = request.ToTime.ToString("O");
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.ClientBaseAddress}/api/metrics/network/from/{fromParameter}/to/{toParameter}");

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

                using var responseStream = response.Content.ReadAsStreamAsync().Result;

                return(JsonSerializer.DeserializeAsync <AllNetworkMetricApiResponse>(responseStream, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }
        public Task Execute(IJobExecutionContext context)
        {
            var agentsList = _agentsRepository.GetAgentList();

            if (agentsList.Count == 0)
            {
                return(Task.CompletedTask);
            }

            foreach (var agent in agentsList)
            {
                DateTimeOffset fromTime = _repository.GetLastTime(agent.AgentId);
                DateTimeOffset toTime   = DateTimeOffset.UtcNow;

                var request = new GetAllNetworkMetricsApiRequest
                {
                    ClientBaseAddress = agent.AgentAddress,
                    FromTime          = fromTime,
                    ToTime            = toTime
                };

                var metrics = _agentClient.GetAllNetworkMetrics(request);

                if (metrics.Metrics.Count == 0)
                {
                    return(Task.CompletedTask);
                }

                foreach (var metric in metrics.Metrics)
                {
                    _repository.Create(new NetworkMetricApi {
                        Time = metric.Time, Value = metric.Value, AgentId = agent.AgentId
                    });
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
        public AllNetworkMetricsApiResponse GetAllNetworkMetrics(GetAllNetworkMetricsApiRequest request)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Get,
                                                     $"{request.Addres}/api/metrics/network/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 <AllNetworkMetricsApiResponse>(content, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }