shirou / gopsutil

psutil for golang
Other
10.68k stars 1.59k forks source link

process.MemoryInfo returns MemoryInfoStat with only two out of five fields filled on linux #620

Open tonimctoni opened 5 years ago

tonimctoni commented 5 years ago

I do not know if this is intended, but on linux process.MemoryInfo returns a MemoryInfoStat struct with only the RSS and VMS fields set.

They get set here.

I find it weird because here the other fields get set too, so it does not seem to be a limitation of the platform.

It got me confused because the procstat plugin for telegraf seems to ignore this here.

shirou commented 5 years ago

Sorry for late response. Could you show us your platform and if linux, /proc/<some pid>/status ?

vazhem commented 5 years ago

https://github.com/influxdata/telegraf/issues/3606 Telegraf uses MemoryInfo() to get memory info for a process. The problem is that gopsutil for this call returns data from /proc/pid/statm. /proc/pid/statm does not have info about swap. But /proc/pid/status does. So gopsutil should be fixed to return swap info in the MemoryInfo() call.

example of /proc/pid/status

cat /proc/80425/status
Name:   telegraf
Umask:  0022
State:  S (sleeping)
Tgid:   80425
Ngid:   80425
Pid:    80425
PPid:   80150
TracerPid:      0
Uid:    0       0       0       0
Gid:    0       0       0       0
FDSize: 256
Groups:
NStgid: 80425   136
NSpid:  80425   136
NSpgid: 80150   1
NSsid:  80150   1
VmPeak:  3269424 kB
VmSize:  3220792 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:     40704 kB
VmRSS:     32588 kB
RssAnon:           32588 kB
RssFile:               0 kB
RssShmem:              0 kB
VmData:   728780 kB
VmStk:       132 kB
VmExe:     22988 kB
VmLib:      2080 kB
VmPTE:       696 kB
VmPMD:        28 kB
VmSwap:     2800 kB
HugetlbPages:          0 kB
Threads:        76
SigQ:   0/251420
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: ffffffffffc1feff
CapInh: 0000003fffffffff
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000
NoNewPrivs:     0
Seccomp:        0
Speculation_Store_Bypass:       thread vulnerable
Cpus_allowed:   ffffff
Cpus_allowed_list:      0-23
Mems_allowed:   00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003
Mems_allowed_list:      0-1
voluntary_ctxt_switches:        3084
nonvoluntary_ctxt_switches:     1292