From 2faeef925d36e906f67559d525f1fe2d8e2ef032 Mon Sep 17 00:00:00 2001 From: Joshua Eichorn Date: Wed, 26 Apr 2017 22:14:17 +0000 Subject: [PATCH] Procstat - Support overwriting process_name with the value of the process Cmdline --- plugins/inputs/procstat/process.go | 6 ++++++ plugins/inputs/procstat/procstat.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/inputs/procstat/process.go b/plugins/inputs/procstat/process.go index ec2363f6ecf4c..97ecabc30edd9 100644 --- a/plugins/inputs/procstat/process.go +++ b/plugins/inputs/procstat/process.go @@ -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) @@ -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 { diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index 3715d390be0dd..91fd210234dab 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -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()