fix(proc/proc_net_dev): delay collecting all virtual interfaces (#18812)
Ilya Mashchenko committed
Oct 18, 2024 at 13:18 UTC
707a4c78163ac41ee324eb72712bf871dc1dcd71
1 file changed
+26
-25
src/collectors/proc.plugin/proc_net_dev.c
+26
-25
@@ -12,7 +12,7 @@
12
13
#define READ_RETRY_PERIOD 60 // seconds
14
15
-time_t double_linked_device_collect_delay_secs = 120;
15
+time_t virtual_device_collect_delay_secs = 40;
16
17
enum {
18
NETDEV_DUPLEX_UNKNOWN,
@@ -92,7 +92,6 @@ static struct netdev {
92
int enabled;
93
bool updated;
94
bool function_ready;
95
- bool double_linked; // iflink != ifindex
95
96
time_t discover_time;
97
@@ -811,7 +810,6 @@ static struct netdev *get_netdev(const char *name) {
810
d->len = strlen(d->name);
811
d->chart_labels = rrdlabels_create();
812
d->function_ready = false;
814
- d->double_linked = false;
813
814
d->chart_type_net_bytes = strdupz("net");
815
d->chart_type_net_compressed = strdupz("net_compressed");
@@ -860,25 +858,10 @@ static struct netdev *get_netdev(const char *name) {
858
return d;
859
}
860
863
-static bool is_iface_double_linked(struct netdev *d) {
864
- char filename[FILENAME_MAX + 1];
865
- unsigned long long iflink = 0;
866
- unsigned long long ifindex = 0;
867
-
868
- snprintfz(filename, FILENAME_MAX, "%s/sys/class/net/%s/iflink", netdata_configured_host_prefix, d->name);
869
- if (read_single_number_file(filename, &iflink))
870
- return false;
871
-
872
- snprintfz(filename, FILENAME_MAX, "%s/sys/class/net/%s/ifindex", netdata_configured_host_prefix, d->name);
873
- if (read_single_number_file(filename, &ifindex))
874
- return false;
875
-
876
- return iflink != ifindex;
877
-}
878
-
861
int do_proc_net_dev(int update_every, usec_t dt) {
862
(void)dt;
863
static SIMPLE_PATTERN *disabled_list = NULL;
864
+ static SIMPLE_PATTERN *virtual_iface_no_delay = NULL;
865
static procfile *ff = NULL;
866
static int enable_new_interfaces = -1;
867
static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1,
@@ -923,8 +906,26 @@ int do_proc_net_dev(int update_every, usec_t dt) {
906
do_compressed = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "compressed packets for all interfaces", CONFIG_BOOLEAN_NO);
907
908
disabled_list = simple_pattern_create(
926
- config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "disable by default interfaces matching",
927
- "lo fireqos* *-ifb fwpr* fwbr* fwln*"), NULL, SIMPLE_PATTERN_EXACT, true);
909
+ config_get(
910
+ CONFIG_SECTION_PLUGIN_PROC_NETDEV,
911
+ "disable by default interfaces matching",
912
+ "lo fireqos* *-ifb fwpr* fwbr* fwln*"),
913
+ NULL,
914
+ SIMPLE_PATTERN_EXACT,
915
+ true);
916
+
917
+ virtual_iface_no_delay = simple_pattern_create(
918
+ " bond* "
919
+ " vlan* "
920
+ " vmbr* "
921
+ " wg* "
922
+ " vpn* "
923
+ " tun* "
924
+ " gre* "
925
+ " docker* ",
926
+ NULL,
927
+ SIMPLE_PATTERN_EXACT,
928
+ true);
929
930
netdev_renames_init();
931
}
@@ -1011,8 +1012,6 @@ int do_proc_net_dev(int update_every, usec_t dt) {
1012
if(d->enabled == CONFIG_BOOLEAN_NO)
1013
continue;
1014
1014
- d->double_linked = is_iface_double_linked(d);
1015
-
1015
d->do_bandwidth = do_bandwidth;
1016
d->do_packets = do_packets;
1017
d->do_errors = do_errors;
@@ -1062,8 +1061,10 @@ int do_proc_net_dev(int update_every, usec_t dt) {
1061
// This is necessary to prevent the creation of charts for virtual interfaces that will later be
1062
// recreated as container interfaces (create container) or
1063
// rediscovered and recreated only to be deleted almost immediately (stop/remove container)
1065
- if (d->double_linked && d->virtual && (now - d->discover_time < double_linked_device_collect_delay_secs))
1064
+ if (d->virtual && !simple_pattern_matches(virtual_iface_no_delay, d->name) &&
1065
+ (now - d->discover_time < virtual_device_collect_delay_secs)) {
1066
continue;
1067
+ }
1068
1069
if(likely(d->do_bandwidth != CONFIG_BOOLEAN_NO || !d->virtual)) {
1070
d->rbytes = str2kernel_uint_t(procfile_lineword(ff, l, 1));
@@ -1719,7 +1720,7 @@ void *netdev_main(void *ptr_is_null __maybe_unused)
1720
worker_register_job_name(0, "netdev");
1721
1722
if (getenv("KUBERNETES_SERVICE_HOST") != NULL && getenv("KUBERNETES_SERVICE_PORT") != NULL)
1722
- double_linked_device_collect_delay_secs = 300;
1723
+ virtual_device_collect_delay_secs = 300;
1724
1725
rrd_function_add_inline(localhost, NULL, "network-interfaces", 10,
1726
RRDFUNCTIONS_PRIORITY_DEFAULT, RRDFUNCTIONS_NETDEV_HELP,