Skip to content

slabinfo: Add filters for slab name. #3041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
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 | mount-points | N/A | --collector.filesystem.mount-points-exclude
hwmon | chip | --collector.hwmon.chip-include | --collector.hwmon.chip-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
sysctl | all | --collector.sysctl.include | N/A
systemd | unit | --collector.systemd.unit-include | --collector.systemd.unit-exclude

Expand Down
25 changes: 18 additions & 7 deletions collector/slabinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ package collector
import (
"fmt"

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

var (
slabNameInclude = kingpin.Flag("collector.slabinfo.slabs-include", "Regexp of slabs to include in slabinfo collector.").Default(".*").String()
slabNameExclude = kingpin.Flag("collector.slabinfo.slabs-exclude", "Regexp of slabs to exclude in slabinfo collector.").Default("").String()
)

type slabinfoCollector struct {
fs procfs.FS
logger log.Logger
subsystem string
labels []string
fs procfs.FS
logger log.Logger
subsystem string
labels []string
slabNameFilter deviceFilter
}

func init() {
Expand All @@ -42,9 +49,10 @@ func NewSlabinfoCollector(logger log.Logger) (Collector, error) {
}

return &slabinfoCollector{logger: logger,
fs: fs,
subsystem: "slabinfo",
labels: []string{"slab"},
fs: fs,
subsystem: "slabinfo",
labels: []string{"slab"},
slabNameFilter: newDeviceFilter(*slabNameExclude, *slabNameInclude),
}, nil
}

Expand All @@ -55,6 +63,9 @@ func (c *slabinfoCollector) Update(ch chan<- prometheus.Metric) error {
}

for _, slab := range slabinfo.Slabs {
if c.slabNameFilter.ignored(slab.Name) {
continue
}
ch <- c.activeObjects(slab.Name, slab.ObjActive)
ch <- c.objects(slab.Name, slab.ObjNum)
ch <- c.objectSizeBytes(slab.Name, slab.ObjSize)
Expand Down