Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding cmdline procstat #5681

Merged
merged 6 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/inputs/procstat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/procstat/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions plugins/inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Procstat struct {
Exe string
Pattern string
Prefix string
CmdLineTag bool `toml:"cmdline_tag"`
ProcessName string
User string
SystemdUnit string
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugins/inputs/procstat/procstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down