Greatly reduce the metrics vmstat returns by default.

Vmstat has over 100 fields, most of which are highly
detailed debug information. Trim this down to only
essential fields by default, configurable by flag.

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
Brian Brazil 2018-03-29 16:34:52 +01:00
commit 499c342fed
4 changed files with 156 additions and 4 deletions

View file

@ -19,17 +19,25 @@ import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)
const (
vmStatSubsystem = "vmstat"
)
type vmStatCollector struct{}
var (
vmStatFields = kingpin.Flag("collector.vmstat.fields", "Regexp of fields to return for vmstat collector.").Default("^(pgpg|pswp|pg.*fault|oom_kill).*").String()
)
type vmStatCollector struct {
fieldPattern *regexp.Regexp
}
func init() {
registerCollector("vmstat", defaultEnabled, NewvmStatCollector)
@ -37,7 +45,10 @@ func init() {
// NewvmStatCollector returns a new Collector exposing vmstat stats.
func NewvmStatCollector() (Collector, error) {
return &vmStatCollector{}, nil
pattern := regexp.MustCompile(*vmStatFields)
return &vmStatCollector{
fieldPattern: pattern,
}, nil
}
func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
@ -54,6 +65,9 @@ func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
return err
}
if !c.fieldPattern.MatchString(parts[0]) {
continue
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(