new chart system.bandwidth that aggregates the bandwidth of all network interfaces
Costa Tsaousis (ktsaou) committed
Oct 27, 2017 at 00:01 UTC
6dc7fd7cc8c3fec5408670c4d96bf31b59c51205
4 files changed
+65
-3
src/proc_net_dev.c
+39
@@ -459,6 +459,9 @@ int do_proc_net_dev(int update_every, usec_t dt) {
459
460
netdev_found = 0;
461
462
+ kernel_uint_t system_rbytes = 0;
463
+ kernel_uint_t system_tbytes = 0;
464
+
465
size_t lines = procfile_lines(ff), l;
466
for(l = 2; l < lines ;l++) {
467
// require 17 words on each line
@@ -501,6 +504,9 @@ int do_proc_net_dev(int update_every, usec_t dt) {
504
if(likely(d->do_bandwidth != CONFIG_BOOLEAN_NO)) {
505
d->rbytes = str2kernel_uint_t(procfile_lineword(ff, l, 1));
506
d->tbytes = str2kernel_uint_t(procfile_lineword(ff, l, 9));
507
+
508
+ system_rbytes += d->rbytes;
509
+ system_tbytes += d->tbytes;
510
}
511
512
if(likely(d->do_packets != CONFIG_BOOLEAN_NO)) {
@@ -831,6 +837,39 @@ int do_proc_net_dev(int update_every, usec_t dt) {
837
}
838
}
839
840
+ if(do_bandwidth == CONFIG_BOOLEAN_YES || (do_bandwidth == CONFIG_BOOLEAN_AUTO && (system_rbytes || system_tbytes))) {
841
+ do_bandwidth = CONFIG_BOOLEAN_YES;
842
+ static RRDSET *st_system_bandwidth = NULL;
843
+ static RRDDIM *rd_in = NULL, *rd_out = NULL;
844
+
845
+ if(unlikely(!st_system_bandwidth)) {
846
+ st_system_bandwidth = rrdset_create_localhost(
847
+ "system"
848
+ , "bandwidth"
849
+ , NULL
850
+ , "network"
851
+ , NULL
852
+ , "Network Interfaces Aggregated Bandwidth"
853
+ , "kilobits/s"
854
+ , "proc"
855
+ , "net/dev"
856
+ , 500
857
+ , update_every
858
+ , RRDSET_TYPE_AREA
859
+ );
860
+
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);
863
+ }
864
+ else
865
+ rrdset_next(st_system_bandwidth);
866
+
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);
869
+
870
+ rrdset_done(st_system_bandwidth);
871
+ }
872
+
873
netdev_cleanup();
874
875
return 0;
src/proc_net_netstat.c
+1
-1
@@ -262,7 +262,7 @@ int do_proc_net_netstat(int update_every, usec_t dt) {
262
, "kilobits/s"
263
, "proc"
264
, "net/netstat"
265
- , 500
265
+ , 501
266
, update_every
267
, RRDSET_TYPE_AREA
268
);
src/proc_net_snmp6.c
+1
-1
@@ -291,7 +291,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
291
, "kilobits/s"
292
, "proc"
293
, "net/snmp6"
294
- , 500
294
+ , 502
295
, update_every
296
, RRDSET_TYPE_AREA
297
);
web/index.html
+24
-1
@@ -1388,7 +1388,30 @@
1388
+ ' data-colors="' + NETDATA.colors[12] + '"'
1389
+ ' role="application"></div>';
1390
1391
- if(typeof charts['system.ipv4'] !== 'undefined') {
1391
+ if(typeof charts['system.bandwidth'] !== 'undefined') {
1392
+ head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.bandwidth"'
1393
+ + ' data-dimensions="received"'
1394
+ + ' data-chart-library="easypiechart"'
1395
+ + ' data-title="Net Inbound"'
1396
+ + ' data-width="11%"'
1397
+ + ' data-before="0"'
1398
+ + ' data-after="-' + duration.toString() + '"'
1399
+ + ' data-points="' + duration.toString() + '"'
1400
+ + ' data-common-units="system.bandwidth.mainhead"'
1401
+ + ' role="application"></div>';
1402
+
1403
+ head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.bandwidth"'
1404
+ + ' data-dimensions="sent"'
1405
+ + ' data-chart-library="easypiechart"'
1406
+ + ' data-title="Net Outbound"'
1407
+ + ' data-width="11%"'
1408
+ + ' data-before="0"'
1409
+ + ' data-after="-' + duration.toString() + '"'
1410
+ + ' data-points="' + duration.toString() + '"'
1411
+ + ' data-common-units="system.bandwidth.mainhead"'
1412
+ + ' role="application"></div>';
1413
+ }
1414
+ else if(typeof charts['system.ipv4'] !== 'undefined') {
1415
head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.ipv4"'
1416
+ ' data-dimensions="received"'
1417
+ ' data-chart-library="easypiechart"'