@cryptotaxi247 / netdata-1 / commits / 4adcad215

Add IPv4 ICMP charts to FreeBSD plugin

Vladimir Kobal committed Jan 3, 2017 at 01:04 UTC 4adcad21564315e806eb50c2b44cb92e1a18acc1
1 file changed +93 -1
src/freebsd_sysctl.c
+93 -1
@@ -24,6 +24,10 @@
24 #include <netinet/ip_var.h>
25 #include <netinet/udp.h>
26 #include <netinet/udp_var.h>
27 +// NEEDED BY do_icmp...
28 +#include <netinet/ip.h>
29 +#include <netinet/ip_icmp.h>
30 +#include <netinet/icmp_var.h>
31
32 // NEEDED BY: do_disk_io
33 #define RRD_TYPE_DISK "disk"
@@ -43,7 +47,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
47 do_dev_intr = -1, do_soft_intr = -1, do_netisr = -1, do_netisr_per_core = -1, do_bandwidth = -1,
48 do_tcp_sockets = -1, do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1,
49 do_ecn = -1, do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1,
46 - do_udp_packets = -1, do_udp_errors = -1;
50 + do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1;
51
52 if (unlikely(do_cpu == -1)) {
53 do_cpu = config_get_boolean("plugin:freebsd:sysctl", "cpu utilization", 1);
@@ -205,6 +209,13 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
209 // NEEDED BY: do_udp...
210 struct udpstat udpstat;
211
212 + // NEEDED BY: do_icmp...
213 + struct icmpstat icmpstat;
214 + struct icmp_total {
215 + u_long msgs_in;
216 + u_long msgs_out;
217 + } icmp_total = {0, 0};
218 +
219 // --------------------------------------------------------------------
220
221 if (last_loadavg_usec <= dt) {
@@ -1493,5 +1504,86 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
1504 }
1505 }
1506
1507 + // --------------------------------------------------------------------
1508 +
1509 + if (likely(do_icmp_packets || do_icmpmsg)) {
1510 + if (unlikely(GETSYSCTL("net.inet.icmp.stats", icmpstat))) {
1511 + do_icmp_packets = 0;
1512 + error("DISABLED: ipv4.icmp");
1513 + error("DISABLED: ipv4.icmp_errors");
1514 + do_icmpmsg = 0;
1515 + error("DISABLED: ipv4.icmpmsg");
1516 + } else {
1517 + for (i = 0; i <= ICMP_MAXTYPE; i++) {
1518 + icmp_total.msgs_in += icmpstat.icps_inhist[i];
1519 + icmp_total.msgs_out += icmpstat.icps_outhist[i];
1520 + }
1521 + icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
1522 +
1523 + // --------------------------------------------------------------------
1524 +
1525 + if (likely(do_icmp_packets)) {
1526 + st = rrdset_find("ipv4.icmp");
1527 + if (unlikely(!st)) {
1528 + st = rrdset_create("ipv4", "icmp", NULL, "icmp", NULL, "IPv4 ICMP Packets", "packets/s",
1529 + 2602,
1530 + update_every, RRDSET_TYPE_LINE);
1531 +
1532 + rrddim_add(st, "InMsgs", "received", 1, 1, RRDDIM_INCREMENTAL);
1533 + rrddim_add(st, "OutMsgs", "sent", -1, 1, RRDDIM_INCREMENTAL);
1534 + } else
1535 + rrdset_next(st);
1536 +
1537 + rrddim_set(st, "InMsgs", icmp_total.msgs_in);
1538 + rrddim_set(st, "OutMsgs", icmp_total.msgs_out);
1539 +
1540 + rrdset_done(st);
1541 +
1542 + // --------------------------------------------------------------------
1543 +
1544 + st = rrdset_find("ipv4.icmp_errors");
1545 + if (unlikely(!st)) {
1546 + st = rrdset_create("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
1547 + "packets/s",
1548 + 2603, update_every, RRDSET_TYPE_LINE);
1549 +
1550 + rrddim_add(st, "InErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1551 + rrddim_add(st, "OutErrors", NULL, -1, 1, RRDDIM_INCREMENTAL);
1552 + rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1553 + } else
1554 + rrdset_next(st);
1555 +
1556 + rrddim_set(st, "InErrors", icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort);
1557 + rrddim_set(st, "OutErrors", icmpstat.icps_error);
1558 + rrddim_set(st, "InCsumErrors", icmpstat.icps_checksum);
1559 +
1560 + rrdset_done(st);
1561 + }
1562 +
1563 + // --------------------------------------------------------------------
1564 +
1565 + if (likely(do_icmpmsg)) {
1566 + st = rrdset_find("ipv4.icmpmsg");
1567 + if (unlikely(!st)) {
1568 + st = rrdset_create("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
1569 + "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
1570 +
1571 + rrddim_add(st, "InEchoReps", NULL, 1, 1, RRDDIM_INCREMENTAL);
1572 + rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRDDIM_INCREMENTAL);
1573 + rrddim_add(st, "InEchos", NULL, 1, 1, RRDDIM_INCREMENTAL);
1574 + rrddim_add(st, "OutEchos", NULL, -1, 1, RRDDIM_INCREMENTAL);
1575 + } else
1576 + rrdset_next(st);
1577 +
1578 + rrddim_set(st, "InEchoReps", icmpstat.icps_inhist[ICMP_ECHOREPLY]);
1579 + rrddim_set(st, "OutEchoReps", icmpstat.icps_outhist[ICMP_ECHOREPLY]);
1580 + rrddim_set(st, "InEchos", icmpstat.icps_inhist[ICMP_ECHO]);
1581 + rrddim_set(st, "OutEchos", icmpstat.icps_outhist[ICMP_ECHO]);
1582 +
1583 + rrdset_done(st);
1584 + }
1585 + }
1586 + }
1587 +
1588 return 0;
1589 }