/// <summary> /// 取得Redis CPU資訊 /// </summary> /// <returns></returns> public CPUChart GetCPUInfo(List <RedisInfo> list) { var result = new CPUChart(); result.Title = "CPU Usage"; result.XAxisName = "Time"; result.XAxisList = new List <string> { //"00:00", "04:00", "08:00", "12:00", "16:00", "20:00" }; result.YAxisName = "Byte"; result.YAxisList = new List <string> { "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" }; //result.DataList = new List<decimal> //{ // 81, 90, 96, 81, 86, 93, 90, 81, 90, 96, 81, 86, 93, 90, 100 //}; result.DataList = new List <decimal>(); decimal accumulationBytes = 0; foreach (var info in list) { decimal usedBytes = Convert.ToDecimal(info.CPU.used_cpu_sys); decimal bytes = (usedBytes - accumulationBytes) / 60; result.DataList.Add(bytes); result.XAxisList.Add(info.CollectTime.ToString("HH:mm")); } return(result); }
public ContinuousLineSample() { InitializeComponent(); Loaded += (_, __) => { Task a = Task.Run(() => { Random r = new Random(); while (true) { Dispatcher.Invoke(() => { RandomChart.DataSeries[0].Points.Add(new Point() { Y = r.Next(0, 100) }); RandomChart.DataSeries[1].Points.Add(new Point() { Y = r.Next(0, 100) }); }); Thread.Sleep(200); } }); Task.Run(() => { int coreCount = Environment.ProcessorCount; PerformanceCounter[] counters = new PerformanceCounter[coreCount]; Random r = new Random(); for (int i = 0; i < (coreCount - 1); i++) { Dispatcher.Invoke(() => CPUChart.DataSeries.Add(new Series() { LineThickness = 1, LineStroke = new SolidColorBrush(new Color() { A = (byte)255, R = (byte)r.Next(0, 215), G = (byte)r.Next(0, 215), B = (byte)r.Next(0, 215) }) })); counters[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); } while (true) { for (int i = 0; i < (coreCount - 1); i++) { Dispatcher.Invoke(() => { CPUChart.DataSeries[i].Points.Add(new Point() { Y = counters[i].NextValue() }); }); } Dispatcher.Invoke(() => CPUChart.Refresh()); Thread.Sleep(1000); } }); }; }