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

Function parseMountStats

mountstats.go:274–319  ·  view source on GitHub ↗

parseMountStats parses a /proc/[pid]/mountstats file and returns a slice of Mount structures containing detailed information about each mount. If available, statistics for each mount are parsed as well.

(r io.Reader)

Source from the content-addressed store, hash-verified

272// of Mount structures containing detailed information about each mount.
273// If available, statistics for each mount are parsed as well.
274func parseMountStats(r io.Reader) ([]*Mount, error) {
275 const (
276 device = "device"
277 statVersionPrefix = "statvers="
278
279 nfs3Type = "nfs"
280 nfs4Type = "nfs4"
281 )
282
283 var mounts []*Mount
284
285 s := bufio.NewScanner(r)
286 for s.Scan() {
287 // Only look for device entries in this function
288 ss := strings.Fields(string(s.Bytes()))
289 if len(ss) == 0 || ss[0] != device {
290 continue
291 }
292
293 m, err := parseMount(ss)
294 if err != nil {
295 return nil, err
296 }
297
298 // Does this mount also possess statistics information?
299 if len(ss) > deviceEntryLen {
300 // Only NFSv3 and v4 are supported for parsing statistics
301 if m.Type != nfs3Type && m.Type != nfs4Type {
302 return nil, fmt.Errorf("%w: Cannot parse MountStats for %q", ErrFileParse, m.Type)
303 }
304
305 statVersion := strings.TrimPrefix(ss[8], statVersionPrefix)
306
307 stats, err := parseMountStatsNFS(s, statVersion)
308 if err != nil {
309 return nil, err
310 }
311
312 m.Stats = stats
313 }
314
315 mounts = append(mounts, m)
316 }
317
318 return mounts, s.Err()
319}
320
321// parseMount parses an entry in /proc/[pid]/mountstats in the format:
322//

Callers 4

TestMountStatsFunction · 0.85
MountStatsMethod · 0.85

Calls 3

parseMountFunction · 0.85
parseMountStatsNFSFunction · 0.85
ErrMethod · 0.80

Tested by 3

TestMountStatsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…