Skip to content

Commit

Permalink
Add memory_usage (percent) field to procstat input plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtsquiggs committed Aug 13, 2019
1 parent 5473872 commit f17f399
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 @@ -21,6 +21,7 @@ type Process interface {
NumFDs() (int32, error)
NumThreads() (int32, error)
Percent(interval time.Duration) (float64, error)
MemoryPercent() (float32, error)
Times() (*cpu.TimesStat, error)
RlimitUsage(bool) ([]process.RlimitStat, error)
Username() (string, error)
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 @@ -245,6 +245,11 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
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)
if err == nil {
for _, rlim := range rlims {
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 @@ -148,6 +148,10 @@ func (p *testProc) Percent(interval time.Duration) (float64, error) {
return 0, nil
}

func (p *testProc) MemoryPercent() (float32, error) {
return 0, nil
}

func (p *testProc) Times() (*cpu.TimesStat, error) {
return &cpu.TimesStat{}, nil
}
Expand Down

0 comments on commit f17f399

Please sign in to comment.