Skip to content

Commit

Permalink
Net: improve interfaces excluding
Browse files Browse the repository at this point in the history
– excluded interfaces no longer appears on the first interation
– net_interface_exclude should match the name(folded)

Previously net_interface_exclude can exclude interface which name contains substring. This could result in some interfaces excluded by mistake

Now it should be clear separation of when to use net_interface_exclude and when to use net_interface_exclude_regex
  • Loading branch information
requilence committed Oct 10, 2018
1 parent 21d1441 commit aa78c4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fs_path_exclude = ['/mnt/*','h:'] # default []
fs_metrics = ['free_B','free_percent','used_B','used_percent','total_B','inodes_used_percent'] # default ['free_B','free_percent','total_B']

# Network
net_interface_exclude = ['QoS Packet','LightWeight Filter','Kernel Debug','Software Loopback','Pseudo-Interface','ISATAP','utun', 'awdl']
net_interface_exclude = ['utun', 'awdl']
net_interface_exclude_regex = ["en[1-9]"] # default [], default on windows: ["Pseudo-Interface"]
net_interface_exclude_disconnected = true # default true
net_interface_exclude_loopback = true # default true
Expand Down
63 changes: 34 additions & 29 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,14 @@ func (nw *netWatcher) Results() (MeasurementsMap, error) {
}

for _, netIf := range interfaces {
if nw.cagent.NetInterfaceExcludeDisconnected {
up := false
for _, flag := range netIf.Flags {
if flag == "up" {
up = true
break
}
}
if !up {
log.Debugf("[NET] down interface excluded: %s", netIf.Name)
continue
}
}

if ifExcluded, cacheExists := nw.ExcludedInterfaceCache[netIf.Name]; cacheExists {
if ifExcluded {
if isExcluded, cacheExists := nw.ExcludedInterfaceCache[netIf.Name]; cacheExists {
if isExcluded {
log.Debugf("[NET] interface excluded: %s", netIf.Name)
continue
}
} else {
isExcluded := false

if nw.cagent.NetInterfaceExcludeLoopback {
loopback := false
for _, flag := range netIf.Flags {
Expand All @@ -81,32 +69,46 @@ func (nw *netWatcher) Results() (MeasurementsMap, error) {
break
}
}
nw.ExcludedInterfaceCache[netIf.Name] = loopback

if loopback {
log.Debugf("[NET] loopback interface excluded: %s", netIf.Name)
continue
isExcluded = true
}
}
ifExcluded := false
for _, excludedIf := range nw.cagent.NetInterfaceExclude {
if strings.Contains(strings.ToLower(netIf.Name), strings.ToLower(excludedIf)) {
ifExcluded = true
break

if !isExcluded && nw.cagent.NetInterfaceExcludeDisconnected {
up := false
for _, flag := range netIf.Flags {
if flag == "up" {
up = true
break
}
}
if !up {
isExcluded = true
}
}

if !isExcluded {
for _, excludedIf := range nw.cagent.NetInterfaceExclude {
if strings.EqualFold(netIf.Name, excludedIf) {
isExcluded = true
break
}
}
}

if !ifExcluded {
if !isExcluded {
for _, re := range netInterfaceExcludeRegexCompiled {
if re.MatchString(netIf.Name) {
ifExcluded = true
isExcluded = true
break
}
}
}

nw.ExcludedInterfaceCache[netIf.Name] = ifExcluded
nw.ExcludedInterfaceCache[netIf.Name] = isExcluded

if ifExcluded {
if isExcluded {
log.Debugf("[NET] interface excluded: %s", netIf.Name)
continue
}
Expand All @@ -128,7 +130,7 @@ func (nw *netWatcher) Results() (MeasurementsMap, error) {
gotIOCountersAt := time.Now()
if nw.lastIOCounters != nil {
for _, counter := range counters {
if ifIncluded, exists := nw.ExcludedInterfaceCache[counter.Name]; exists && !ifIncluded {
if isExcluded, exists := nw.ExcludedInterfaceCache[counter.Name]; exists && !isExcluded {
var previousIOCounters *net.IOCountersStat
for _, lastIOCounter := range nw.lastIOCounters {
if lastIOCounter.Name == counter.Name {
Expand Down Expand Up @@ -159,6 +161,9 @@ func (nw *netWatcher) Results() (MeasurementsMap, error) {
} else {
log.Debugf("[NET] IO stat is available starting at 2nd check")
for _, netIf := range interfaces {
if isExcluded, exists := nw.ExcludedInterfaceCache[netIf.Name]; exists && isExcluded {
continue
}
for _, metric := range nw.cagent.NetMetrics {
results[metric+"."+netIf.Name] = nil
}
Expand Down

0 comments on commit aa78c4c

Please sign in to comment.