rename system.bandwidth to system.net and aggregate only non-virtual interfaces
Costa Tsaousis (ktsaou) committed
Oct 27, 2017 at 01:10 UTC
a6d3c0b7a283107945ed5a08ee5bb73904828a71
2 files changed
+46
-28
src/proc_net_dev.c
+41
-23
@@ -9,6 +9,7 @@ static struct netdev {
9
size_t len;
10
11
// flags
12
+ int virtual;
13
int configured;
14
int enabled;
15
int updated;
@@ -428,8 +429,14 @@ int do_proc_net_dev(int update_every, usec_t dt) {
429
static procfile *ff = NULL;
430
static int enable_new_interfaces = -1;
431
static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
432
+ static char *path_to_sys_devices_virtual_net = NULL;
433
434
if(unlikely(enable_new_interfaces == -1)) {
435
+ char filename[FILENAME_MAX + 1];
436
+
437
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/devices/virtual/net/%s");
438
+ path_to_sys_devices_virtual_net = config_get("plugin:proc:/proc/net/dev", "path to get virtual interfaces", filename);
439
+
440
enable_new_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable new interfaces detected at runtime", CONFIG_BOOLEAN_AUTO);
441
442
do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", CONFIG_BOOLEAN_AUTO);
@@ -482,31 +489,42 @@ int do_proc_net_dev(int update_every, usec_t dt) {
489
if(d->enabled)
490
d->enabled = !simple_pattern_matches(disabled_list, d->name);
491
485
- char var_name[512 + 1];
486
- snprintfz(var_name, 512, "plugin:proc:/proc/net/dev:%s", d->name);
487
- d->enabled = config_get_boolean_ondemand(var_name, "enabled", d->enabled);
492
+ char buffer[FILENAME_MAX + 1];
493
+
494
+ snprintfz(buffer, FILENAME_MAX, path_to_sys_devices_virtual_net, d->name);
495
+ if(likely(access(buffer, R_OK) == 0)) {
496
+ d->virtual = 1;
497
+ }
498
+ else
499
+ d->virtual = 0;
500
+
501
+ snprintfz(buffer, FILENAME_MAX, "plugin:proc:/proc/net/dev:%s", d->name);
502
+ d->enabled = config_get_boolean_ondemand(buffer, "enabled", d->enabled);
503
+ d->virtual = config_get_boolean(buffer, "virtual", d->virtual);
504
505
if(d->enabled == CONFIG_BOOLEAN_NO)
506
continue;
507
492
- d->do_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", do_bandwidth);
493
- d->do_packets = config_get_boolean_ondemand(var_name, "packets", do_packets);
494
- d->do_errors = config_get_boolean_ondemand(var_name, "errors", do_errors);
495
- d->do_drops = config_get_boolean_ondemand(var_name, "drops", do_drops);
496
- d->do_fifo = config_get_boolean_ondemand(var_name, "fifo", do_fifo);
497
- d->do_compressed = config_get_boolean_ondemand(var_name, "compressed", do_compressed);
498
- d->do_events = config_get_boolean_ondemand(var_name, "events", do_events);
508
+ d->do_bandwidth = config_get_boolean_ondemand(buffer, "bandwidth", do_bandwidth);
509
+ d->do_packets = config_get_boolean_ondemand(buffer, "packets", do_packets);
510
+ d->do_errors = config_get_boolean_ondemand(buffer, "errors", do_errors);
511
+ d->do_drops = config_get_boolean_ondemand(buffer, "drops", do_drops);
512
+ d->do_fifo = config_get_boolean_ondemand(buffer, "fifo", do_fifo);
513
+ d->do_compressed = config_get_boolean_ondemand(buffer, "compressed", do_compressed);
514
+ d->do_events = config_get_boolean_ondemand(buffer, "events", do_events);
515
}
516
517
if(unlikely(!d->enabled))
518
continue;
519
504
- if(likely(d->do_bandwidth != CONFIG_BOOLEAN_NO)) {
520
+ if(likely(d->do_bandwidth != CONFIG_BOOLEAN_NO || !d->virtual)) {
521
d->rbytes = str2kernel_uint_t(procfile_lineword(ff, l, 1));
522
d->tbytes = str2kernel_uint_t(procfile_lineword(ff, l, 9));
523
508
- system_rbytes += d->rbytes;
509
- system_tbytes += d->tbytes;
524
+ if(likely(!d->virtual)) {
525
+ system_rbytes += d->rbytes;
526
+ system_tbytes += d->tbytes;
527
+ }
528
}
529
530
if(likely(d->do_packets != CONFIG_BOOLEAN_NO)) {
@@ -839,13 +857,13 @@ int do_proc_net_dev(int update_every, usec_t dt) {
857
858
if(do_bandwidth == CONFIG_BOOLEAN_YES || (do_bandwidth == CONFIG_BOOLEAN_AUTO && (system_rbytes || system_tbytes))) {
859
do_bandwidth = CONFIG_BOOLEAN_YES;
842
- static RRDSET *st_system_bandwidth = NULL;
860
+ static RRDSET *st_system_net = NULL;
861
static RRDDIM *rd_in = NULL, *rd_out = NULL;
862
845
- if(unlikely(!st_system_bandwidth)) {
846
- st_system_bandwidth = rrdset_create_localhost(
863
+ if(unlikely(!st_system_net)) {
864
+ st_system_net = rrdset_create_localhost(
865
"system"
848
- , "bandwidth"
866
+ , "net"
867
, NULL
868
, "network"
869
, NULL
@@ -858,16 +876,16 @@ int do_proc_net_dev(int update_every, usec_t dt) {
876
, RRDSET_TYPE_AREA
877
);
878
861
- rd_in = rrddim_add(st_system_bandwidth, "InOctets", "received", 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
862
- rd_out = rrddim_add(st_system_bandwidth, "OutOctets", "sent", -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
879
+ rd_in = rrddim_add(st_system_net, "InOctets", "received", 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
880
+ rd_out = rrddim_add(st_system_net, "OutOctets", "sent", -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
881
}
882
else
865
- rrdset_next(st_system_bandwidth);
883
+ rrdset_next(st_system_net);
884
867
- rrddim_set_by_pointer(st_system_bandwidth, rd_in, (collected_number)system_rbytes);
868
- rrddim_set_by_pointer(st_system_bandwidth, rd_out, (collected_number)system_tbytes);
885
+ rrddim_set_by_pointer(st_system_net, rd_in, (collected_number)system_rbytes);
886
+ rrddim_set_by_pointer(st_system_net, rd_out, (collected_number)system_tbytes);
887
870
- rrdset_done(st_system_bandwidth);
888
+ rrdset_done(st_system_net);
889
}
890
891
netdev_cleanup();
web/index.html
+5
-5
@@ -1388,8 +1388,8 @@
1388
+ ' data-colors="' + NETDATA.colors[12] + '"'
1389
+ ' role="application"></div>';
1390
1391
- if(typeof charts['system.bandwidth'] !== 'undefined') {
1392
- head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.bandwidth"'
1391
+ if(typeof charts['system.net'] !== 'undefined') {
1392
+ head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.net"'
1393
+ ' data-dimensions="received"'
1394
+ ' data-chart-library="easypiechart"'
1395
+ ' data-title="Net Inbound"'
@@ -1397,10 +1397,10 @@
1397
+ ' data-before="0"'
1398
+ ' data-after="-' + duration.toString() + '"'
1399
+ ' data-points="' + duration.toString() + '"'
1400
- + ' data-common-units="system.bandwidth.mainhead"'
1400
+ + ' data-common-units="system.net.mainhead"'
1401
+ ' role="application"></div>';
1402
1403
- head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.bandwidth"'
1403
+ head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.net"'
1404
+ ' data-dimensions="sent"'
1405
+ ' data-chart-library="easypiechart"'
1406
+ ' data-title="Net Outbound"'
@@ -1408,7 +1408,7 @@
1408
+ ' data-before="0"'
1409
+ ' data-after="-' + duration.toString() + '"'
1410
+ ' data-points="' + duration.toString() + '"'
1411
- + ' data-common-units="system.bandwidth.mainhead"'
1411
+ + ' data-common-units="system.net.mainhead"'
1412
+ ' role="application"></div>';
1413
}
1414
else if(typeof charts['system.ipv4'] !== 'undefined') {