Add pid tag to procstat plugin, dont exit on error, only log

This commit is contained in:
Cameron Sparr 2015-10-07 11:42:50 -06:00
parent 6827459b9f
commit 795ea49093
1 changed files with 14 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package procstat
import ( import (
"fmt" "fmt"
"log"
"github.com/shirou/gopsutil/process" "github.com/shirou/gopsutil/process"
@ -19,10 +20,16 @@ func (p *SpecProcessor) add(metric string, value interface{}) {
p.acc.Add(p.Prefix+"_"+metric, value, p.tags) p.acc.Add(p.Prefix+"_"+metric, value, p.tags)
} }
func NewSpecProcessor(prefix string, acc plugins.Accumulator, p *process.Process) *SpecProcessor { func NewSpecProcessor(
prefix string,
acc plugins.Accumulator,
p *process.Process,
) *SpecProcessor {
tags := make(map[string]string)
tags["pid"] = fmt.Sprintf("%v", p.Pid)
return &SpecProcessor{ return &SpecProcessor{
Prefix: prefix, Prefix: prefix,
tags: map[string]string{}, tags: tags,
acc: acc, acc: acc,
proc: p, proc: p,
} }
@ -30,19 +37,19 @@ func NewSpecProcessor(prefix string, acc plugins.Accumulator, p *process.Process
func (p *SpecProcessor) pushMetrics() error { func (p *SpecProcessor) pushMetrics() error {
if err := p.pushFDStats(); err != nil { if err := p.pushFDStats(); err != nil {
return err log.Printf(err.Error())
} }
if err := p.pushCtxStats(); err != nil { if err := p.pushCtxStats(); err != nil {
return err log.Printf(err.Error())
} }
if err := p.pushIOStats(); err != nil { if err := p.pushIOStats(); err != nil {
return err log.Printf(err.Error())
} }
if err := p.pushCPUStats(); err != nil { if err := p.pushCPUStats(); err != nil {
return err log.Printf(err.Error())
} }
if err := p.pushMemoryStats(); err != nil { if err := p.pushMemoryStats(); err != nil {
return err log.Printf(err.Error())
} }
return nil return nil
} }