MCPcopy
hub / github.com/prometheus/node_exporter / parseLoad

Function parseLoad

collector/loadavg_linux.go:39–52  ·  view source on GitHub ↗

Parse /proc loadavg and return 1m, 5m and 15m.

(data string)

Source from the content-addressed store, hash-verified

37
38// Parse /proc loadavg and return 1m, 5m and 15m.
39func parseLoad(data string) (loads []float64, err error) {
40 loads = make([]float64, 3)
41 parts := strings.Fields(data)
42 if len(parts) < 3 {
43 return nil, fmt.Errorf("unexpected content in %s", procFilePath("loadavg"))
44 }
45 for i, load := range parts[0:3] {
46 loads[i], err = strconv.ParseFloat(load, 64)
47 if err != nil {
48 return nil, fmt.Errorf("could not parse load '%s': %w", load, err)
49 }
50 }
51 return loads, nil
52}

Callers 2

TestLoadFunction · 0.85
getLoadFunction · 0.85

Calls 1

procFilePathFunction · 0.85

Tested by 1

TestLoadFunction · 0.68