Update retrieves and exports bcachefs statistics.
(ch chan<- prometheus.Metric)
| 132 | |
| 133 | // Update retrieves and exports bcachefs statistics. |
| 134 | func (c *bcachefsCollector) Update(ch chan<- prometheus.Metric) error { |
| 135 | stats, err := c.fs.Stats() |
| 136 | if err != nil { |
| 137 | if os.IsNotExist(err) { |
| 138 | c.logger.Debug("bcachefs sysfs path does not exist", "path", sysFilePath("fs/bcachefs")) |
| 139 | return ErrNoData |
| 140 | } |
| 141 | return fmt.Errorf("failed to retrieve bcachefs stats: %w", err) |
| 142 | } |
| 143 | |
| 144 | if len(stats) == 0 { |
| 145 | return ErrNoData |
| 146 | } |
| 147 | |
| 148 | for _, s := range stats { |
| 149 | uuid := s.UUID |
| 150 | |
| 151 | ch <- prometheus.MustNewConstMetric( |
| 152 | bcachefsInfoDesc, |
| 153 | prometheus.GaugeValue, |
| 154 | 1, |
| 155 | uuid, |
| 156 | ) |
| 157 | |
| 158 | ch <- prometheus.MustNewConstMetric( |
| 159 | bcachefsBtreeCacheSizeBytes, |
| 160 | prometheus.GaugeValue, |
| 161 | float64(s.BtreeCacheSizeBytes), |
| 162 | uuid, |
| 163 | ) |
| 164 | |
| 165 | for algorithm, comp := range s.Compression { |
| 166 | ch <- prometheus.MustNewConstMetric( |
| 167 | bcachefsCompressionCompressedBytesDesc, |
| 168 | prometheus.GaugeValue, |
| 169 | float64(comp.CompressedBytes), |
| 170 | uuid, algorithm, |
| 171 | ) |
| 172 | ch <- prometheus.MustNewConstMetric( |
| 173 | bcachefsCompressionUncompressedBytesDesc, |
| 174 | prometheus.GaugeValue, |
| 175 | float64(comp.UncompressedBytes), |
| 176 | uuid, algorithm, |
| 177 | ) |
| 178 | } |
| 179 | |
| 180 | for errorType, errStats := range s.Errors { |
| 181 | ch <- prometheus.MustNewConstMetric( |
| 182 | bcachefsErrorsTotalDesc, |
| 183 | prometheus.CounterValue, |
| 184 | float64(errStats.Count), |
| 185 | uuid, errorType, |
| 186 | ) |
| 187 | } |
| 188 | |
| 189 | for counterName, counterStats := range s.Counters { |
| 190 | metricName := SanitizeMetricName(counterName) + "_total" |
| 191 | ch <- prometheus.MustNewConstMetric( |
nothing calls this directly
no test coverage detected