Add --collector.netdev.device-whitelist flag (#1279)
* Add --collector.netdev.device-whitelist flag Sometimes it is desired to monitor only one netdev. The golang regexp does not support a negated regex, so the ignored-devices flag is too cumbersome for this task. This change introduces a new flag: accept-devices, which is mutually exclusive to ignored-devices. This flag allows specifying ONLY the netdev you'd like. Signed-off-by: Noam Meltzer <noam@cynerio.co>
This commit is contained in:
parent
fc02b5dfbc
commit
501ccf9fb4
7 changed files with 72 additions and 16 deletions
|
|
@ -27,7 +27,7 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error) {
|
||||
func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) {
|
||||
netDev := map[string]map[string]string{}
|
||||
|
||||
ifs, err := net.Interfaces()
|
||||
|
|
@ -46,6 +46,10 @@ func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error)
|
|||
log.Debugf("Ignoring device: %s", iface.Name)
|
||||
continue
|
||||
}
|
||||
if accept != nil && !accept.MatchString(iface.Name) {
|
||||
log.Debugf("Ignoring device: %s", iface.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
devStats := map[string]string{}
|
||||
devStats["receive_packets"] = strconv.FormatUint(ifaceData.Data.Ipackets, 10)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue