Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## master / unreleased

* [CHANGE]
* [FEATURE]
* [FEATURE] Add device filtering to the infiniband collector #3694
* [ENHANCEMENT]
* [BUGFIX]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ filesystem | fs-types | --collector.filesystem.fs-types-include | --collector.fi
filesystem | mount-points | --collector.filesystem.mount-points-include | --collector.filesystem.mount-points-exclude
hwmon | chip | --collector.hwmon.chip-include | --collector.hwmon.chip-exclude
hwmon | sensor | --collector.hwmon.sensor-include | --collector.hwmon.sensor-exclude
infiniband | device | --collector.infiniband.device-include | --collector.infiniband.device-exclude
interrupts | name | --collector.interrupts.name-include | --collector.interrupts.name-exclude
netdev | device | --collector.netdev.device-include | --collector.netdev.device-exclude
qdisk | device | --collector.qdisk.device-include | --collector.qdisk.device-exclude
Expand Down
27 changes: 23 additions & 4 deletions collector/infiniband_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ import (
"os"
"strconv"

"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
)

var (
infinibandDeviceInclude = kingpin.Flag("collector.infiniband.device-include", "Regexp of infiniband devices to include (mutually exclusive to device-exclude).").String()
infinibandDeviceExclude = kingpin.Flag("collector.infiniband.device-exclude", "Regexp of infiniband devices to exclude (mutually exclusive to device-include).").String()
)

type infinibandCollector struct {
fs sysfs.FS
metricDescs map[string]*prometheus.Desc
logger *slog.Logger
subsystem string
fs sysfs.FS
metricDescs map[string]*prometheus.Desc
logger *slog.Logger
subsystem string
deviceFilter deviceFilter
}

func init() {
Expand Down Expand Up @@ -129,6 +136,14 @@ func NewInfiniBandCollector(logger *slog.Logger) (Collector, error) {
)
}

if *infinibandDeviceInclude != "" {
i.logger.Info("Parsed flag --collector.infiniband.device-include", "flag", *infinibandDeviceInclude)
}
if *infinibandDeviceExclude != "" {
i.logger.Info("Parsed flag --collector.infiniband.device-exclude", "flag", *infinibandDeviceExclude)
}
i.deviceFilter = newDeviceFilter(*infinibandDeviceExclude, *infinibandDeviceInclude)

return &i, nil
}

Expand All @@ -153,6 +168,10 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error {
}

for _, device := range devices {
if c.deviceFilter.ignored(device.Name) {
continue
}

infoDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, c.subsystem, "info"),
"Non-numeric data from /sys/class/infiniband/<device>, value is always 1.",
Expand Down