From 3b035c8fa1f75c4c00e57acc14fb71dfd62e31ee Mon Sep 17 00:00:00 2001 From: Aleksei Zakharov Date: Mon, 10 Aug 2020 17:50:58 +0300 Subject: bcache: add priorityStats flag (#1621) * bcache: add priorityStats flag Fixes #1593 Signed-off-by: Aleksei Zakharov --- collector/bcache_linux.go | 50 +++++++++++++++++++++++++++++++---------------- end-to-end-test.sh | 1 + 2 files changed, 34 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 ( "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/bcache" + "gopkg.in/alecthomas/kingpin.v2" +) + +var ( + priorityStats = kingpin.Flag("collector.bcache.priorityStats", "Expose expensive priority stats.").Bool() ) func init() { @@ -50,7 +55,13 @@ func NewBcacheCollector(logger log.Logger) (Collector, error) { // Update reads and exposes bcache stats. // It implements the Collector interface. func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error { - stats, err := c.fs.Stats() + var stats []*bcache.Stats + var err error + if *priorityStats { + stats, err = c.fs.Stats() + } else { + stats, err = c.fs.StatsWithoutPriority() + } if err != nil { return fmt.Errorf("failed to retrieve bcache stats: %w", err) } @@ -259,23 +270,28 @@ func (c *bcacheCollector) updateBcacheStats(ch chan<- prometheus.Metric, s *bcac extraLabel: []string{"cache_device"}, extraLabelValue: cache.Name, }, + } + if *priorityStats { // metrics in /sys/fs/bcache///priority_stats - { - name: "priority_stats_unused_percent", - desc: "The percentage of the cache that doesn't contain any data.", - value: float64(cache.Priority.UnusedPercent), - metricType: prometheus.GaugeValue, - extraLabel: []string{"cache_device"}, - extraLabelValue: cache.Name, - }, - { - name: "priority_stats_metadata_percent", - desc: "Bcache's metadata overhead.", - value: float64(cache.Priority.MetadataPercent), - metricType: prometheus.GaugeValue, - extraLabel: []string{"cache_device"}, - extraLabelValue: cache.Name, - }, + priorityStatsMetrics := []bcacheMetric{ + { + name: "priority_stats_unused_percent", + desc: "The percentage of the cache that doesn't contain any data.", + value: float64(cache.Priority.UnusedPercent), + metricType: prometheus.GaugeValue, + extraLabel: []string{"cache_device"}, + extraLabelValue: cache.Name, + }, + { + name: "priority_stats_metadata_percent", + desc: "Bcache's metadata overhead.", + value: float64(cache.Priority.MetadataPercent), + metricType: prometheus.GaugeValue, + extraLabel: []string{"cache_device"}, + extraLabelValue: cache.Name, + }, + } + metrics = append(metrics, priorityStatsMetrics...) } allMetrics = append(allMetrics, metrics...) } diff --git a/end-to-end-test.sh b/end-to-end-test.sh index 955ab1d..2406061 100755 --- a/end-to-end-test.sh +++ b/end-to-end-test.sh @@ -106,6 +106,7 @@ fi --collector.wifi.fixtures="collector/fixtures/wifi" \ --collector.qdisc.fixtures="collector/fixtures/qdisc/" \ --collector.netclass.ignored-devices="(bond0|dmz|int)" \ + --collector.bcache.priorityStats \ --collector.cpu.info \ --collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \ --collector.cpu.info.bugs-include="^(cpu_meltdown|spectre_.*|mds)$" \ -- cgit v1.2.3