Add cmdline tag to procstat input (#5681)
This commit is contained in:
parent
7f8bf56670
commit
d2666d0db6
|
@ -41,6 +41,9 @@ Processes can be selected for monitoring using one of several methods:
|
|||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
# cmdline_tag = false
|
||||
|
||||
## 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.
|
||||
|
@ -72,6 +75,7 @@ implemented as a WMI query. The pattern allows fuzzy matching using only
|
|||
- procstat
|
||||
- tags:
|
||||
- pid (when `pid_tag` is true)
|
||||
- cmdline (when 'cmdline_tag' is true)
|
||||
- process_name
|
||||
- pidfile (when defined)
|
||||
- exe (when defined)
|
||||
|
|
|
@ -15,6 +15,7 @@ type Process interface {
|
|||
IOCounters() (*process.IOCountersStat, error)
|
||||
MemoryInfo() (*process.MemoryInfoStat, error)
|
||||
Name() (string, error)
|
||||
Cmdline() (string, error)
|
||||
NumCtxSwitches() (*process.NumCtxSwitchesStat, error)
|
||||
NumFDs() (int32, error)
|
||||
NumThreads() (int32, error)
|
||||
|
|
|
@ -27,6 +27,7 @@ type Procstat struct {
|
|||
Exe string
|
||||
Pattern string
|
||||
Prefix string
|
||||
CmdLineTag bool `toml:"cmdline_tag"`
|
||||
ProcessName string
|
||||
User string
|
||||
SystemdUnit string
|
||||
|
@ -65,6 +66,9 @@ var sampleConfig = `
|
|||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
# cmdline_tag = false
|
||||
|
||||
## 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.
|
||||
|
@ -170,6 +174,16 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
|
|||
fields["pid"] = int32(proc.PID())
|
||||
}
|
||||
|
||||
//If cmd_line tag is true and it is not already set add cmdline as a tag
|
||||
if p.CmdLineTag {
|
||||
if _, ok := proc.Tags()["cmdline"]; !ok {
|
||||
Cmdline, err := proc.Cmdline()
|
||||
if err == nil {
|
||||
proc.Tags()["cmdline"] = Cmdline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numThreads, err := proc.NumThreads()
|
||||
if err == nil {
|
||||
fields[prefix+"num_threads"] = numThreads
|
||||
|
|
|
@ -76,6 +76,10 @@ func (pg *testPgrep) PidFile(path string) ([]PID, error) {
|
|||
return pg.pids, pg.err
|
||||
}
|
||||
|
||||
func (p *testProc) Cmdline() (string, error) {
|
||||
return "test_proc", nil
|
||||
}
|
||||
|
||||
func (pg *testPgrep) Pattern(pattern string) ([]PID, error) {
|
||||
return pg.pids, pg.err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue