Provide method to include core count when reporting cpu_usage in procstat input (#6165)
* Provide a non-irix reporting of cpu_usage in procstat input * Update sample config to include cpu gathering mode * cleanup readme from merge
This commit is contained in:
parent
ed72aac0be
commit
7c17055178
|
|
@ -44,6 +44,9 @@ Processes can be selected for monitoring using one of several methods:
|
||||||
## When true add the full cmdline as a tag.
|
## When true add the full cmdline as a tag.
|
||||||
# cmdline_tag = false
|
# cmdline_tag = false
|
||||||
|
|
||||||
|
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||||
|
# mode = "irix"
|
||||||
|
|
||||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||||
## processes with otherwise matching tags this setting should be enabled to
|
## processes with otherwise matching tags this setting should be enabled to
|
||||||
## ensure each process has a unique identity.
|
## ensure each process has a unique identity.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
|
@ -34,6 +36,9 @@ type Procstat struct {
|
||||||
CGroup string `toml:"cgroup"`
|
CGroup string `toml:"cgroup"`
|
||||||
PidTag bool
|
PidTag bool
|
||||||
WinService string `toml:"win_service"`
|
WinService string `toml:"win_service"`
|
||||||
|
Mode string
|
||||||
|
|
||||||
|
solarisMode bool
|
||||||
|
|
||||||
finder PIDFinder
|
finder PIDFinder
|
||||||
|
|
||||||
|
|
@ -69,6 +74,9 @@ var sampleConfig = `
|
||||||
## When true add the full cmdline as a tag.
|
## When true add the full cmdline as a tag.
|
||||||
# cmdline_tag = false
|
# cmdline_tag = false
|
||||||
|
|
||||||
|
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||||
|
# mode = "irix"
|
||||||
|
|
||||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||||
## processes with otherwise matching tags this setting should be enabled to
|
## processes with otherwise matching tags this setting should be enabled to
|
||||||
## ensure each process has a unique identity.
|
## ensure each process has a unique identity.
|
||||||
|
|
@ -240,7 +248,11 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
|
||||||
|
|
||||||
cpu_perc, err := proc.Percent(time.Duration(0))
|
cpu_perc, err := proc.Percent(time.Duration(0))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fields[prefix+"cpu_usage"] = cpu_perc
|
if p.solarisMode {
|
||||||
|
fields[prefix+"cpu_usage"] = cpu_perc / float64(runtime.NumCPU())
|
||||||
|
} else {
|
||||||
|
fields[prefix+"cpu_usage"] = cpu_perc
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mem, err := proc.MemoryInfo()
|
mem, err := proc.MemoryInfo()
|
||||||
|
|
@ -461,6 +473,14 @@ func (p *Procstat) winServicePIDs() ([]PID, error) {
|
||||||
return pids, nil
|
return pids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Procstat) Init() error {
|
||||||
|
if strings.ToLower(p.Mode) == "solaris" {
|
||||||
|
p.solarisMode = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("procstat", func() telegraf.Input {
|
inputs.Add("procstat", func() telegraf.Input {
|
||||||
return &Procstat{}
|
return &Procstat{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue