feat(inputs.procstat): Add status field (#13505)

This commit is contained in:
Vanilla 2023-06-27 23:12:16 +08:00 committed by GitHub
parent adf12c6c4c
commit f2a1101581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View File

@ -124,6 +124,7 @@ the `win_perf_counters` input plugin as a more mature alternative.
- num_threads (int) - num_threads (int)
- pid (int) - pid (int)
- ppid (int) - ppid (int)
- status (string)
- read_bytes (int, *telegraf* may need to be ran as **root**) - read_bytes (int, *telegraf* may need to be ran as **root**)
- read_count (int, *telegraf* may need to be ran as **root**) - read_count (int, *telegraf* may need to be ran as **root**)
- realtime_priority (int) - realtime_priority (int)

View File

@ -28,6 +28,7 @@ type Process interface {
Username() (string, error) Username() (string, error)
CreateTime() (int64, error) CreateTime() (int64, error)
Ppid() (int32, error) Ppid() (int32, error)
Status() ([]string, error)
} }
type PIDFinder interface { type PIDFinder interface {

View File

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

View File

@ -169,6 +169,10 @@ func (p *testProc) Ppid() (int32, error) {
return 0, nil return 0, nil
} }
func (p *testProc) Status() ([]string, error) {
return []string{"running"}, nil
}
var pid = PID(42) var pid = PID(42)
var exe = "foo" var exe = "foo"