Add memory_usage field to procstat input plugin (#6249)

This commit is contained in:
Matthew Crenshaw 2019-08-14 13:17:38 -04:00 committed by Daniel Nelson
parent 5473872ac1
commit e36639b15d
3 changed files with 10 additions and 0 deletions

View File

@ -21,6 +21,7 @@ type Process interface {
NumFDs() (int32, error) NumFDs() (int32, error)
NumThreads() (int32, error) NumThreads() (int32, error)
Percent(interval time.Duration) (float64, error) Percent(interval time.Duration) (float64, error)
MemoryPercent() (float32, error)
Times() (*cpu.TimesStat, error) Times() (*cpu.TimesStat, error)
RlimitUsage(bool) ([]process.RlimitStat, error) RlimitUsage(bool) ([]process.RlimitStat, error)
Username() (string, error) Username() (string, error)

View File

@ -245,6 +245,11 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
fields[prefix+"memory_locked"] = mem.Locked fields[prefix+"memory_locked"] = mem.Locked
} }
mem_perc, err := proc.MemoryPercent()
if err == nil {
fields[prefix+"memory_usage"] = mem_perc
}
rlims, err := proc.RlimitUsage(true) rlims, err := proc.RlimitUsage(true)
if err == nil { if err == nil {
for _, rlim := range rlims { for _, rlim := range rlims {

View File

@ -148,6 +148,10 @@ func (p *testProc) Percent(interval time.Duration) (float64, error) {
return 0, nil return 0, nil
} }
func (p *testProc) MemoryPercent() (float32, error) {
return 0, nil
}
func (p *testProc) Times() (*cpu.TimesStat, error) { func (p *testProc) Times() (*cpu.TimesStat, error) {
return &cpu.TimesStat{}, nil return &cpu.TimesStat{}, nil
} }