MCPcopy Create free account
hub / github.com/prometheus/procfs / VM

Method VM

vm.go:81–211  ·  view source on GitHub ↗

VM reads the VM statistics from the specified `proc` filesystem.

()

Source from the content-addressed store, hash-verified

79
80// VM reads the VM statistics from the specified `proc` filesystem.
81func (fs FS) VM() (*VM, error) {
82 path := fs.proc.Path("sys/vm")
83 file, err := os.Stat(path)
84 if err != nil {
85 return nil, err
86 }
87 if !file.Mode().IsDir() {
88 return nil, fmt.Errorf("%w: %s is not a directory", ErrFileRead, path)
89 }
90
91 files, err := os.ReadDir(path)
92 if err != nil {
93 return nil, err
94 }
95
96 var vm VM
97 for _, f := range files {
98 if f.IsDir() {
99 continue
100 }
101
102 name := filepath.Join(path, f.Name())
103 // ignore errors on read, as there are some write only
104 // in /proc/sys/vm
105 value, err := parsers.SysReadFile(name)
106 if err != nil {
107 continue
108 }
109 vp := parsers.NewValueParser(value)
110
111 switch f.Name() {
112 case "admin_reserve_kbytes":
113 vm.AdminReserveKbytes = vp.PInt64()
114 case "block_dump":
115 vm.BlockDump = vp.PInt64()
116 case "compact_unevictable_allowed":
117 vm.CompactUnevictableAllowed = vp.PInt64()
118 case "dirty_background_bytes":
119 vm.DirtyBackgroundBytes = vp.PInt64()
120 case "dirty_background_ratio":
121 vm.DirtyBackgroundRatio = vp.PInt64()
122 case "dirty_bytes":
123 vm.DirtyBytes = vp.PInt64()
124 case "dirty_expire_centisecs":
125 vm.DirtyExpireCentisecs = vp.PInt64()
126 case "dirty_ratio":
127 vm.DirtyRatio = vp.PInt64()
128 case "dirtytime_expire_seconds":
129 vm.DirtytimeExpireSeconds = vp.PInt64()
130 case "dirty_writeback_centisecs":
131 vm.DirtyWritebackCentisecs = vp.PInt64()
132 case "drop_caches":
133 vm.DropCaches = vp.PInt64()
134 case "extfrag_threshold":
135 vm.ExtfragThreshold = vp.PInt64()
136 case "hugetlb_shm_group":
137 vm.HugetlbShmGroup = vp.PInt64()
138 case "laptop_mode":

Callers 1

TestVMFunction · 0.95

Calls 7

PInt64Method · 0.95
ErrMethod · 0.95
SysReadFileFunction · 0.92
NewValueParserFunction · 0.92
NameMethod · 0.80
PathMethod · 0.45
StatMethod · 0.45

Tested by 1

TestVMFunction · 0.76