Feat: detect NIC speed and alarm on each device for net traffic overflow (#4430)
* add chart local variable nic_speed_max and alarm for net traffic overflow * simplify code and respect with netdata host prefix * split sent/received traffic alarm * evaluate alarm only when nic_speed_max is set above 0
Dylan Wang committed
Oct 24, 2018 at 17:43 UTC
866170672aee2c6dbeed5f79caf18755d850c32c
2 files changed
+46
collectors/proc.plugin/proc_net_dev.c
+13
@@ -66,6 +66,7 @@ static struct netdev {
66
kernel_uint_t tcollisions;
67
kernel_uint_t tcarrier;
68
kernel_uint_t tcompressed;
69
+ kernel_uint_t speed_max;
70
71
// charts
72
RRDSET *st_bandwidth;
@@ -435,6 +436,7 @@ int do_proc_net_dev(int update_every, usec_t dt) {
436
static int enable_new_interfaces = -1;
437
static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
438
static char *path_to_sys_devices_virtual_net = NULL;
439
+ static char *path_to_sys_net_speed = NULL;
440
441
if(unlikely(enable_new_interfaces == -1)) {
442
char filename[FILENAME_MAX + 1];
@@ -503,6 +505,14 @@ int do_proc_net_dev(int update_every, usec_t dt) {
505
else
506
d->virtual = 0;
507
508
+ // set nic speed if present
509
+ if(likely(!d->virtual)) {
510
+ snprintfz(buffer, FILENAME_MAX, "%s/sys/class/net/%s/speed", netdata_configured_host_prefix, d->name);
511
+ path_to_sys_net_speed = config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "path to get net device speed", buffer);
512
+ int ret = read_single_number_file(path_to_sys_net_speed, (unsigned long long*)&d->speed_max);
513
+ if(ret) error("Cannot read '%s'.", path_to_sys_net_speed);
514
+ }
515
+
516
snprintfz(buffer, FILENAME_MAX, "plugin:proc:/proc/net/dev:%s", d->name);
517
d->enabled = config_get_boolean_ondemand(buffer, "enabled", d->enabled);
518
d->virtual = config_get_boolean(buffer, "virtual", d->virtual);
@@ -587,6 +597,9 @@ int do_proc_net_dev(int update_every, usec_t dt) {
597
, RRDSET_TYPE_AREA
598
);
599
600
+ RRDSETVAR *nic_speed_max = rrdsetvar_custom_chart_variable_create(d->st_bandwidth, "nic_speed_max");
601
+ if(nic_speed_max) rrdsetvar_custom_chart_variable_set(nic_speed_max, (calculated_number)d->speed_max);
602
+
603
d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
604
d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
605
health/health.d/net.conf
+33
@@ -1,6 +1,39 @@
1
2
# you can disable an alarm notification by setting the 'to' line to: silent
3
4
+# -----------------------------------------------------------------------------
5
+# net traffic overflow
6
+
7
+ template: 1m_received_traffic_overflow
8
+ on: net.net
9
+ os: linux
10
+ hosts: *
11
+ families: *
12
+ lookup: average -1m unaligned absolute of received
13
+ calc: ($nic_speed_max > 0) ? ($this * 100 / ($nic_speed_max * 1000)) : ( nan )
14
+ units: %
15
+ every: 10s
16
+ warn: $this > (($status >= $WARNING) ? (80) : (85))
17
+ crit: $this > (($status == $CRITICAL) ? (85) : (90))
18
+ delay: down 1m multiplier 1.5 max 1h
19
+ info: interface received bandwidth usage over net device speed max
20
+ to: sysadmin
21
+
22
+ template: 1m_sent_traffic_overflow
23
+ on: net.net
24
+ os: linux
25
+ hosts: *
26
+ families: *
27
+ lookup: average -1m unaligned absolute of sent
28
+ calc: ($nic_speed_max > 0) ? ($this * 100 / ($nic_speed_max * 1000)) : ( nan )
29
+ units: %
30
+ every: 10s
31
+ warn: $this > (($status >= $WARNING) ? (80) : (85))
32
+ crit: $this > (($status == $CRITICAL) ? (85) : (90))
33
+ delay: down 1m multiplier 1.5 max 1h
34
+ info: interface sent bandwidth usage over net device speed max
35
+ to: sysadmin
36
+
37
# -----------------------------------------------------------------------------
38
# dropped packets
39