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

Method Update

collector/filefd_linux.go:46–66  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

44}
45
46func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error {
47 fileFDStat, err := parseFileFDStats(procFilePath("sys/fs/file-nr"))
48 if err != nil {
49 return fmt.Errorf("couldn't get file-nr: %w", err)
50 }
51 for name, value := range fileFDStat {
52 v, err := strconv.ParseFloat(value, 64)
53 if err != nil {
54 return fmt.Errorf("invalid value %s in file-nr: %w", value, err)
55 }
56 ch <- prometheus.MustNewConstMetric(
57 prometheus.NewDesc(
58 prometheus.BuildFQName(namespace, fileFDStatSubsystem, name),
59 fmt.Sprintf("File descriptor statistics: %s.", name),
60 nil, nil,
61 ),
62 prometheus.GaugeValue, v,
63 )
64 }
65 return nil
66}
67
68func parseFileFDStats(filename string) (map[string]string, error) {
69 file, err := os.Open(filename)

Callers

nothing calls this directly

Calls 2

parseFileFDStatsFunction · 0.85
procFilePathFunction · 0.85

Tested by

no test coverage detected