From 939c4853382b37768b434d99e9ce1ac83cdecc86 Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:04:41 +0800 Subject: [PATCH] add win --- cpu.go | 2 +- cpu_test.go | 24 ++++++++++++++++++++++++ host1.csv | 3 --- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 cpu_test.go delete mode 100644 host1.csv diff --git a/cpu.go b/cpu.go index b9abf2b..dd52bb4 100644 --- a/cpu.go +++ b/cpu.go @@ -22,7 +22,7 @@ func getCPUInfo(ip, port string) (int, float64, error) { lines := strings.Split(data, "\n") for _, line := range lines { //有两个版本的Metrics node_cpu_seconds_total and node_cpu - if strings.HasPrefix(line, "node_cpu{cpu=") || strings.HasPrefix(line, "node_cpu_seconds_total") { + if strings.HasPrefix(line, "node_cpu{cpu=") || strings.HasPrefix(line, "node_cpu_seconds_total") || strings.HasPrefix(line, "windows_cpu_time_total") { fields := strings.Fields(line) if len(fields) == 2 { cpuData, err := extractMetricValue(fields[1]) diff --git a/cpu_test.go b/cpu_test.go new file mode 100644 index 0000000..e56377b --- /dev/null +++ b/cpu_test.go @@ -0,0 +1,24 @@ +/* +* +@author: sre +@date: 2023/11/22 0022 +@desc: todo +* +*/ +package main + +import ( + "fmt" + "testing" + "time" +) + +func TestGetWinCPU(t *testing.T) { + ip, port := "127.0.0.1", "9182" + for { + fmt.Println(getCPUInfo(ip, port)) + time.Sleep(time.Second * 1) + } +} + +//windows_cs_physical_memory_bytes diff --git a/host1.csv b/host1.csv deleted file mode 100644 index 00826e7..0000000 --- a/host1.csv +++ /dev/null @@ -1,3 +0,0 @@ -ip,port -119.91.19.44,9100 -119.91.19.44,9100 \ No newline at end of file