diff options
Diffstat (limited to 'collector')
-rw-r--r-- | collector/bcache_linux.go | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/collector/bcache_linux.go b/collector/bcache_linux.go index 20995c7..7941025 100644 --- a/collector/bcache_linux.go +++ b/collector/bcache_linux.go | |||
@@ -21,6 +21,11 @@ import ( | |||
21 | "github.com/go-kit/kit/log" | 21 | "github.com/go-kit/kit/log" |
22 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/procfs/bcache" | 23 | "github.com/prometheus/procfs/bcache" |
24 | "gopkg.in/alecthomas/kingpin.v2" | ||
25 | ) | ||
26 | |||
27 | var ( | ||
28 | priorityStats = kingpin.Flag("collector.bcache.priorityStats", "Expose expensive priority stats.").Bool() | ||
24 | ) | 29 | ) |
25 | 30 | ||
26 | func init() { | 31 | func init() { |
@@ -50,7 +55,13 @@ func NewBcacheCollector(logger log.Logger) (Collector, error) { | |||
50 | // Update reads and exposes bcache stats. | 55 | // Update reads and exposes bcache stats. |
51 | // It implements the Collector interface. | 56 | // It implements the Collector interface. |
52 | func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error { | 57 | func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error { |
53 | stats, err := c.fs.Stats() | 58 | var stats []*bcache.Stats |
59 | var err error | ||
60 | if *priorityStats { | ||
61 | stats, err = c.fs.Stats() | ||
62 | } else { | ||
63 | stats, err = c.fs.StatsWithoutPriority() | ||
64 | } | ||
54 | if err != nil { | 65 | if err != nil { |
55 | return fmt.Errorf("failed to retrieve bcache stats: %w", err) | 66 | return fmt.Errorf("failed to retrieve bcache stats: %w", err) |
56 | } | 67 | } |
@@ -259,23 +270,28 @@ func (c *bcacheCollector) updateBcacheStats(ch chan<- prometheus.Metric, s *bcac | |||
259 | extraLabel: []string{"cache_device"}, | 270 | extraLabel: []string{"cache_device"}, |
260 | extraLabelValue: cache.Name, | 271 | extraLabelValue: cache.Name, |
261 | }, | 272 | }, |
273 | } | ||
274 | if *priorityStats { | ||
262 | // metrics in /sys/fs/bcache/<uuid>/<cache>/priority_stats | 275 | // metrics in /sys/fs/bcache/<uuid>/<cache>/priority_stats |
263 | { | 276 | priorityStatsMetrics := []bcacheMetric{ |
264 | name: "priority_stats_unused_percent", | 277 | { |
265 | desc: "The percentage of the cache that doesn't contain any data.", | 278 | name: "priority_stats_unused_percent", |
266 | value: float64(cache.Priority.UnusedPercent), | 279 | desc: "The percentage of the cache that doesn't contain any data.", |
267 | metricType: prometheus.GaugeValue, | 280 | value: float64(cache.Priority.UnusedPercent), |
268 | extraLabel: []string{"cache_device"}, | 281 | metricType: prometheus.GaugeValue, |
269 | extraLabelValue: cache.Name, | 282 | extraLabel: []string{"cache_device"}, |
270 | }, | 283 | extraLabelValue: cache.Name, |
271 | { | 284 | }, |
272 | name: "priority_stats_metadata_percent", | 285 | { |
273 | desc: "Bcache's metadata overhead.", | 286 | name: "priority_stats_metadata_percent", |
274 | value: float64(cache.Priority.MetadataPercent), | 287 | desc: "Bcache's metadata overhead.", |
275 | metricType: prometheus.GaugeValue, | 288 | value: float64(cache.Priority.MetadataPercent), |
276 | extraLabel: []string{"cache_device"}, | 289 | metricType: prometheus.GaugeValue, |
277 | extraLabelValue: cache.Name, | 290 | extraLabel: []string{"cache_device"}, |
278 | }, | 291 | extraLabelValue: cache.Name, |
292 | }, | ||
293 | } | ||
294 | metrics = append(metrics, priorityStatsMetrics...) | ||
279 | } | 295 | } |
280 | allMetrics = append(allMetrics, metrics...) | 296 | allMetrics = append(allMetrics, metrics...) |
281 | } | 297 | } |