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:
parent
c8c144587e
commit
499c342fed
4 changed files with 156 additions and 4 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue