fix(inputs.procstat): Collect swap via /proc/$pid/smaps (#13779)
This commit is contained in:
parent
dcadf44bf9
commit
86a546c88d
|
|
@ -111,10 +111,15 @@ the `win_perf_counters` input plugin as a more mature alternative.
|
||||||
- cpu_usage (float)
|
- cpu_usage (float)
|
||||||
- involuntary_context_switches (int)
|
- involuntary_context_switches (int)
|
||||||
- major_faults (int)
|
- major_faults (int)
|
||||||
- memory_data (int)
|
- memory_anonymous (int)
|
||||||
- memory_locked (int)
|
- memory_private_clean (int)
|
||||||
|
- memory_private_dirty (int)
|
||||||
|
- memory_pss (int)
|
||||||
|
- memory_referenced (int)
|
||||||
- memory_rss (int)
|
- memory_rss (int)
|
||||||
- memory_stack (int)
|
- memory_shared_clean (int)
|
||||||
|
- memory_shared_dirty (int)
|
||||||
|
- memory_size (int)
|
||||||
- memory_swap (int)
|
- memory_swap (int)
|
||||||
- memory_usage (float)
|
- memory_usage (float)
|
||||||
- memory_vms (int)
|
- memory_vms (int)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package procstat
|
||||||
|
|
||||||
|
func collectMemmap(proc Process, prefix string, fields map[string]any) {
|
||||||
|
memMapStats, err := proc.MemoryMaps(true)
|
||||||
|
if err == nil && len(*memMapStats) == 1 {
|
||||||
|
memMap := (*memMapStats)[0]
|
||||||
|
fields[prefix+"memory_size"] = memMap.Size
|
||||||
|
fields[prefix+"memory_pss"] = memMap.Pss
|
||||||
|
fields[prefix+"memory_shared_clean"] = memMap.SharedClean
|
||||||
|
fields[prefix+"memory_shared_dirty"] = memMap.SharedDirty
|
||||||
|
fields[prefix+"memory_private_clean"] = memMap.PrivateClean
|
||||||
|
fields[prefix+"memory_private_dirty"] = memMap.PrivateDirty
|
||||||
|
fields[prefix+"memory_referenced"] = memMap.Referenced
|
||||||
|
fields[prefix+"memory_anonymous"] = memMap.Anonymous
|
||||||
|
fields[prefix+"memory_swap"] = memMap.Swap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package procstat
|
||||||
|
|
||||||
|
func collectMemmap(Process, string, map[string]any) {}
|
||||||
|
|
@ -16,6 +16,7 @@ type Process interface {
|
||||||
PageFaults() (*process.PageFaultsStat, error)
|
PageFaults() (*process.PageFaultsStat, error)
|
||||||
IOCounters() (*process.IOCountersStat, error)
|
IOCounters() (*process.IOCountersStat, error)
|
||||||
MemoryInfo() (*process.MemoryInfoStat, error)
|
MemoryInfo() (*process.MemoryInfoStat, error)
|
||||||
|
MemoryMaps(bool) (*[]process.MemoryMapsStat, error)
|
||||||
Name() (string, error)
|
Name() (string, error)
|
||||||
Cmdline() (string, error)
|
Cmdline() (string, error)
|
||||||
NumCtxSwitches() (*process.NumCtxSwitchesStat, error)
|
NumCtxSwitches() (*process.NumCtxSwitchesStat, error)
|
||||||
|
|
|
||||||
|
|
@ -225,16 +225,15 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator, t time.Time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This only returns values for RSS and VMS
|
||||||
mem, err := proc.MemoryInfo()
|
mem, err := proc.MemoryInfo()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fields[prefix+"memory_rss"] = mem.RSS
|
fields[prefix+"memory_rss"] = mem.RSS
|
||||||
fields[prefix+"memory_vms"] = mem.VMS
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collectMemmap(proc, prefix, fields)
|
||||||
|
|
||||||
memPerc, err := proc.MemoryPercent()
|
memPerc, err := proc.MemoryPercent()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fields[prefix+"memory_usage"] = memPerc
|
fields[prefix+"memory_usage"] = memPerc
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,10 @@ func (p *testProc) MemoryInfo() (*process.MemoryInfoStat, error) {
|
||||||
return &process.MemoryInfoStat{}, nil
|
return &process.MemoryInfoStat{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *testProc) MemoryMaps(bool) (*[]process.MemoryMapsStat, error) {
|
||||||
|
return &[]process.MemoryMapsStat{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *testProc) Name() (string, error) {
|
func (p *testProc) Name() (string, error) {
|
||||||
return "test_proc", nil
|
return "test_proc", nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue