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

Function parsePSIStats

proc_psi.go:71–102  ·  view source on GitHub ↗

parsePSIStats parses the specified file for pressure stall information.

(r io.Reader)

Source from the content-addressed store, hash-verified

69
70// parsePSIStats parses the specified file for pressure stall information.
71func parsePSIStats(r io.Reader) (PSIStats, error) {
72 psiStats := PSIStats{}
73
74 scanner := bufio.NewScanner(r)
75 for scanner.Scan() {
76 l := scanner.Text()
77 prefix := strings.Split(l, " ")[0]
78 switch prefix {
79 case "some":
80 psi := PSILine{}
81 _, err := fmt.Sscanf(l, fmt.Sprintf("some %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
82 if err != nil {
83 return PSIStats{}, err
84 }
85 psiStats.Some = &psi
86 case "full":
87 psi := PSILine{}
88 _, err := fmt.Sscanf(l, fmt.Sprintf("full %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total)
89 if err != nil {
90 return PSIStats{}, err
91 }
92 psiStats.Full = &psi
93 default:
94 // If we encounter a line with an unknown prefix, ignore it and move on
95 // Should new measurement types be added in the future we'll simply ignore them instead
96 // of erroring on retrieval
97 continue
98 }
99 }
100
101 return psiStats, nil
102}

Callers 2

TestParsePSIStatsFunction · 0.85
PSIStatsForResourceMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParsePSIStatsFunction · 0.68