Perf: Add white/black-listing of volumes

This commit is contained in:
Calle Pettersson 2016-08-27 10:00:14 +02:00
parent 663d438001
commit 5f05452a23

View File

@ -4,12 +4,20 @@
package collectors package collectors
import ( import (
"flag"
"fmt"
"log" "log"
"regexp"
"github.com/StackExchange/wmi" "github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus" "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 // A PerfCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfDisk_LogicalDisk metrics
type PerfCollector struct { type PerfCollector struct {
AvgDiskBytesPerRead *prometheus.Desc AvgDiskBytesPerRead *prometheus.Desc
@ -46,6 +54,9 @@ type PerfCollector struct {
PercentIdleTime *prometheus.Desc PercentIdleTime *prometheus.Desc
PercentIdleTime_Base *prometheus.Desc PercentIdleTime_Base *prometheus.Desc
SplitIOPerSec *prometheus.Desc SplitIOPerSec *prometheus.Desc
volumeWhitelistPattern *regexp.Regexp
volumeBlacklistPattern *regexp.Regexp
} }
// NewPerfCollector ... // NewPerfCollector ...
@ -289,6 +300,9 @@ func NewPerfCollector() *PerfCollector {
[]string{"volume"}, []string{"volume"},
nil, 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 { for _, volume := range dst {
if c.volumeBlacklistPattern.MatchString(volume.Name) || !c.volumeWhitelistPattern.MatchString(volume.Name) {
continue
}
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.AvgDiskBytesPerRead, c.AvgDiskBytesPerRead,
prometheus.GaugeValue, prometheus.GaugeValue,