Skip to content

Commit 614dace

Browse files
conallobSuperQ
authored andcommitted
Add include and exclude filter for hwmon collector (prometheus#2699)
* Add include and exclude flags chip name flags to hwmon collector, following example in systemd collector --------- Signed-off-by: Conall O'Brien <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
1 parent 306a99b commit 614dace

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

collector/hwmon_linux.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ import (
2424
"strconv"
2525
"strings"
2626

27+
"github.com/alecthomas/kingpin/v2"
2728
"github.com/go-kit/log"
2829
"github.com/go-kit/log/level"
2930
"github.com/prometheus/client_golang/prometheus"
3031
"golang.org/x/sys/unix"
3132
)
3233

3334
var (
35+
collectorHWmonChipInclude = kingpin.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String()
36+
collectorHWmonChipExclude = kingpin.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String()
37+
3438
hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
3539
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
3640
hwmonLabelDesc = []string{"chip", "sensor"}
@@ -47,13 +51,18 @@ func init() {
4751
}
4852

4953
type hwMonCollector struct {
50-
logger log.Logger
54+
deviceFilter deviceFilter
55+
logger log.Logger
5156
}
5257

5358
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
5459
// (similar to lm-sensors).
5560
func NewHwMonCollector(logger log.Logger) (Collector, error) {
56-
return &hwMonCollector{logger}, nil
61+
62+
return &hwMonCollector{
63+
logger: logger,
64+
deviceFilter: newDeviceFilter(*collectorHWmonChipExclude, *collectorHWmonChipExclude),
65+
}, nil
5766
}
5867

5968
func cleanMetricName(name string) string {
@@ -154,6 +163,10 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
154163
return err
155164
}
156165

166+
if c.deviceFilter.ignored(hwmonName) {
167+
return nil
168+
}
169+
157170
data := make(map[string]map[string]string)
158171
err = collectSensorData(dir, data)
159172
if err != nil {

0 commit comments

Comments
 (0)