Skip to content

Commit

Permalink
Procstat - Support overwriting process_name with the value of the pro…
Browse files Browse the repository at this point in the history
…cess Cmdline
  • Loading branch information
jeichorn committed Mar 26, 2019
1 parent 0f21373 commit d82c4e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/inputs/procstat/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Process interface {
PID() PID
Tags() map[string]string
CmdLine() (string, error)

IOCounters() (*process.IOCountersStat, error)
MemoryInfo() (*process.MemoryInfoStat, error)
Expand Down Expand Up @@ -63,6 +64,11 @@ func (p *Proc) Username() (string, error) {
return p.Process.Username()
}

func (p *Proc) CmdLine() (string, error) {
name, err := p.Process.Cmdline()
return name, err
}

func (p *Proc) Percent(interval time.Duration) (float64, error) {
cpu_perc, err := p.Process.Percent(time.Duration(0))
if !p.hasCPUTimes && err == nil {
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {

fields := map[string]interface{}{}

// PATCH
// if the name is Cmdline replace it with the value of proc.Cmdline()
if tag, _ := proc.Tags()["process_name"]; tag == "Cmdline" {
name, err := proc.CmdLine()
if err == nil {
proc.Tags()["process_name"] = name
}
}
// PATCH

//If process_name tag is not already set, set to actual name
if _, nameInTags := proc.Tags()["process_name"]; !nameInTags {
name, err := proc.Name()
Expand Down

0 comments on commit d82c4e0

Please sign in to comment.