From e7b77f77216f7a139ee7cde653210b6a6d6b52a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20R=C3=B6hl?= Date: Wed, 5 Apr 2023 11:20:09 +0200 Subject: [PATCH] Add cpu_used (all-cpu_idle) to CpustatCollector --- collectors/cpustatMetric.go | 9 +++++++++ collectors/cpustatMetric.md | 1 + 2 files changed, 10 insertions(+) diff --git a/collectors/cpustatMetric.go b/collectors/cpustatMetric.go index bd6ec2f..2b1756f 100644 --- a/collectors/cpustatMetric.go +++ b/collectors/cpustatMetric.go @@ -119,12 +119,21 @@ func (m *CpustatCollector) parseStatLine(linefields []string, tags map[string]st } } + sum := float64(0) for name, value := range values { + sum += value y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value * 100}, now) if err == nil { output <- y } } + if v, ok := values["cpu_idle"]; ok { + sum -= v + y, err := lp.New("cpu_used", tags, m.meta, map[string]interface{}{"value": sum * 100}, now) + if err == nil { + output <- y + } + } } func (m *CpustatCollector) Read(interval time.Duration, output chan lp.CCMetric) { diff --git a/collectors/cpustatMetric.md b/collectors/cpustatMetric.md index 8963536..d160410 100644 --- a/collectors/cpustatMetric.md +++ b/collectors/cpustatMetric.md @@ -23,3 +23,4 @@ Metrics: * `cpu_steal` * `cpu_guest` * `cpu_guest_nice` +* `cpu_used` = `cpu_* - cpu_idle` \ No newline at end of file