mirror of
https://github.com/prometheus/node_exporter
synced 2025-02-03 19:11:50 +00:00
Add include and exclude filter for hwmon collector (#2699)
* Add include and exclude flags chip name flags to hwmon collector, following example in systemd collector --------- Signed-off-by: Conall O'Brien <conall@conall.net> Co-authored-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
ed57c15e2c
commit
8b4dc82488
@ -24,6 +24,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -31,6 +32,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
collectorHWmonChipInclude = kingpin.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String()
|
||||||
|
collectorHWmonChipExclude = kingpin.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String()
|
||||||
|
|
||||||
hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
|
hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
|
||||||
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
|
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
|
||||||
hwmonLabelDesc = []string{"chip", "sensor"}
|
hwmonLabelDesc = []string{"chip", "sensor"}
|
||||||
@ -47,13 +51,18 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type hwMonCollector struct {
|
type hwMonCollector struct {
|
||||||
logger log.Logger
|
deviceFilter deviceFilter
|
||||||
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
|
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
|
||||||
// (similar to lm-sensors).
|
// (similar to lm-sensors).
|
||||||
func NewHwMonCollector(logger log.Logger) (Collector, error) {
|
func NewHwMonCollector(logger log.Logger) (Collector, error) {
|
||||||
return &hwMonCollector{logger}, nil
|
|
||||||
|
return &hwMonCollector{
|
||||||
|
logger: logger,
|
||||||
|
deviceFilter: newDeviceFilter(*collectorHWmonChipExclude, *collectorHWmonChipExclude),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanMetricName(name string) string {
|
func cleanMetricName(name string) string {
|
||||||
@ -154,6 +163,10 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.deviceFilter.ignored(hwmonName) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
data := make(map[string]map[string]string)
|
data := make(map[string]map[string]string)
|
||||||
err = collectSensorData(dir, data)
|
err = collectSensorData(dir, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user