Skip to content

Commit

Permalink
Add PPID field to procstat input plugin (influxdata#8887)
Browse files Browse the repository at this point in the history
  • Loading branch information
reimda authored Mar 3, 2021
1 parent 6008168 commit 851136f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/procstat/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Process interface {
RlimitUsage(bool) ([]process.RlimitStat, error)
Username() (string, error)
CreateTime() (int64, error)
Ppid() (int32, error)
}

type PIDFinder interface {
Expand Down
5 changes: 5 additions & 0 deletions plugins/inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/inputs/procstat/procstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 851136f

Please sign in to comment.