Add process resource limits to procstat input (#3231)
This commit is contained in:
committed by
Daniel Nelson
parent
c2383e9d78
commit
19084f8fb6
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
"github.com/shirou/gopsutil/process"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -154,6 +155,48 @@ func (p *Procstat) addMetrics(proc Process, acc telegraf.Accumulator) {
|
||||
fields[prefix+"memory_rss"] = mem.RSS
|
||||
fields[prefix+"memory_vms"] = mem.VMS
|
||||
fields[prefix+"memory_swap"] = mem.Swap
|
||||
fields[prefix+"memory_data"] = mem.Data
|
||||
fields[prefix+"memory_stack"] = mem.Stack
|
||||
fields[prefix+"memory_locked"] = mem.Locked
|
||||
}
|
||||
|
||||
rlims, err := proc.RlimitUsage(true)
|
||||
if err == nil {
|
||||
for _, rlim := range rlims {
|
||||
var name string
|
||||
switch rlim.Resource {
|
||||
case process.RLIMIT_CPU:
|
||||
name = "cpu_time"
|
||||
case process.RLIMIT_DATA:
|
||||
name = "memory_data"
|
||||
case process.RLIMIT_STACK:
|
||||
name = "memory_stack"
|
||||
case process.RLIMIT_RSS:
|
||||
name = "memory_rss"
|
||||
case process.RLIMIT_NOFILE:
|
||||
name = "num_fds"
|
||||
case process.RLIMIT_MEMLOCK:
|
||||
name = "memory_locked"
|
||||
case process.RLIMIT_AS:
|
||||
name = "memory_vms"
|
||||
case process.RLIMIT_LOCKS:
|
||||
name = "file_locks"
|
||||
case process.RLIMIT_SIGPENDING:
|
||||
name = "signals_pending"
|
||||
case process.RLIMIT_NICE:
|
||||
name = "nice_priority"
|
||||
case process.RLIMIT_RTPRIO:
|
||||
name = "realtime_priority"
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
fields[prefix+"rlimit_"+name+"_soft"] = rlim.Soft
|
||||
fields[prefix+"rlimit_"+name+"_hard"] = rlim.Hard
|
||||
if name != "file_locks" { // gopsutil doesn't currently track the used file locks count
|
||||
fields[prefix+name] = rlim.Used
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acc.AddFields("procstat", fields, proc.Tags())
|
||||
|
||||
Reference in New Issue
Block a user