From d5d1d1fc1e7e660597392c6f3be64a765845a840 Mon Sep 17 00:00:00 2001 From: Rikaard Hosein Date: Mon, 3 Oct 2016 20:24:18 -0400 Subject: [PATCH] Can turn pid into tag instead of field --- plugins/inputs/procstat/procstat.go | 6 ++++++ plugins/inputs/procstat/spec_processor.go | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index e29b5031c..929490e4a 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -21,6 +21,7 @@ type Procstat struct { Prefix string ProcessName string User string + PidTag bool // pidmap maps a pid to a process object, so we don't recreate every gather pidmap map[int32]*process.Process @@ -53,6 +54,8 @@ var sampleConfig = ` prefix = "" ## comment this out if you want raw cpu_time stats fielddrop = ["cpu_time_*"] + ## This is optional; moves pid into a tag instead of a field + pid_tag = false ` func (_ *Procstat) SampleConfig() string { @@ -70,6 +73,9 @@ func (p *Procstat) Gather(acc telegraf.Accumulator) error { p.Exe, p.PidFile, p.Pattern, p.User, err.Error()) } else { for pid, proc := range p.pidmap { + if p.PidTag { + p.tagmap[pid]["pid"] = fmt.Sprint(pid) + } p := NewSpecProcessor(p.ProcessName, p.Prefix, pid, acc, proc, p.tagmap[pid]) p.pushMetrics() } diff --git a/plugins/inputs/procstat/spec_processor.go b/plugins/inputs/procstat/spec_processor.go index 5143d8bcc..3b56fbc3e 100644 --- a/plugins/inputs/procstat/spec_processor.go +++ b/plugins/inputs/procstat/spec_processor.go @@ -48,7 +48,12 @@ func (p *SpecProcessor) pushMetrics() { if p.Prefix != "" { prefix = p.Prefix + "_" } - fields := map[string]interface{}{"pid": p.pid} + fields := map[string]interface{}{} + + //If pid is not present as a tag, include it as a field. + if _, pidInTags := p.tags["pid"]; !pidInTags { + fields["pid"] = p.pid + } numThreads, err := p.proc.NumThreads() if err == nil {