Skip to content

Commit

Permalink
Add hwmon device filtering, leveraging collector/device_filter.go, as
Browse files Browse the repository at this point in the history
demonstrated by prometheus#2432

Signed-off-by: Conall O'Brien <conall@conall.net>
  • Loading branch information
conallob committed Jul 6, 2023
1 parent 4d7ea39 commit 75ba1d0
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ import (
)

var (
hwmonIncludeSet bool
hwmonInclude = kingpin.Flag("collector.hwmon.unit-include", "Regexp of hwmon units to include. Units must both match include and not match exclude to be included.").Default(".+").PreAction(func(c *kingpin.ParseContext) error {
hwmonIncludeSet = true
return nil
}).String()
hwmonExcludeSet bool
hwmonExclude = kingpin.Flag("collector.hwmon.unit-exclude", "Regexp of hwmon units to exclude. Units must both match include and not match exclude to be included.").Default("").PreAction(func(c *kingpin.ParseContext) error {
hwmonExcludeSet = true
return nil
}).String()
collectorHWmonUnitInclude = kingpin.Flag("collector.hwmon.unit-include", "Regexp of hwmon devices to include (mutually exclusive to device-exclude).").String()
collectorHWmonUnitExclude = kingpin.Flag("collector.hwmon.unit-exclude", "Regexp of hwmon devices 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>.+))?$`)
Expand All @@ -60,24 +52,17 @@ func init() {
}

type hwMonCollector struct {
hwmonIncludePattern *regexp.Regexp
hwmonExcludePattern *regexp.Regexp
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) {

level.Info(logger).Log("msg", "Parsed flag --collector.hwmon.unit-include", "flag", *hwmonInclude)
hwmonIncludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *hwmonInclude))
level.Info(logger).Log("msg", "Parsed flag --collector.hwmon.unit-exclude", "flag", *hwmonExclude)
hwmonExcludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *hwmonExclude))

return &hwMonCollector{
hwmonIncludePattern: hwmonIncludePattern,
hwmonExcludePattern: hwmonExcludePattern,
logger: logger,
logger: logger,
deviceFilter: newDeviceFilter(*collectorHWmonUnitExclude, *collectorHWmonUnitExclude),
}, nil
}

Expand Down

0 comments on commit 75ba1d0

Please sign in to comment.