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

Function parseCgroupSummaryString

proc_cgroups.go:43–68  ·  view source on GitHub ↗

parseCgroupSummary parses each line of the /proc/cgroup file Line format is `subsys_name hierarchy num_cgroups enabled`.

(cgroupSummaryStr string)

Source from the content-addressed store, hash-verified

41// parseCgroupSummary parses each line of the /proc/cgroup file
42// Line format is `subsys_name hierarchy num_cgroups enabled`.
43func parseCgroupSummaryString(cgroupSummaryStr string) (*CgroupSummary, error) {
44 var err error
45
46 fields := strings.Fields(cgroupSummaryStr)
47 // require at least 4 fields
48 if len(fields) < 4 {
49 return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), cgroupSummaryStr)
50 }
51
52 CgroupSummary := &CgroupSummary{
53 SubsysName: fields[0],
54 }
55 CgroupSummary.Hierarchy, err = strconv.Atoi(fields[1])
56 if err != nil {
57 return nil, fmt.Errorf("%w: Unable to parse hierarchy ID from %q", ErrFileParse, fields[1])
58 }
59 CgroupSummary.Cgroups, err = strconv.Atoi(fields[2])
60 if err != nil {
61 return nil, fmt.Errorf("%w: Unable to parse Cgroup Num from %q", ErrFileParse, fields[2])
62 }
63 CgroupSummary.Enabled, err = strconv.Atoi(fields[3])
64 if err != nil {
65 return nil, fmt.Errorf("%w: Unable to parse Enabled from %q", ErrFileParse, fields[3])
66 }
67 return CgroupSummary, nil
68}
69
70// parseCgroupSummary reads each line of the /proc/cgroup file.
71func parseCgroupSummary(data []byte) ([]CgroupSummary, error) {

Callers 2

parseCgroupSummaryFunction · 0.85

Calls

no outgoing calls

Tested by 1