using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public string __name__ { get; set; }
public string core { get; set; }
public string instance { get; set; }
public string job { get; set; }
public Metric metric { get; set; }
public IList<object> value { get; set; }
public string resultType { get; set; }
public IList<Result> result { get; set; }
public class CpuUsageResponse
public string status { get; set; }
public Data data { get; set; }
public static void Test()
var apiResponse = GetJson();
CpuUsageResponse dataGetAll;
dataGetAll = JsonConvert.DeserializeObject<CpuUsageResponse>(apiResponse);
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberGroupSeparator = ".";
foreach(CpuUsageResponse x in dataGetAll)
sum1 += Convert.ToDouble(x.data.result[1].value[1], provider);
var json = @"{""status"":""success"",""data"":{""resultType"":""vector"",""result"":[{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,0"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""79186.65625""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,1"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""85518.546875""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,2"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""77787.5625""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,3"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""84295.765625""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,4"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""80077.3125""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,5"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""84062.078125""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,6"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""82094.75""]},{""metric"":{""__name__"":""wmi_cpu_time_total"",""core"":""0,7"",""instance"":""192.168.1.101:9182"",""job"":""Server-monitoring-Api""},""value"":[1583851813.666,""73822.078125""]}]}}";
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Assembly.GetName().Name, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];