Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert "Rename unitInclude* and unitExclude* variables to systemdIncl…
…ude* and"

This reverts commit 15d6137.

Signed-off-by: Conall O'Brien <[email protected]>
  • Loading branch information
conallob committed May 24, 2023
commit 7c49531c9c76b2bdd0fe6979d2b2c81a4e2ad5c7
38 changes: 19 additions & 19 deletions collector/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const (
)

var (
systemdIncludeSet bool
systemdInclude = kingpin.Flag("collector.systemd.unit-include", "Regexp of systemd units to include. Units must both match include and not match exclude to be included.").Default(".+").PreAction(func(c *kingpin.ParseContext) error {
systemdIncludeSet = true
unitIncludeSet bool
unitInclude = kingpin.Flag("collector.systemd.unit-include", "Regexp of systemd units to include. Units must both match include and not match exclude to be included.").Default(".+").PreAction(func(c *kingpin.ParseContext) error {
unitIncludeSet = true
return nil
}).String()
oldUnitInclude = kingpin.Flag("collector.systemd.unit-whitelist", "DEPRECATED: Use --collector.systemd.unit-include").Hidden().String()
systemdExcludeSet bool
systemdExclude = kingpin.Flag("collector.systemd.unit-exclude", "Regexp of systemd units to exclude. Units must both match include and not match exclude to be included.").Default(".+\\.(automount|device|mount|scope|slice)").PreAction(func(c *kingpin.ParseContext) error {
systemdExcludeSet = true
unitExcludeSet bool
unitExclude = kingpin.Flag("collector.systemd.unit-exclude", "Regexp of systemd units to exclude. Units must both match include and not match exclude to be included.").Default(".+\\.(automount|device|mount|scope|slice)").PreAction(func(c *kingpin.ParseContext) error {
unitExcludeSet = true
return nil
}).String()
oldUnitExclude = kingpin.Flag("collector.systemd.unit-blacklist", "DEPRECATED: Use collector.systemd.unit-exclude").Hidden().String()
Expand All @@ -75,8 +75,8 @@ type systemdCollector struct {
socketCurrentConnectionsDesc *prometheus.Desc
socketRefusedConnectionsDesc *prometheus.Desc
systemdVersionDesc *prometheus.Desc
systemdIncludePattern *regexp.Regexp
systemdExcludePattern *regexp.Regexp
unitIncludePattern *regexp.Regexp
unitExcludePattern *regexp.Regexp
logger log.Logger
}

Expand Down Expand Up @@ -134,25 +134,25 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) {
"Detected systemd version", []string{"version"}, nil)

if *oldUnitExclude != "" {
if !systemdExcludeSet {
if !unitExcludeSet {
level.Warn(logger).Log("msg", "--collector.systemd.unit-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-exclude")
*systemdExclude = *oldUnitExclude
*unitExclude = *oldUnitExclude
} else {
return nil, errors.New("--collector.systemd.unit-blacklist and --collector.systemd.unit-exclude are mutually exclusive")
}
}
if *oldUnitInclude != "" {
if !systemdIncludeSet {
if !unitIncludeSet {
level.Warn(logger).Log("msg", "--collector.systemd.unit-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-include")
*systemdInclude = *oldUnitInclude
*unitInclude = *oldUnitInclude
} else {
return nil, errors.New("--collector.systemd.unit-whitelist and --collector.systemd.unit-include are mutually exclusive")
}
}
level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-include", "flag", *systemdInclude)
systemdIncludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdInclude))
level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-exclude", "flag", *systemdExclude)
systemdExcludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdExclude))
level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-include", "flag", *unitInclude)
unitIncludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitInclude))
level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-exclude", "flag", *unitExclude)
unitExcludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitExclude))

return &systemdCollector{
unitDesc: unitDesc,
Expand All @@ -167,8 +167,8 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) {
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
socketRefusedConnectionsDesc: socketRefusedConnectionsDesc,
systemdVersionDesc: systemdVersionDesc,
systemdIncludePattern: systemdIncludePattern,
systemdExcludePattern: systemdExcludePattern,
unitIncludePattern: unitIncludePattern,
unitExcludePattern: unitExcludePattern,
logger: logger,
}, nil
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error {
level.Debug(c.logger).Log("msg", "collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds())

begin = time.Now()
units := filterUnits(allUnits, c.systemdIncludePattern, c.systemdExcludePattern, c.logger)
units := filterUnits(allUnits, c.unitIncludePattern, c.unitExcludePattern, c.logger)
level.Debug(c.logger).Log("msg", "filterUnits took", "duration_seconds", time.Since(begin).Seconds())

var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion collector/systemd_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestSystemdIgnoreFilterDefaultKeepsAll(t *testing.T) {
}
fixtures := getUnitListFixtures()
collector := c.(*systemdCollector)
filtered := filterUnits(fixtures[0], collector.systemdIncludePattern, collector.systemdExcludePattern, logger)
filtered := filterUnits(fixtures[0], collector.unitIncludePattern, collector.unitExcludePattern, logger)
// Adjust fixtures by 3 "not-found" units.
if len(filtered) != len(fixtures[0])-3 {
t.Error("Default filters removed units")
Expand Down