Skip to content

Commit

Permalink
Perf: Add white/black-listing of volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Aug 27, 2016
1 parent 663d438 commit 5f05452
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions collectors/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,6 +54,9 @@ type PerfCollector struct {
PercentIdleTime *prometheus.Desc
PercentIdleTime_Base *prometheus.Desc
SplitIOPerSec *prometheus.Desc

volumeWhitelistPattern *regexp.Regexp
volumeBlacklistPattern *regexp.Regexp
}

// NewPerfCollector ...
Expand Down Expand Up @@ -289,6 +300,9 @@ func NewPerfCollector() *PerfCollector {
[]string{"volume"},
nil,
),

volumeWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeWhitelist)),
volumeBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeBlacklist)),
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5f05452

Please sign in to comment.