From a3a760bb48b518674480c4c02c777b0203271ed9 Mon Sep 17 00:00:00 2001 From: XiaoShao Date: Tue, 8 Sep 2026 11:24:29 +0800 Subject: [PATCH] telemetry: drop unused getCPUStats, unblocking darwin builds without cgo (#4841) getCPUStats has no callers: node CPU load comes from hwstats.CPUStats in GetNodeStats, and nothing in the tree reads getCPUStats. Only getLoadAvg is still used. Remove the function from both the windows and non-windows variants along with the state it kept. getLoadAvg is untouched, and go-osstat stays a direct dependency through it. Co-authored-by: XiaoShao <26596822+xiaoshao9704@users.noreply.github.com> --- pkg/telemetry/prometheus/node_nonwindows.go | 33 +-------------------- pkg/telemetry/prometheus/node_windows.go | 4 --- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/pkg/telemetry/prometheus/node_nonwindows.go b/pkg/telemetry/prometheus/node_nonwindows.go index b765ce27..9661e08f 100644 --- a/pkg/telemetry/prometheus/node_nonwindows.go +++ b/pkg/telemetry/prometheus/node_nonwindows.go @@ -18,39 +18,8 @@ package prometheus -import ( - "runtime" - "sync" - - "github.com/mackerelio/go-osstat/cpu" - "github.com/mackerelio/go-osstat/loadavg" -) - -var ( - cpuStatsLock sync.RWMutex - lastCPUTotal, lastCPUIdle uint64 -) +import "github.com/mackerelio/go-osstat/loadavg" func getLoadAvg() (*loadavg.Stats, error) { return loadavg.Get() } - -func getCPUStats() (cpuLoad float32, numCPUs uint32, err error) { - cpuInfo, err := cpu.Get() - if err != nil { - return - } - - cpuStatsLock.Lock() - if lastCPUTotal > 0 && lastCPUTotal < cpuInfo.Total { - cpuLoad = 1 - float32(cpuInfo.Idle-lastCPUIdle)/float32(cpuInfo.Total-lastCPUTotal) - } - - lastCPUTotal = cpuInfo.Total - lastCPUIdle = cpuInfo.Idle - cpuStatsLock.Unlock() - - numCPUs = uint32(runtime.NumCPU()) - - return -} diff --git a/pkg/telemetry/prometheus/node_windows.go b/pkg/telemetry/prometheus/node_windows.go index eb0ba48a..507b8043 100644 --- a/pkg/telemetry/prometheus/node_windows.go +++ b/pkg/telemetry/prometheus/node_windows.go @@ -23,7 +23,3 @@ import "github.com/mackerelio/go-osstat/loadavg" func getLoadAvg() (*loadavg.Stats, error) { return &loadavg.Stats{}, nil } - -func getCPUStats() (cpuLoad float32, numCPUs uint32, err error) { - return 1, 1, nil -}