diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 73c40ef79213e..8d43d86eaf568 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -44,6 +44,9 @@ Processes can be selected for monitoring using one of several methods: ## When true add the full cmdline as a tag. # 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 ## processes with otherwise matching tags this setting should be enabled to ## ensure each process has a unique identity. diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index 1d6af5df42246..aa654da560c10 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -6,7 +6,9 @@ import ( "io/ioutil" "os/exec" "path/filepath" + "runtime" "strconv" + "strings" "time" "github.com/influxdata/telegraf" @@ -34,6 +36,9 @@ type Procstat struct { CGroup string `toml:"cgroup"` PidTag bool WinService string `toml:"win_service"` + Mode string + + solarisMode bool finder PIDFinder @@ -69,6 +74,9 @@ var sampleConfig = ` ## When true add the full cmdline as a tag. # 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 ## processes with otherwise matching tags this setting should be enabled to ## 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)) 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() @@ -461,6 +473,14 @@ func (p *Procstat) winServicePIDs() ([]PID, error) { return pids, nil } +func (p *Procstat) Init() error { + if strings.ToLower(p.Mode) == "solaris" { + p.solarisMode = true + } + + return nil +} + func init() { inputs.Add("procstat", func() telegraf.Input { return &Procstat{}