Add IPv6 packets, errors and fragments charts to FreeBSD plugin
Vladimir Kobal committed
Jan 3, 2017 at 21:22 UTC
846bfd95e07cccb6237c77c38832aca1a0a2d1f6
1 file changed
+143
-1
src/freebsd_sysctl.c
+143
-1
@@ -29,6 +29,8 @@
29
#include <netinet/ip.h>
30
#include <netinet/ip_icmp.h>
31
#include <netinet/icmp_var.h>
32
+// NEEDED BY do_ip6...
33
+#include <netinet6/ip6_var.h>
34
35
// NEEDED BY: do_disk_io
36
#define RRD_TYPE_DISK "disk"
@@ -49,7 +51,8 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
51
do_tcp_sockets = -1, do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1,
52
do_ecn = -1, do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1,
53
do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1,
52
- do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1;
54
+ do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1,
55
+ do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1;
56
57
if (unlikely(do_cpu == -1)) {
58
do_cpu = config_get_boolean("plugin:freebsd:sysctl", "cpu utilization", 1);
@@ -88,6 +91,10 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
91
do_ip_fragsout = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments sent", 1);
92
do_ip_fragsin = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments assembly", 1);
93
do_ip_errors = config_get_boolean("plugin:freebsd:sysctl", "ipv4 errors", 1);
94
+ do_ip6_packets = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 packets", CONFIG_ONDEMAND_ONDEMAND);
95
+ do_ip6_fragsout = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 fragments sent", CONFIG_ONDEMAND_ONDEMAND);
96
+ do_ip6_fragsin = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 fragments assembly", CONFIG_ONDEMAND_ONDEMAND);
97
+ do_ip6_errors = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 errors", CONFIG_ONDEMAND_ONDEMAND);
98
}
99
100
RRDSET *st;
@@ -225,6 +232,9 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
232
// NEEDED BY: do_ip...
233
struct ipstat ipstat;
234
235
+ // NEEDED BY: do_ip6...
236
+ struct ip6stat ip6stat;
237
+
238
// --------------------------------------------------------------------
239
240
if (last_loadavg_usec <= dt) {
@@ -1703,5 +1713,137 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
1713
}
1714
}
1715
1716
+ // --------------------------------------------------------------------
1717
+
1718
+ if (likely(do_ip6_packets || do_ip6_fragsout || do_ip6_fragsin || do_ip6_errors)) {
1719
+ if (unlikely(GETSYSCTL("net.inet6.ip6.stats", ip6stat))) {
1720
+ do_ip6_packets = 0;
1721
+ error("DISABLED: ipv6.packets");
1722
+ do_ip6_fragsout = 0;
1723
+ error("DISABLED: ipv6.fragsout");
1724
+ do_ip6_fragsin = 0;
1725
+ error("DISABLED: ipv6.fragsin");
1726
+ do_ip6_errors = 0;
1727
+ error("DISABLED: ipv6.errors");
1728
+ } else {
1729
+ if (do_ip6_packets == CONFIG_ONDEMAND_YES || (do_ip6_packets == CONFIG_ONDEMAND_ONDEMAND &&
1730
+ (ip6stat.ip6s_localout || ip6stat.ip6s_total ||
1731
+ ip6stat.ip6s_forward || ip6stat.ip6s_delivered))) {
1732
+ do_ip6_packets = CONFIG_ONDEMAND_YES;
1733
+ st = rrdset_find("ipv6.packets");
1734
+ if (unlikely(!st)) {
1735
+ st = rrdset_create("ipv6", "packets", NULL, "packets", NULL, "IPv6 Packets", "packets/s", 3000,
1736
+ update_every, RRDSET_TYPE_LINE);
1737
+
1738
+ rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
1739
+ rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
1740
+ rrddim_add(st, "forwarded", NULL, 1, 1, RRDDIM_INCREMENTAL);
1741
+ rrddim_add(st, "delivers", NULL, -1, 1, RRDDIM_INCREMENTAL);
1742
+ } else
1743
+ rrdset_next(st);
1744
+
1745
+ rrddim_set(st, "sent", ip6stat.ip6s_localout);
1746
+ rrddim_set(st, "received", ip6stat.ip6s_total);
1747
+ rrddim_set(st, "forwarded", ip6stat.ip6s_forward);
1748
+ rrddim_set(st, "delivers", ip6stat.ip6s_delivered);
1749
+ rrdset_done(st);
1750
+ }
1751
+
1752
+ // --------------------------------------------------------------------
1753
+
1754
+ if (do_ip6_fragsout == CONFIG_ONDEMAND_YES || (do_ip6_fragsout == CONFIG_ONDEMAND_ONDEMAND &&
1755
+ (ip6stat.ip6s_fragmented || ip6stat.ip6s_cantfrag ||
1756
+ ip6stat.ip6s_ofragments))) {
1757
+ do_ip6_fragsout = CONFIG_ONDEMAND_YES;
1758
+ st = rrdset_find("ipv6.fragsout");
1759
+ if (unlikely(!st)) {
1760
+ st = rrdset_create("ipv6", "fragsout", NULL, "fragments", NULL, "IPv6 Fragments Sent",
1761
+ "packets/s", 3010, update_every, RRDSET_TYPE_LINE);
1762
+ st->isdetail = 1;
1763
+
1764
+ rrddim_add(st, "ok", NULL, 1, 1, RRDDIM_INCREMENTAL);
1765
+ rrddim_add(st, "failed", NULL, -1, 1, RRDDIM_INCREMENTAL);
1766
+ rrddim_add(st, "all", NULL, 1, 1, RRDDIM_INCREMENTAL);
1767
+ } else
1768
+ rrdset_next(st);
1769
+
1770
+ rrddim_set(st, "ok", ip6stat.ip6s_fragmented);
1771
+ rrddim_set(st, "failed", ip6stat.ip6s_cantfrag);
1772
+ rrddim_set(st, "all", ip6stat.ip6s_ofragments);
1773
+ rrdset_done(st);
1774
+ }
1775
+
1776
+ // --------------------------------------------------------------------
1777
+
1778
+ if (do_ip6_fragsin == CONFIG_ONDEMAND_YES || (do_ip6_fragsin == CONFIG_ONDEMAND_ONDEMAND &&
1779
+ (ip6stat.ip6s_reassembled || ip6stat.ip6s_fragdropped ||
1780
+ ip6stat.ip6s_fragtimeout || ip6stat.ip6s_fragments))) {
1781
+ do_ip6_fragsin = CONFIG_ONDEMAND_YES;
1782
+ st = rrdset_find("ipv6.fragsin");
1783
+ if (unlikely(!st)) {
1784
+ st = rrdset_create("ipv6", "fragsin", NULL, "fragments", NULL, "IPv6 Fragments Reassembly",
1785
+ "packets/s", 3011, update_every, RRDSET_TYPE_LINE);
1786
+ st->isdetail = 1;
1787
+
1788
+ rrddim_add(st, "ok", NULL, 1, 1, RRDDIM_INCREMENTAL);
1789
+ rrddim_add(st, "failed", NULL, -1, 1, RRDDIM_INCREMENTAL);
1790
+ rrddim_add(st, "timeout", NULL, -1, 1, RRDDIM_INCREMENTAL);
1791
+ rrddim_add(st, "all", NULL, 1, 1, RRDDIM_INCREMENTAL);
1792
+ } else
1793
+ rrdset_next(st);
1794
+
1795
+ rrddim_set(st, "ok", ip6stat.ip6s_reassembled);
1796
+ rrddim_set(st, "failed", ip6stat.ip6s_fragdropped);
1797
+ rrddim_set(st, "timeout", ip6stat.ip6s_fragtimeout);
1798
+ rrddim_set(st, "all", ip6stat.ip6s_fragments);
1799
+ rrdset_done(st);
1800
+ }
1801
+
1802
+ // --------------------------------------------------------------------
1803
+
1804
+ if (do_ip6_errors == CONFIG_ONDEMAND_YES || (do_ip6_errors == CONFIG_ONDEMAND_ONDEMAND && (
1805
+ ip6stat.ip6s_toosmall ||
1806
+ ip6stat.ip6s_odropped ||
1807
+ ip6stat.ip6s_badoptions ||
1808
+ ip6stat.ip6s_badvers ||
1809
+ ip6stat.ip6s_exthdrtoolong ||
1810
+ ip6stat.ip6s_sources_none ||
1811
+ ip6stat.ip6s_tooshort ||
1812
+ ip6stat.ip6s_cantforward ||
1813
+ ip6stat.ip6s_noroute))) {
1814
+ do_ip6_errors = CONFIG_ONDEMAND_YES;
1815
+ st = rrdset_find("ipv6.errors");
1816
+ if (unlikely(!st)) {
1817
+ st = rrdset_create("ipv6", "errors", NULL, "errors", NULL, "IPv6 Errors", "packets/s", 3002,
1818
+ update_every, RRDSET_TYPE_LINE);
1819
+ st->isdetail = 1;
1820
+
1821
+ rrddim_add(st, "InDiscards", NULL, 1, 1, RRDDIM_INCREMENTAL);
1822
+ rrddim_add(st, "OutDiscards", NULL, -1, 1, RRDDIM_INCREMENTAL);
1823
+
1824
+ rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1825
+ rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1826
+ rrddim_add(st, "InTruncatedPkts", NULL, 1, 1, RRDDIM_INCREMENTAL);
1827
+ rrddim_add(st, "InNoRoutes", NULL, 1, 1, RRDDIM_INCREMENTAL);
1828
+
1829
+ rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRDDIM_INCREMENTAL);
1830
+ } else
1831
+ rrdset_next(st);
1832
+
1833
+ rrddim_set(st, "InDiscards", ip6stat.ip6s_toosmall);
1834
+ rrddim_set(st, "OutDiscards", ip6stat.ip6s_odropped);
1835
+
1836
+ rrddim_set(st, "InHdrErrors",
1837
+ ip6stat.ip6s_badoptions + ip6stat.ip6s_badvers + ip6stat.ip6s_exthdrtoolong);
1838
+ rrddim_set(st, "InAddrErrors", ip6stat.ip6s_sources_none);
1839
+ rrddim_set(st, "InTruncatedPkts", ip6stat.ip6s_tooshort);
1840
+ rrddim_set(st, "InNoRoutes", ip6stat.ip6s_cantforward);
1841
+
1842
+ rrddim_set(st, "OutNoRoutes", ip6stat.ip6s_noroute);
1843
+ rrdset_done(st);
1844
+ }
1845
+ }
1846
+ }
1847
+
1848
return 0;
1849
}