Skip to content

Commit 6f1ab1e

Browse files
scottprichardMathieu Lecarme
authored andcommitted
Add cmdline tag to procstat input (influxdata#5681)
1 parent e8275ac commit 6f1ab1e

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

plugins/inputs/procstat/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Processes can be selected for monitoring using one of several methods:
4141
## Field name prefix
4242
# prefix = ""
4343

44+
## When true add the full cmdline as a tag.
45+
# cmdline_tag = false
46+
4447
## Add PID as a tag instead of a field; useful to differentiate between
4548
## processes whose tags are otherwise the same. Can create a large number
4649
## of series, use judiciously.
@@ -72,6 +75,7 @@ implemented as a WMI query. The pattern allows fuzzy matching using only
7275
- procstat
7376
- tags:
7477
- pid (when `pid_tag` is true)
78+
- cmdline (when 'cmdline_tag' is true)
7579
- process_name
7680
- pidfile (when defined)
7781
- exe (when defined)

plugins/inputs/procstat/process.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Process interface {
1515
IOCounters() (*process.IOCountersStat, error)
1616
MemoryInfo() (*process.MemoryInfoStat, error)
1717
Name() (string, error)
18+
Cmdline() (string, error)
1819
NumCtxSwitches() (*process.NumCtxSwitchesStat, error)
1920
NumFDs() (int32, error)
2021
NumThreads() (int32, error)

plugins/inputs/procstat/procstat.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Procstat struct {
2727
Exe string
2828
Pattern string
2929
Prefix string
30+
CmdLineTag bool `toml:"cmdline_tag"`
3031
ProcessName string
3132
User string
3233
SystemdUnit string
@@ -65,6 +66,9 @@ var sampleConfig = `
6566
## Field name prefix
6667
# prefix = ""
6768
69+
## When true add the full cmdline as a tag.
70+
# cmdline_tag = false
71+
6872
## Add PID as a tag instead of a field; useful to differentiate between
6973
## processes whose tags are otherwise the same. Can create a large number
7074
## of series, use judiciously.
@@ -170,6 +174,16 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
170174
fields["pid"] = int32(proc.PID())
171175
}
172176

177+
//If cmd_line tag is true and it is not already set add cmdline as a tag
178+
if p.CmdLineTag {
179+
if _, ok := proc.Tags()["cmdline"]; !ok {
180+
Cmdline, err := proc.Cmdline()
181+
if err == nil {
182+
proc.Tags()["cmdline"] = Cmdline
183+
}
184+
}
185+
}
186+
173187
numThreads, err := proc.NumThreads()
174188
if err == nil {
175189
fields[prefix+"num_threads"] = numThreads

plugins/inputs/procstat/procstat_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (pg *testPgrep) PidFile(path string) ([]PID, error) {
7676
return pg.pids, pg.err
7777
}
7878

79+
func (p *testProc) Cmdline() (string, error) {
80+
return "test_proc", nil
81+
}
82+
7983
func (pg *testPgrep) Pattern(pattern string) ([]PID, error) {
8084
return pg.pids, pg.err
8185
}

0 commit comments

Comments
 (0)