Skip to content

Commit

Permalink
Add interrupts collector filtering (#3028)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SuperQ authored Jul 14, 2024
1 parent 2ce82ca commit e0c4a47
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions collector/interrupts_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@
package collector

import (
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)

type interruptsCollector struct {
desc typedDesc
logger log.Logger
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{
Expand All @@ -39,6 +48,8 @@ func NewInterruptsCollector(logger log.Logger) (Collector, error) {
"Interrupt details.",
interruptLabelNames, nil,
), prometheus.CounterValue},
logger: logger,
logger: logger,
nameFilter: newDeviceFilter(*interruptsExclude, *interruptsInclude),
includeZeros: *interruptsIncludeZeros,
}, nil
}
10 changes: 10 additions & 0 deletions collector/interrupts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strconv"
"strings"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -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)
}
}
Expand Down
13 changes: 12 additions & 1 deletion collector/interrupts_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strconv"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -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,
)
}
Expand Down
13 changes: 12 additions & 1 deletion collector/interrupts_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strconv"
"unsafe"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -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,
)
}
Expand Down

0 comments on commit e0c4a47

Please sign in to comment.