diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 8ce834a7..80328054 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 PID as a tag instead of a field; useful to differentiate between ## processes whose tags are otherwise the same. Can create a large number ## of series, use judiciously. diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index b0270a6e..9acbc936 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -8,6 +8,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "time" "github.com/influxdata/telegraf" @@ -37,6 +38,8 @@ type Procstat struct { WinService string `toml:"win_service"` Mode string + solarisMode bool + finder PIDFinder createPIDFinder func() (PIDFinder, error) @@ -71,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 PID as a tag instead of a field; useful to differentiate between ## processes whose tags are otherwise the same. Can create a large number ## of series, use judiciously. @@ -234,10 +240,10 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) { cpu_perc, err := proc.Percent(time.Duration(0)) if err == nil { - if p.Mode != "non-irix" { - fields[prefix+"cpu_usage"] = cpu_perc - } else { + if p.solarisMode { fields[prefix+"cpu_usage"] = cpu_perc / float64(runtime.NumCPU()) + } else { + fields[prefix+"cpu_usage"] = cpu_perc } } @@ -454,6 +460,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{}