Example #1
0
        public AllCpuMetricsApiResponse GetAllCpuMetrics(GetAllCpuMetricsApiRequest 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/cpu/from/{fromParameter}/to/{toParameter}");

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

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

                var allCpuMetricsApiResponse = JsonConvert.DeserializeObject <AllCpuMetricsApiResponse>(jsonString);

                return(allCpuMetricsApiResponse);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public AllCpuMetricsApiResponse GetCpuMetrics(GetAllCpuMetricsApiRequest request)
        {
            string content = GetMetricsApiResponseString(request, Strings.TableNames[(int)Enums.MetricsNames.Cpu]);

            if (content != null)
            {
                return(JsonConvert.DeserializeObject <AllCpuMetricsApiResponse>(content));
            }
            else
            {
                _logger.LogError("null content");
                return(null);
            }
        }
Example #3
0
        public AllCpuMetricsApiResponse GetCpuMetrics(GetAllCpuMetricsApiRequest 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/cpu/from/{fromParameter}/to/{toParameter}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;
                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                return(JsonSerializer.DeserializeAsync <AllCpuMetricsApiResponse>(responseStream).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }
        public AllCpuMetricsApiResponse GetCpuMetrics(GetAllCpuMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.ToUnixTimeSeconds();
            var toParameter   = request.ToTime.ToUnixTimeSeconds();
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.AgentUrl}/api/cpumetrics/from/{fromParameter}/to/{toParameter}");

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

                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                return(JsonSerializer.DeserializeAsync <AllCpuMetricsApiResponse>(responseStream).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(null);
        }
Example #5
0
        public AllCpuMetricsApiResponse GetAllCpuMetrics(GetAllCpuMetricsApiRequest 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/cpu/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 <AllCpuMetricsApiResponse>(content));
            }
            catch (Exception ex)
            {
                _loggerCpu.LogError(ex.Message);
                return(null);
            }
        }
Example #6
0
        public AllCpuMetricApiResponse GetAllCpuMetrics(GetAllCpuMetricsApiRequest request)
        {
            var fromParameter = request.FromTime.ToString("O");
            var toParameter   = request.ToTime.ToString("O");
            var httpRequest   = new HttpRequestMessage(HttpMethod.Get, $"{request.ClientBaseAddress}/api/metrics/cpu/from/{fromParameter}/to/{toParameter}");

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

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

                return(JsonSerializer.DeserializeAsync <AllCpuMetricApiResponse>(responseStream, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }).Result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }
Example #7
0
        public AllCpuMetricsApiResponse GetAllCpuMetrics(GetAllCpuMetricsApiRequest request)
        {
            var httpRequest = new HttpRequestMessage(HttpMethod.Get,
                                                     $"{request.Addres}/api/metrics/cpu/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 <AllCpuMetricsApiResponse>(content, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(null);
        }