From 5f05452a23358ad4709752544c2d52f393108280 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Sat, 27 Aug 2016 10:00:14 +0200 Subject: [PATCH] Perf: Add white/black-listing of volumes --- collectors/perf.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/collectors/perf.go b/collectors/perf.go index 775e9d14..34b90fca 100644 --- a/collectors/perf.go +++ b/collectors/perf.go @@ -4,12 +4,20 @@ package collectors import ( + "flag" + "fmt" "log" + "regexp" "github.com/StackExchange/wmi" "github.com/prometheus/client_golang/prometheus" ) +var ( + volumeWhitelist = flag.String("collector.perf.volume-whitelist", ".+", "Regexp of volumes to whitelist. Volume name must both match whitelist and not match blacklist to be included.") + volumeBlacklist = flag.String("collector.perf.volume-blacklist", "_Total", "Regexp of volumes to blacklist. Volume name must both match whitelist and not match blacklist to be included.") +) + // A PerfCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfDisk_LogicalDisk metrics type PerfCollector struct { AvgDiskBytesPerRead *prometheus.Desc @@ -46,6 +54,9 @@ type PerfCollector struct { PercentIdleTime *prometheus.Desc PercentIdleTime_Base *prometheus.Desc SplitIOPerSec *prometheus.Desc + + volumeWhitelistPattern *regexp.Regexp + volumeBlacklistPattern *regexp.Regexp } // NewPerfCollector ... @@ -289,6 +300,9 @@ func NewPerfCollector() *PerfCollector { []string{"volume"}, nil, ), + + volumeWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeWhitelist)), + volumeBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeBlacklist)), } } @@ -387,6 +401,10 @@ func (c *PerfCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, } for _, volume := range dst { + if c.volumeBlacklistPattern.MatchString(volume.Name) || !c.volumeWhitelistPattern.MatchString(volume.Name) { + continue + } + ch <- prometheus.MustNewConstMetric( c.AvgDiskBytesPerRead, prometheus.GaugeValue,