qdisk-linux: Add exclude and include flags for interface name

Signed-off-by: binjip978 <pdp.eleven11@gmail.com>
Signed-off-by: Johannes 'fish' Ziemke <github@freigeist.org>
This commit is contained in:
binjip978 2022-04-10 11:58:01 +00:00 committed by Johannes 'fish' Ziemke
parent 0b82f402d0
commit c38e1e27ca
2 changed files with 24 additions and 10 deletions

View File

@ -18,6 +18,7 @@ package collector
import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
@ -28,6 +29,8 @@ import (
)
type qdiscStatCollector struct {
logger log.Logger
deviceFilter deviceFilter
bytes typedDesc
packets typedDesc
drops typedDesc
@ -35,11 +38,12 @@ type qdiscStatCollector struct {
overlimits typedDesc
qlength typedDesc
backlog typedDesc
logger log.Logger
}
var (
collectorQdisc = kingpin.Flag("collector.qdisc.fixtures", "test fixtures to use for qdisc collector end-to-end testing").Default("").String()
collectorQdiskDeviceInclude = kingpin.Flag("collector.qdisk.device-include", "Regexp of qdisk devices to include (mutually exclusive to device-exclude).").String()
collectorQdiskDeviceExclude = kingpin.Flag("collector.qdisk.device-exclude", "Regexp of qdisk devices to exclude (mutually exclusive to device-include).").String()
)
func init() {
@ -48,6 +52,10 @@ func init() {
// NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics.
func NewQdiscStatCollector(logger log.Logger) (Collector, error) {
if *collectorQdiskDeviceExclude != "" && *collectorQdiskDeviceInclude != "" {
return nil, fmt.Errorf("collector.qdisk.device-include and collector.qdisk.device-exclude are mutaly exclusive")
}
return &qdiscStatCollector{
bytes: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "qdisc", "bytes_total"),
@ -85,6 +93,7 @@ func NewQdiscStatCollector(logger log.Logger) (Collector, error) {
[]string{"device", "kind"}, nil,
), prometheus.GaugeValue},
logger: logger,
deviceFilter: newDeviceFilter(*collectorQdiskDeviceExclude, *collectorQdiskDeviceExclude),
}, nil
}
@ -122,6 +131,10 @@ func (c *qdiscStatCollector) Update(ch chan<- prometheus.Metric) error {
continue
}
if c.deviceFilter.ignored(msg.IfaceName) {
continue
}
ch <- c.bytes.mustNewConstMetric(float64(msg.Bytes), msg.IfaceName, msg.Kind)
ch <- c.packets.mustNewConstMetric(float64(msg.Packets), msg.IfaceName, msg.Kind)
ch <- c.drops.mustNewConstMetric(float64(msg.Drops), msg.IfaceName, msg.Kind)

View File

@ -128,6 +128,7 @@ fi
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
--collector.wifi.fixtures="collector/fixtures/wifi" \
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \
--collector.qdisk.device-include="(wlan0|eth0)" \
--collector.arp.device-exclude="nope" \
--collector.netclass.ignored-devices="(dmz|int)" \
--collector.netclass.ignore-invalid-speed \