From 1c9ce5581285b1e10c23a04acbe0056761245599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20L=C3=B3pez?= Date: Wed, 7 Aug 2019 00:55:06 +0200 Subject: [PATCH] Update the number of logical CPUs dynamically in system plugin (#6214) --- plugins/inputs/system/README.md | 2 ++ plugins/inputs/system/system.go | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/system/README.md b/plugins/inputs/system/README.md index d5bcd7b03a951..8b16c1de08d25 100644 --- a/plugins/inputs/system/README.md +++ b/plugins/inputs/system/README.md @@ -3,6 +3,8 @@ The system plugin gathers general stats on system load, uptime, and number of users logged in. It is similar to the unix `uptime` command. +Number of CPUs is obtained from the /proc/cpuinfo file. + ### Configuration: ```toml diff --git a/plugins/inputs/system/system.go b/plugins/inputs/system/system.go index faf44f03e4e13..82e6b6db074d7 100644 --- a/plugins/inputs/system/system.go +++ b/plugins/inputs/system/system.go @@ -6,12 +6,12 @@ import ( "fmt" "log" "os" - "runtime" "strings" "time" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/load" ) @@ -35,11 +35,16 @@ func (_ *SystemStats) Gather(acc telegraf.Accumulator) error { return err } + numCPUs, err := cpu.Counts(true) + if err != nil { + return err + } + fields := map[string]interface{}{ "load1": loadavg.Load1, "load5": loadavg.Load5, "load15": loadavg.Load15, - "n_cpus": runtime.NumCPU(), + "n_cpus": numCPUs, } users, err := host.Users()