Update sample config to include cpu gathering mode

This commit is contained in:
greg linton
2019-09-19 09:18:34 -06:00
parent 4ec7872c35
commit a6182e3207
2 changed files with 20 additions and 3 deletions
+3
View File
@@ -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.
+17 -3
View File
@@ -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{}