mirror of
https://github.com/wahyd4/telegraf.git
synced 2026-08-09 04:36:05 +10:00
Update sample config to include cpu gathering mode
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user