Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include and exclude filter for hwmon collector #2699

Merged
merged 20 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
be0ce61
Add include and exclude kingpin flags, following example in systemd c…
conallob May 23, 2023
15d6137
Rename unitInclude* and unitExclude* variables to systemdInclude* and
conallob May 23, 2023
7c49531
Revert "Rename unitInclude* and unitExclude* variables to systemdIncl…
conallob May 24, 2023
e7fa213
Run gofmt on hwmon_linux.go
conallob May 24, 2023
ca60247
Merge branch 'master' into hwmon-exclude-flags
conallob May 24, 2023
6e53c06
Merge branch 'hwmon-exclude-flags' of github.com:conallob/node_export…
conallob May 29, 2023
a8bcad3
Add checks against hwmonIncludePattern and hwmonExcludePattern, where…
conallob May 29, 2023
07c9cc9
Merge branch 'master' into hwmon-exclude-flags
conallob May 29, 2023
731483c
Run gofmt
conallob May 29, 2023
96d11fc
Merge branch 'hwmon-exclude-flags' of github.com:conallob/node_export…
conallob May 29, 2023
f8096b7
Add checks against hwmonIncludePattern and hwmonExcludePattern, where
conallob May 29, 2023
3f2605a
Merge branch 'hwmon-exclude-flags' of github.com:conallob/node_export…
conallob May 29, 2023
9168508
Don't return anything when including a device. Return nil, not err when
conallob May 29, 2023
4d7ea39
Merge branch 'prometheus:master' into hwmon-exclude-flags
conallob Jul 6, 2023
75ba1d0
Add hwmon device filtering, leveraging collector/device_filter.go, as
conallob Jul 6, 2023
e20df55
Remove superfluous regexp handling, device_filter.go handles this for us
conallob Jul 6, 2023
71dc549
Update collector/hwmon_linux.go
conallob Jul 6, 2023
af47909
Update filtering variable names to be HWmon Chips, not units
conallob Jul 6, 2023
5a1d5ee
Merge branch 'hwmon-exclude-flags' of github.com:conallob/node_export…
conallob Jul 6, 2023
03e4a4d
Skip hwmon chip if it's marked as ignored by device_filter
conallob Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ import (
"strconv"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)

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:_]")
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
hwmonLabelDesc = []string{"chip", "sensor"}
Expand All @@ -47,13 +51,18 @@ func init() {
}

type hwMonCollector struct {
logger log.Logger
deviceFilter deviceFilter
logger log.Logger
}

// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
// (similar to lm-sensors).
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 {
Expand Down Expand Up @@ -154,6 +163,10 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
return err
}

if c.deviceFilter.ignored(hwmonName) {
return nil
}

data := make(map[string]map[string]string)
err = collectSensorData(dir, data)
if err != nil {
Expand Down