Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the number of logcal CPUs dynamically #6214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/inputs/system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions plugins/inputs/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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()
Expand Down