Add IPv4 ICMP charts to macOS plugin
Vladimir Kobal committed
Jan 9, 2017 at 14:50 UTC
64bd37c09c95577ece8f7187559f61cd8f7d044a
2 files changed
+101
-1
src/freebsd_sysctl.c
+2
@@ -97,6 +97,8 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
97
do_tcpext_connaborts = config_get_boolean_ondemand("plugin:freebsd:sysctl", "TCP connection aborts", CONFIG_ONDEMAND_ONDEMAND);
98
do_udp_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 UDP packets", 1);
99
do_udp_errors = config_get_boolean("plugin:freebsd:sysctl", "ipv4 UDP errors", 1);
100
+ do_icmp_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP packets", 1);
101
+ do_icmpmsg = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP messages", 1);
102
do_ip_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 packets", 1);
103
do_ip_fragsout = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments sent", 1);
104
do_ip_fragsin = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments assembly", 1);
src/macos_sysctl.c
+99
-1
@@ -11,6 +11,10 @@
11
// NEEDED BY do_udp...
12
#include <netinet/udp.h>
13
#include <netinet/udp_var.h>
14
+// NEEDED BY do_icmp...
15
+#include <netinet/ip.h>
16
+#include <netinet/ip_icmp.h>
17
+#include <netinet/icmp_var.h>
18
19
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
20
@@ -25,7 +29,7 @@ int do_macos_sysctl(int update_every, usec_t dt) {
29
static int do_loadavg = -1, do_swap = -1, do_bandwidth = -1,
30
do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1, do_ecn = -1,
31
do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1,
28
- do_udp_packets = -1, do_udp_errors = -1;
32
+ do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1;
33
34
35
if (unlikely(do_loadavg == -1)) {
@@ -41,6 +45,8 @@ int do_macos_sysctl(int update_every, usec_t dt) {
45
do_tcpext_connaborts = config_get_boolean_ondemand("plugin:macos:sysctl", "TCP connection aborts", CONFIG_ONDEMAND_ONDEMAND);
46
do_udp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 UDP packets", 1);
47
do_udp_errors = config_get_boolean("plugin:macos:sysctl", "ipv4 UDP errors", 1);
48
+ do_icmp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP packets", 1);
49
+ do_icmpmsg = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP messages", 1);
50
}
51
52
RRDSET *st;
@@ -74,6 +80,15 @@ int do_macos_sysctl(int update_every, usec_t dt) {
80
// NEEDED BY: do_udp...
81
struct udpstat udpstat;
82
83
+ // NEEDED BY: do_icmp...
84
+ struct icmpstat icmpstat;
85
+ struct icmp_total {
86
+ u_long msgs_in;
87
+ u_long msgs_out;
88
+ } icmp_total = {0, 0};
89
+
90
+ // --------------------------------------------------------------------
91
+
92
if (last_loadavg_usec <= dt) {
93
if (likely(do_loadavg)) {
94
if (unlikely(GETSYSCTL("vm.loadavg", sysload))) {
@@ -101,6 +116,8 @@ int do_macos_sysctl(int update_every, usec_t dt) {
116
}
117
else last_loadavg_usec -= dt;
118
119
+ // --------------------------------------------------------------------
120
+
121
if (likely(do_swap)) {
122
if (unlikely(GETSYSCTL("vm.swapusage", swap_usage))) {
123
do_swap = 0;
@@ -388,6 +405,87 @@ int do_macos_sysctl(int update_every, usec_t dt) {
405
}
406
}
407
408
+ // --------------------------------------------------------------------
409
+
410
+ if (likely(do_icmp_packets || do_icmpmsg)) {
411
+ if (unlikely(GETSYSCTL("net.inet.icmp.stats", icmpstat))) {
412
+ do_icmp_packets = 0;
413
+ error("DISABLED: ipv4.icmp");
414
+ error("DISABLED: ipv4.icmp_errors");
415
+ do_icmpmsg = 0;
416
+ error("DISABLED: ipv4.icmpmsg");
417
+ } else {
418
+ for (i = 0; i <= ICMP_MAXTYPE; i++) {
419
+ icmp_total.msgs_in += icmpstat.icps_inhist[i];
420
+ icmp_total.msgs_out += icmpstat.icps_outhist[i];
421
+ }
422
+ icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
423
+
424
+ // --------------------------------------------------------------------
425
+
426
+ if (likely(do_icmp_packets)) {
427
+ st = rrdset_find("ipv4.icmp");
428
+ if (unlikely(!st)) {
429
+ st = rrdset_create("ipv4", "icmp", NULL, "icmp", NULL, "IPv4 ICMP Packets", "packets/s",
430
+ 2602,
431
+ update_every, RRDSET_TYPE_LINE);
432
+
433
+ rrddim_add(st, "InMsgs", "received", 1, 1, RRDDIM_INCREMENTAL);
434
+ rrddim_add(st, "OutMsgs", "sent", -1, 1, RRDDIM_INCREMENTAL);
435
+ } else
436
+ rrdset_next(st);
437
+
438
+ rrddim_set(st, "InMsgs", icmp_total.msgs_in);
439
+ rrddim_set(st, "OutMsgs", icmp_total.msgs_out);
440
+
441
+ rrdset_done(st);
442
+
443
+ // --------------------------------------------------------------------
444
+
445
+ st = rrdset_find("ipv4.icmp_errors");
446
+ if (unlikely(!st)) {
447
+ st = rrdset_create("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
448
+ "packets/s",
449
+ 2603, update_every, RRDSET_TYPE_LINE);
450
+
451
+ rrddim_add(st, "InErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
452
+ rrddim_add(st, "OutErrors", NULL, -1, 1, RRDDIM_INCREMENTAL);
453
+ rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
454
+ } else
455
+ rrdset_next(st);
456
+
457
+ rrddim_set(st, "InErrors", icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort);
458
+ rrddim_set(st, "OutErrors", icmpstat.icps_error);
459
+ rrddim_set(st, "InCsumErrors", icmpstat.icps_checksum);
460
+
461
+ rrdset_done(st);
462
+ }
463
+
464
+ // --------------------------------------------------------------------
465
+
466
+ if (likely(do_icmpmsg)) {
467
+ st = rrdset_find("ipv4.icmpmsg");
468
+ if (unlikely(!st)) {
469
+ st = rrdset_create("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
470
+ "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
471
+
472
+ rrddim_add(st, "InEchoReps", NULL, 1, 1, RRDDIM_INCREMENTAL);
473
+ rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRDDIM_INCREMENTAL);
474
+ rrddim_add(st, "InEchos", NULL, 1, 1, RRDDIM_INCREMENTAL);
475
+ rrddim_add(st, "OutEchos", NULL, -1, 1, RRDDIM_INCREMENTAL);
476
+ } else
477
+ rrdset_next(st);
478
+
479
+ rrddim_set(st, "InEchoReps", icmpstat.icps_inhist[ICMP_ECHOREPLY]);
480
+ rrddim_set(st, "OutEchoReps", icmpstat.icps_outhist[ICMP_ECHOREPLY]);
481
+ rrddim_set(st, "InEchos", icmpstat.icps_inhist[ICMP_ECHO]);
482
+ rrddim_set(st, "OutEchos", icmpstat.icps_outhist[ICMP_ECHO]);
483
+
484
+ rrdset_done(st);
485
+ }
486
+ }
487
+ }
488
+
489
return 0;
490
}
491