Add PPID field to procstat input plugin (#8887)

This commit is contained in:
reimda 2021-03-02 21:42:06 -07:00 committed by GitHub
parent 600816826d
commit 851136f16c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,7 @@ type Process interface {
RlimitUsage(bool) ([]process.RlimitStat, error)
Username() (string, error)
CreateTime() (int64, error)
Ppid() (int32, error)
}
type PIDFinder interface {

View File

@ -311,6 +311,11 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator, t time.Time
}
}
ppid, err := proc.Ppid()
if err == nil {
fields[prefix+"ppid"] = ppid
}
acc.AddFields("procstat", fields, proc.Tags(), t)
}

View File

@ -164,6 +164,10 @@ func (p *testProc) RlimitUsage(_ bool) ([]process.RlimitStat, error) {
return []process.RlimitStat{}, nil
}
func (p *testProc) Ppid() (int32, error) {
return 0, nil
}
var pid = PID(42)
var exe = "foo"