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
|
|
@ -31,7 +31,7 @@ import (
|
|||
*/
|
||||
import "C"
|
||||
|
||||
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{}
|
||||
|
||||
var ifap, ifa *C.struct_ifaddrs
|
||||
|
|
@ -43,7 +43,11 @@ func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error)
|
|||
for ifa = ifap; ifa != nil; ifa = ifa.ifa_next {
|
||||
if ifa.ifa_addr.sa_family == C.AF_LINK {
|
||||
dev := C.GoString(ifa.ifa_name)
|
||||
if ignore.MatchString(dev) {
|
||||
if ignore != nil && ignore.MatchString(dev) {
|
||||
log.Debugf("Ignoring device: %s", dev)
|
||||
continue
|
||||
}
|
||||
if accept != nil && !accept.MatchString(dev) {
|
||||
log.Debugf("Ignoring device: %s", dev)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue