bcache: add priorityStats flag (#1621)
* bcache: add priorityStats flag Fixes #1593 Signed-off-by: Aleksei Zakharov <zaharov@selectel.ru>
This commit is contained in:
parent
503e4fc848
commit
3b035c8fa1
|
@ -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,7 +270,10 @@ func (c *bcacheCollector) updateBcacheStats(ch chan<- prometheus.Metric, s *bcac
|
|||
extraLabel: []string{"cache_device"},
|
||||
extraLabelValue: cache.Name,
|
||||
},
|
||||
}
|
||||
if *priorityStats {
|
||||
// metrics in /sys/fs/bcache/<uuid>/<cache>/priority_stats
|
||||
priorityStatsMetrics := []bcacheMetric{
|
||||
{
|
||||
name: "priority_stats_unused_percent",
|
||||
desc: "The percentage of the cache that doesn't contain any data.",
|
||||
|
@ -277,6 +291,8 @@ func (c *bcacheCollector) updateBcacheStats(ch chan<- prometheus.Metric, s *bcac
|
|||
extraLabelValue: cache.Name,
|
||||
},
|
||||
}
|
||||
metrics = append(metrics, priorityStatsMetrics...)
|
||||
}
|
||||
allMetrics = append(allMetrics, metrics...)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)$" \
|
||||
|
|
Loading…
Reference in New Issue