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 Apr 26, 2017
1 parent c66e289 commit 2faeef9
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 @@ -50,6 +51,11 @@ func (p *Proc) PID() PID {
return PID(p.Process.Pid)
}

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 @@ -92,6 +92,16 @@ func (p *Procstat) addMetrics(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 2faeef9

Please sign in to comment.