aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Zakharov <zakharov.a.g@yandex.ru>2020-08-10 17:50:58 +0300
committerGitHub <noreply@github.com>2020-08-10 16:50:58 +0200
commit3b035c8fa1f75c4c00e57acc14fb71dfd62e31ee (patch)
tree4ea44b6c47da6f5ab406f7f70c2652490e4f07ee
parent503e4fc8486c0082d6bd8c53fad646bcfafeedf6 (diff)
downloadprometheus_node_collector-master.tar.bz2
prometheus_node_collector-master.tar.xz
prometheus_node_collector-master.zip
bcache: add priorityStats flag (#1621)HEADmaster
* bcache: add priorityStats flag Fixes #1593 Signed-off-by: Aleksei Zakharov <zaharov@selectel.ru>
-rw-r--r--collector/bcache_linux.go50
-rwxr-xr-xend-to-end-test.sh1
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 (
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
27var (
28 priorityStats = kingpin.Flag("collector.bcache.priorityStats", "Expose expensive priority stats.").Bool()
24) 29)
25 30
26func init() { 31func 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.
52func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error { 57func (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 }
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
106 --collector.wifi.fixtures="collector/fixtures/wifi" \ 106 --collector.wifi.fixtures="collector/fixtures/wifi" \
107 --collector.qdisc.fixtures="collector/fixtures/qdisc/" \ 107 --collector.qdisc.fixtures="collector/fixtures/qdisc/" \
108 --collector.netclass.ignored-devices="(bond0|dmz|int)" \ 108 --collector.netclass.ignored-devices="(bond0|dmz|int)" \
109 --collector.bcache.priorityStats \
109 --collector.cpu.info \ 110 --collector.cpu.info \
110 --collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \ 111 --collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \
111 --collector.cpu.info.bugs-include="^(cpu_meltdown|spectre_.*|mds)$" \ 112 --collector.cpu.info.bugs-include="^(cpu_meltdown|spectre_.*|mds)$" \