Add interrupts collector filtering (#3028)

In order to reduce cardinality of the interrupts collector add
filtering options
* Add include/exclude regexp filter flags.
* Add boolean flag to include zero values, enabled by default.

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2024-07-14 10:17:20 -04:00 committed by GitHub
parent 2ce82ca8e8
commit e0c4a47a02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 5 deletions

View File

@ -103,6 +103,7 @@ filesystem | fs-types | N/A | --collector.filesystem.fs-types-exclude
filesystem | mount-points | N/A | --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
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
slabinfo | slab-names | --collector.slabinfo.slabs-include | --collector.slabinfo.slabs-exclude

View File

@ -18,6 +18,7 @@
package collector
import (
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
@ -25,12 +26,20 @@ import (
type interruptsCollector struct {
desc typedDesc
logger log.Logger
nameFilter deviceFilter
includeZeros bool
}
func init() {
registerCollector("interrupts", defaultDisabled, NewInterruptsCollector)
}
var (
interruptsInclude = kingpin.Flag("collector.interrupts.name-include", "Regexp of interrupts name to include (mutually exclusive to --collector.interrupts.name-exclude).").String()
interruptsExclude = kingpin.Flag("collector.interrupts.name-exclude", "Regexp of interrupts name to exclude (mutually exclusive to --collector.interrupts.name-include).").String()
interruptsIncludeZeros = kingpin.Flag("collector.interrupts.include-zeros", "Include interrupts that have a zero value").Default("true").Bool()
)
// NewInterruptsCollector returns a new Collector exposing interrupts stats.
func NewInterruptsCollector(logger log.Logger) (Collector, error) {
return &interruptsCollector{
@ -40,5 +49,7 @@ func NewInterruptsCollector(logger log.Logger) (Collector, error) {
interruptLabelNames, nil,
), prometheus.CounterValue},
logger: logger,
nameFilter: newDeviceFilter(*interruptsExclude, *interruptsInclude),
includeZeros: *interruptsIncludeZeros,
}, nil
}

View File

@ -25,6 +25,7 @@ import (
"strconv"
"strings"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -39,10 +40,19 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) {
}
for name, interrupt := range interrupts {
for cpuNo, value := range interrupt.values {
filterName := name + ";" + interrupt.info + ";" + interrupt.devices
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
continue
}
fv, err := strconv.ParseFloat(value, 64)
if err != nil {
return fmt.Errorf("invalid value %s in interrupts: %w", value, err)
}
if !c.includeZeros && fv == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices)
}
}

View File

@ -20,6 +20,7 @@ import (
"fmt"
"strconv"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
@ -106,10 +107,20 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error {
}
for dev, interrupt := range interrupts {
for cpuNo, value := range interrupt.values {
interruptType := fmt.Sprintf("%d", interrupt.vector)
filterName := interruptType + ";" + dev
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
continue
}
if !c.includeZeros && value == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(
value,
strconv.Itoa(cpuNo),
strconv.Itoa(interrupt.vector),
interruptType,
dev,
)
}

View File

@ -21,6 +21,7 @@ import (
"strconv"
"unsafe"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
@ -77,10 +78,20 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error {
}
for dev, interrupt := range interrupts {
for cpuNo, value := range interrupt.values {
interruptType := fmt.Sprintf("%d", interrupt.vector)
filterName := interruptType + ";" + dev
if c.nameFilter.ignored(filterName) {
level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName)
continue
}
if !c.includeZeros && value == 0.0 {
level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo)
continue
}
ch <- c.desc.mustNewConstMetric(
value,
strconv.Itoa(cpuNo),
fmt.Sprintf("%d", interrupt.vector),
interruptType,
dev,
)
}