(ch chan<- prometheus.Metric)
| 44 | } |
| 45 | |
| 46 | func (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 | |
| 68 | func parseFileFDStats(filename string) (map[string]string, error) { |
| 69 | file, err := os.Open(filename) |
nothing calls this directly
no test coverage detected