Procstat input plugin - functionality for overriding of process_name (#1192)
Being able to override the process_name in the procstat module is useful for daemonized perl, ruby, erlang etc. processes. This allows for manually setting process_name rather than it being set to the interpreter/VM of the process.
This commit is contained in:
parent
debf7bf149
commit
ab54064689
|
@ -19,6 +19,7 @@ type Procstat struct {
|
||||||
Exe string
|
Exe string
|
||||||
Pattern string
|
Pattern string
|
||||||
Prefix string
|
Prefix string
|
||||||
|
ProcessName string
|
||||||
User string
|
User string
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -45,6 +46,9 @@ var sampleConfig = `
|
||||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||||
# user = "nginx"
|
# user = "nginx"
|
||||||
|
|
||||||
|
## override for process_name
|
||||||
|
## This is optional; default is sourced from /proc/<pid>/status
|
||||||
|
# process_name = "bar"
|
||||||
## Field name prefix
|
## Field name prefix
|
||||||
prefix = ""
|
prefix = ""
|
||||||
## comment this out if you want raw cpu_time stats
|
## comment this out if you want raw cpu_time stats
|
||||||
|
@ -66,7 +70,7 @@ 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 {
|
||||||
p := NewSpecProcessor(p.Prefix, acc, proc, p.tagmap[pid])
|
p := NewSpecProcessor(p.ProcessName, p.Prefix, acc, proc, p.tagmap[pid])
|
||||||
p.pushMetrics()
|
p.pushMetrics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,20 @@ type SpecProcessor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSpecProcessor(
|
func NewSpecProcessor(
|
||||||
|
processName string,
|
||||||
prefix string,
|
prefix string,
|
||||||
acc telegraf.Accumulator,
|
acc telegraf.Accumulator,
|
||||||
p *process.Process,
|
p *process.Process,
|
||||||
tags map[string]string,
|
tags map[string]string,
|
||||||
) *SpecProcessor {
|
) *SpecProcessor {
|
||||||
if name, err := p.Name(); err == nil {
|
if processName != "" {
|
||||||
|
tags["process_name"] = processName
|
||||||
|
} else {
|
||||||
|
name, err := p.Name()
|
||||||
|
if err == nil {
|
||||||
tags["process_name"] = name
|
tags["process_name"] = name
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return &SpecProcessor{
|
return &SpecProcessor{
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
|
Loading…
Reference in New Issue