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

Method Update

collector/vmstat_linux.go:57–85  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

55}
56
57func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
58 file, err := os.Open(procFilePath("vmstat"))
59 if err != nil {
60 return err
61 }
62 defer file.Close()
63
64 scanner := bufio.NewScanner(file)
65 for scanner.Scan() {
66 parts := strings.Fields(scanner.Text())
67 value, err := strconv.ParseFloat(parts[1], 64)
68 if err != nil {
69 return err
70 }
71 if !c.fieldPattern.MatchString(parts[0]) {
72 continue
73 }
74
75 ch <- prometheus.MustNewConstMetric(
76 prometheus.NewDesc(
77 prometheus.BuildFQName(namespace, vmStatSubsystem, parts[0]),
78 fmt.Sprintf("/proc/vmstat information field %s.", parts[0]),
79 nil, nil),
80 prometheus.UntypedValue,
81 value,
82 )
83 }
84 return scanner.Err()
85}

Callers

nothing calls this directly

Calls 2

procFilePathFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected