Skip to content
Snippets Groups Projects
Unverified Commit fc9f921b authored by Rikaard Hosein's avatar Rikaard Hosein Committed by Cameron Sparr
Browse files

Can turn pid into tag instead of field

closes #1843
fixes  #1668
parent 12db3b91
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin. - [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin.
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus. - [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus.
- [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker. - [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker.
- [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag.
## v1.1.2 [2016-12-12] ## v1.1.2 [2016-12-12]
......
...@@ -21,6 +21,7 @@ type Procstat struct { ...@@ -21,6 +21,7 @@ type Procstat struct {
Prefix string Prefix string
ProcessName string ProcessName string
User string User string
PidTag bool
// pidmap maps a pid to a process object, so we don't recreate every gather // pidmap maps a pid to a process object, so we don't recreate every gather
pidmap map[int32]*process.Process pidmap map[int32]*process.Process
...@@ -53,6 +54,8 @@ var sampleConfig = ` ...@@ -53,6 +54,8 @@ var sampleConfig = `
prefix = "" prefix = ""
## comment this out if you want raw cpu_time stats ## comment this out if you want raw cpu_time stats
fielddrop = ["cpu_time_*"] fielddrop = ["cpu_time_*"]
## This is optional; moves pid into a tag instead of a field
pid_tag = false
` `
func (_ *Procstat) SampleConfig() string { func (_ *Procstat) SampleConfig() string {
...@@ -70,6 +73,9 @@ func (p *Procstat) Gather(acc telegraf.Accumulator) error { ...@@ -70,6 +73,9 @@ func (p *Procstat) Gather(acc telegraf.Accumulator) error {
p.Exe, p.PidFile, p.Pattern, p.User, err.Error()) p.Exe, p.PidFile, p.Pattern, p.User, err.Error())
} else { } else {
for pid, proc := range p.pidmap { 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 := NewSpecProcessor(p.ProcessName, p.Prefix, pid, acc, proc, p.tagmap[pid])
p.pushMetrics() p.pushMetrics()
} }
......
...@@ -48,7 +48,12 @@ func (p *SpecProcessor) pushMetrics() { ...@@ -48,7 +48,12 @@ func (p *SpecProcessor) pushMetrics() {
if p.Prefix != "" { if p.Prefix != "" {
prefix = 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() numThreads, err := p.proc.NumThreads()
if err == nil { if err == nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment