Add cpu_used (all-cpu_idle) to CpustatCollector

This commit is contained in:
Thomas Röhl 2023-04-05 11:20:09 +02:00
parent 3d7bb4cdd7
commit e7b77f7721
2 changed files with 10 additions and 0 deletions

View File

@ -119,12 +119,21 @@ func (m *CpustatCollector) parseStatLine(linefields []string, tags map[string]st
} }
} }
sum := float64(0)
for name, value := range values { for name, value := range values {
sum += value
y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value * 100}, now) y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value * 100}, now)
if err == nil { if err == nil {
output <- y 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) { func (m *CpustatCollector) Read(interval time.Duration, output chan lp.CCMetric) {

View File

@ -23,3 +23,4 @@ Metrics:
* `cpu_steal` * `cpu_steal`
* `cpu_guest` * `cpu_guest`
* `cpu_guest_nice` * `cpu_guest_nice`
* `cpu_used` = `cpu_* - cpu_idle`