delay collecting virtual network interfaces (#15244)
Ilya Mashchenko committed
Jun 26, 2023 at 15:26 UTC
c1a95e17c442cbc8e65810d0df6132b7a74803d4
1 file changed
+16
collectors/proc.plugin/proc_net_dev.c
+16
@@ -57,6 +57,8 @@ static struct netdev {
57
int configured;
58
int enabled;
59
int updated;
60
+
61
+ time_t discover_time;
62
63
int carrier_file_exists;
64
time_t carrier_file_lost_time;
@@ -529,6 +531,7 @@ static inline void netdev_rename(struct netdev *d) {
531
if(unlikely(r && !r->processed)) {
532
netdev_rename_cgroup(d, r);
533
r->processed = 1;
534
+ d->discover_time = 0;
535
netdev_pending_renames--;
536
}
537
}
@@ -671,6 +674,8 @@ static struct netdev *get_netdev(const char *name) {
674
return d;
675
}
676
677
+#define NETDEV_VIRTUAL_COLLECT_DELAY 15 // 1 full run of the cgroups discovery thread (10 secs by default)
678
+
679
int do_proc_net_dev(int update_every, usec_t dt) {
680
(void)dt;
681
static SIMPLE_PATTERN *disabled_list = NULL;
@@ -747,6 +752,8 @@ int do_proc_net_dev(int update_every, usec_t dt) {
752
kernel_uint_t system_rbytes = 0;
753
kernel_uint_t system_tbytes = 0;
754
755
+ time_t now = now_realtime_sec();
756
+
757
size_t lines = procfile_lines(ff), l;
758
for(l = 2; l < lines ;l++) {
759
// require 17 words on each line
@@ -765,6 +772,7 @@ int do_proc_net_dev(int update_every, usec_t dt) {
772
773
// remember we configured it
774
d->configured = 1;
775
+ d->discover_time = now;
776
777
d->enabled = enable_new_interfaces;
778
@@ -826,6 +834,14 @@ int do_proc_net_dev(int update_every, usec_t dt) {
834
if(unlikely(!d->enabled))
835
continue;
836
837
+ // See https://github.com/netdata/netdata/issues/15206
838
+ // This is necessary to prevent the creation of charts for virtual interfaces that will later be
839
+ // recreated as container interfaces (create container) or
840
+ // rediscovered and recreated only to be deleted almost immediately (stop/remove container)
841
+ if (d->virtual && (now - d->discover_time < NETDEV_VIRTUAL_COLLECT_DELAY)) {
842
+ continue;
843
+ }
844
+
845
if(likely(d->do_bandwidth != CONFIG_BOOLEAN_NO || !d->virtual)) {
846
d->rbytes = str2kernel_uint_t(procfile_lineword(ff, l, 1));
847
d->tbytes = str2kernel_uint_t(procfile_lineword(ff, l, 9));