@cryptotaxi247 / netdata-1 / commits / 6f5938dd4

Add ICMPv6 charts to FreeBSD plugin

Vladimir Kobal committed Jan 4, 2017 at 00:26 UTC 6f5938dd40d962209128de465e240856c6b96676
1 file changed +238 -1
src/freebsd_sysctl.c
+238 -1
@@ -31,6 +31,8 @@
31 #include <netinet/icmp_var.h>
32 // NEEDED BY do_ip6...
33 #include <netinet6/ip6_var.h>
34 +// NEEDED BY do_icmp6...
35 +#include <netinet/icmp6.h>
36
37 // NEEDED BY: do_disk_io
38 #define RRD_TYPE_DISK "disk"
@@ -52,7 +54,9 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
54 do_ecn = -1, do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1,
55 do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1,
56 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;
57 + do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1,
58 + do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1,
59 + do_icmp6_neighbor = -1, do_icmp6_types = -1;
60
61 if (unlikely(do_cpu == -1)) {
62 do_cpu = config_get_boolean("plugin:freebsd:sysctl", "cpu utilization", 1);
@@ -95,6 +99,13 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
99 do_ip6_fragsout = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 fragments sent", CONFIG_ONDEMAND_ONDEMAND);
100 do_ip6_fragsin = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 fragments assembly", CONFIG_ONDEMAND_ONDEMAND);
101 do_ip6_errors = config_get_boolean_ondemand("plugin:freebsd:sysctl", "ipv6 errors", CONFIG_ONDEMAND_ONDEMAND);
102 + do_icmp6 = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp", CONFIG_ONDEMAND_ONDEMAND);
103 + do_icmp6_redir = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp redirects", CONFIG_ONDEMAND_ONDEMAND);
104 + do_icmp6_errors = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp errors", CONFIG_ONDEMAND_ONDEMAND);
105 + do_icmp6_echos = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp echos", CONFIG_ONDEMAND_ONDEMAND);
106 + do_icmp6_router = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp router", CONFIG_ONDEMAND_ONDEMAND);
107 + do_icmp6_neighbor = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp neighbor", CONFIG_ONDEMAND_ONDEMAND);
108 + do_icmp6_types = config_get_boolean_ondemand("plugin:freebsd:sysctl", "icmp types", CONFIG_ONDEMAND_ONDEMAND);
109 }
110
111 RRDSET *st;
@@ -235,6 +246,13 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
246 // NEEDED BY: do_ip6...
247 struct ip6stat ip6stat;
248
249 + // NEEDED BY: do_icmp6...
250 + struct icmp6stat icmp6stat;
251 + struct icmp6_total {
252 + u_long msgs_in;
253 + u_long msgs_out;
254 + } icmp6_total = {0, 0};
255 +
256 // --------------------------------------------------------------------
257
258 if (last_loadavg_usec <= dt) {
@@ -1845,5 +1863,224 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
1863 }
1864 }
1865
1866 + // --------------------------------------------------------------------
1867 +
1868 + if (likely(do_icmp6 || do_icmp6_redir || do_icmp6_errors || do_icmp6_echos || do_icmp6_router || do_icmp6_neighbor || do_icmp6_types)) {
1869 + if (unlikely(GETSYSCTL("net.inet6.icmp6.stats", icmp6stat))) {
1870 + do_icmp6 = 0;
1871 + error("DISABLED: ipv6.icmp");
1872 + } else {
1873 + for (i = 0; i <= ICMP6_MAXTYPE; i++) {
1874 + icmp6_total.msgs_in += icmp6stat.icp6s_inhist[i];
1875 + icmp6_total.msgs_out += icmp6stat.icp6s_outhist[i];
1876 + }
1877 + icmp6_total.msgs_in += icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort;
1878 + if (do_icmp6 == CONFIG_ONDEMAND_YES || (do_icmp6 == CONFIG_ONDEMAND_ONDEMAND && (icmp6_total.msgs_in || icmp6_total.msgs_out))) {
1879 + do_icmp6 = CONFIG_ONDEMAND_YES;
1880 + st = rrdset_find("ipv6.icmp");
1881 + if (unlikely(!st)) {
1882 + st = rrdset_create("ipv6", "icmp", NULL, "icmp", NULL, "IPv6 ICMP Messages",
1883 + "messages/s", 10000, update_every, RRDSET_TYPE_LINE);
1884 +
1885 + rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
1886 + rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
1887 + } else
1888 + rrdset_next(st);
1889 +
1890 + rrddim_set(st, "sent", icmp6_total.msgs_in);
1891 + rrddim_set(st, "received", icmp6_total.msgs_out);
1892 + rrdset_done(st);
1893 + }
1894 +
1895 + // --------------------------------------------------------------------
1896 +
1897 + if (do_icmp6_redir == CONFIG_ONDEMAND_YES || (do_icmp6_redir == CONFIG_ONDEMAND_ONDEMAND && (icmp6stat.icp6s_inhist[ND_REDIRECT] || icmp6stat.icp6s_outhist[ND_REDIRECT]))) {
1898 + do_icmp6_redir = CONFIG_ONDEMAND_YES;
1899 + st = rrdset_find("ipv6.icmpredir");
1900 + if (unlikely(!st)) {
1901 + st = rrdset_create("ipv6", "icmpredir", NULL, "icmp", NULL, "IPv6 ICMP Redirects",
1902 + "redirects/s", 10050, update_every, RRDSET_TYPE_LINE);
1903 +
1904 + rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
1905 + rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
1906 + } else
1907 + rrdset_next(st);
1908 +
1909 + rrddim_set(st, "sent", icmp6stat.icp6s_inhist[ND_REDIRECT]);
1910 + rrddim_set(st, "received", icmp6stat.icp6s_outhist[ND_REDIRECT]);
1911 + rrdset_done(st);
1912 + }
1913 +
1914 + // --------------------------------------------------------------------
1915 +
1916 + if (do_icmp6_errors == CONFIG_ONDEMAND_YES || (do_icmp6_errors == CONFIG_ONDEMAND_ONDEMAND && (
1917 + icmp6stat.icp6s_badcode ||
1918 + icmp6stat.icp6s_badlen ||
1919 + icmp6stat.icp6s_checksum ||
1920 + icmp6stat.icp6s_tooshort ||
1921 + icmp6stat.icp6s_error ||
1922 + icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH] ||
1923 + icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED] ||
1924 + icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB] ||
1925 + icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH] ||
1926 + icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED] ||
1927 + icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]))) {
1928 + do_icmp6_errors = CONFIG_ONDEMAND_YES;
1929 + st = rrdset_find("ipv6.icmperrors");
1930 + if (unlikely(!st)) {
1931 + st = rrdset_create("ipv6", "icmperrors", NULL, "icmp", NULL, "IPv6 ICMP Errors", "errors/s", 10100, update_every, RRDSET_TYPE_LINE);
1932 +
1933 + rrddim_add(st, "InErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1934 + rrddim_add(st, "OutErrors", NULL, -1, 1, RRDDIM_INCREMENTAL);
1935 +
1936 + rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
1937 + rrddim_add(st, "InDestUnreachs", NULL, 1, 1, RRDDIM_INCREMENTAL);
1938 + rrddim_add(st, "InPktTooBigs", NULL, 1, 1, RRDDIM_INCREMENTAL);
1939 + rrddim_add(st, "InTimeExcds", NULL, 1, 1, RRDDIM_INCREMENTAL);
1940 + rrddim_add(st, "InParmProblems", NULL, 1, 1, RRDDIM_INCREMENTAL);
1941 + rrddim_add(st, "OutDestUnreachs", NULL, -1, 1, RRDDIM_INCREMENTAL);
1942 + rrddim_add(st, "OutTimeExcds", NULL, -1, 1, RRDDIM_INCREMENTAL);
1943 + rrddim_add(st, "OutParmProblems", NULL, -1, 1, RRDDIM_INCREMENTAL);
1944 + } else
1945 + rrdset_next(st);
1946 +
1947 + rrddim_set(st, "InErrors", icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort);
1948 + rrddim_set(st, "OutErrors", icmp6stat.icp6s_error);
1949 + rrddim_set(st, "InCsumErrors", icmp6stat.icp6s_checksum);
1950 + rrddim_set(st, "InDestUnreachs", icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH]);
1951 + rrddim_set(st, "InPktTooBigs", icmp6stat.icp6s_badlen);
1952 + rrddim_set(st, "InTimeExcds", icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED]);
1953 + rrddim_set(st, "InParmProblems", icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB]);
1954 + rrddim_set(st, "OutDestUnreachs", icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH]);
1955 + rrddim_set(st, "OutTimeExcds", icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED]);
1956 + rrddim_set(st, "OutParmProblems", icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]);
1957 + rrdset_done(st);
1958 + }
1959 +
1960 + // --------------------------------------------------------------------
1961 +
1962 + if (do_icmp6_echos == CONFIG_ONDEMAND_YES || (do_icmp6_echos == CONFIG_ONDEMAND_ONDEMAND && (
1963 + icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST] ||
1964 + icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST] ||
1965 + icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY] ||
1966 + icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]))) {
1967 + do_icmp6_echos = CONFIG_ONDEMAND_YES;
1968 + st = rrdset_find("ipv6.icmpechos");
1969 + if (unlikely(!st)) {
1970 + st = rrdset_create("ipv6", "icmpechos", NULL, "icmp", NULL, "IPv6 ICMP Echo", "messages/s", 10200, update_every, RRDSET_TYPE_LINE);
1971 +
1972 + rrddim_add(st, "InEchos", NULL, 1, 1, RRDDIM_INCREMENTAL);
1973 + rrddim_add(st, "OutEchos", NULL, -1, 1, RRDDIM_INCREMENTAL);
1974 + rrddim_add(st, "InEchoReplies", NULL, 1, 1, RRDDIM_INCREMENTAL);
1975 + rrddim_add(st, "OutEchoReplies", NULL, -1, 1, RRDDIM_INCREMENTAL);
1976 + } else
1977 + rrdset_next(st);
1978 +
1979 + rrddim_set(st, "InEchos", icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST]);
1980 + rrddim_set(st, "OutEchos", icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST]);
1981 + rrddim_set(st, "InEchoReplies", icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY]);
1982 + rrddim_set(st, "OutEchoReplies", icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]);
1983 + rrdset_done(st);
1984 + }
1985 +
1986 + // --------------------------------------------------------------------
1987 +
1988 + if (do_icmp6_router == CONFIG_ONDEMAND_YES || (do_icmp6_router == CONFIG_ONDEMAND_ONDEMAND && (
1989 + icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT] ||
1990 + icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT] ||
1991 + icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT] ||
1992 + icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]))) {
1993 + do_icmp6_router = CONFIG_ONDEMAND_YES;
1994 + st = rrdset_find("ipv6.icmprouter");
1995 + if (unlikely(!st)) {
1996 + st = rrdset_create("ipv6", "icmprouter", NULL, "icmp", NULL, "IPv6 Router Messages", "messages/s", 10400, update_every, RRDSET_TYPE_LINE);
1997 +
1998 + rrddim_add(st, "InSolicits", NULL, 1, 1, RRDDIM_INCREMENTAL);
1999 + rrddim_add(st, "OutSolicits", NULL, -1, 1, RRDDIM_INCREMENTAL);
2000 + rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRDDIM_INCREMENTAL);
2001 + rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRDDIM_INCREMENTAL);
2002 + } else
2003 + rrdset_next(st);
2004 +
2005 + rrddim_set(st, "InSolicits", icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT]);
2006 + rrddim_set(st, "OutSolicits", icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT]);
2007 + rrddim_set(st, "InAdvertisements", icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT]);
2008 + rrddim_set(st, "OutAdvertisements", icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]);
2009 + rrdset_done(st);
2010 + }
2011 +
2012 + // --------------------------------------------------------------------
2013 +
2014 + if (do_icmp6_neighbor == CONFIG_ONDEMAND_YES || (do_icmp6_neighbor == CONFIG_ONDEMAND_ONDEMAND && (
2015 + icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT] ||
2016 + icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT] ||
2017 + icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT] ||
2018 + icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]))) {
2019 + do_icmp6_neighbor = CONFIG_ONDEMAND_YES;
2020 + st = rrdset_find("ipv6.icmpneighbor");
2021 + if (unlikely(!st)) {
2022 + st = rrdset_create("ipv6", "icmpneighbor", NULL, "icmp", NULL, "IPv6 Neighbor Messages", "messages/s", 10500, update_every, RRDSET_TYPE_LINE);
2023 +
2024 + rrddim_add(st, "InSolicits", NULL, 1, 1, RRDDIM_INCREMENTAL);
2025 + rrddim_add(st, "OutSolicits", NULL, -1, 1, RRDDIM_INCREMENTAL);
2026 + rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRDDIM_INCREMENTAL);
2027 + rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRDDIM_INCREMENTAL);
2028 + } else
2029 + rrdset_next(st);
2030 +
2031 + rrddim_set(st, "InSolicits", icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]);
2032 + rrddim_set(st, "OutSolicits", icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]);
2033 + rrddim_set(st, "InAdvertisements", icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT]);
2034 + rrddim_set(st, "OutAdvertisements", icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]);
2035 + rrdset_done(st);
2036 + }
2037 +
2038 + // --------------------------------------------------------------------
2039 +
2040 + if (do_icmp6_types == CONFIG_ONDEMAND_YES || (do_icmp6_types == CONFIG_ONDEMAND_ONDEMAND && (
2041 + icmp6stat.icp6s_inhist[1] ||
2042 + icmp6stat.icp6s_inhist[128] ||
2043 + icmp6stat.icp6s_inhist[129] ||
2044 + icmp6stat.icp6s_inhist[136] ||
2045 + icmp6stat.icp6s_outhist[1] ||
2046 + icmp6stat.icp6s_outhist[128] ||
2047 + icmp6stat.icp6s_outhist[129] ||
2048 + icmp6stat.icp6s_outhist[133] ||
2049 + icmp6stat.icp6s_outhist[135] ||
2050 + icmp6stat.icp6s_outhist[136]))) {
2051 + do_icmp6_types = CONFIG_ONDEMAND_YES;
2052 + st = rrdset_find("ipv6.icmptypes");
2053 + if (unlikely(!st)) {
2054 + st = rrdset_create("ipv6", "icmptypes", NULL, "icmp", NULL, "IPv6 ICMP Types",
2055 + "messages/s", 10700, update_every, RRDSET_TYPE_LINE);
2056 +
2057 + rrddim_add(st, "InType1", NULL, 1, 1, RRDDIM_INCREMENTAL);
2058 + rrddim_add(st, "InType128", NULL, 1, 1, RRDDIM_INCREMENTAL);
2059 + rrddim_add(st, "InType129", NULL, 1, 1, RRDDIM_INCREMENTAL);
2060 + rrddim_add(st, "InType136", NULL, 1, 1, RRDDIM_INCREMENTAL);
2061 + rrddim_add(st, "OutType1", NULL, -1, 1, RRDDIM_INCREMENTAL);
2062 + rrddim_add(st, "OutType128", NULL, -1, 1, RRDDIM_INCREMENTAL);
2063 + rrddim_add(st, "OutType129", NULL, -1, 1, RRDDIM_INCREMENTAL);
2064 + rrddim_add(st, "OutType133", NULL, -1, 1, RRDDIM_INCREMENTAL);
2065 + rrddim_add(st, "OutType135", NULL, -1, 1, RRDDIM_INCREMENTAL);
2066 + rrddim_add(st, "OutType143", NULL, -1, 1, RRDDIM_INCREMENTAL);
2067 + } else
2068 + rrdset_next(st);
2069 +
2070 + rrddim_set(st, "InType1", icmp6stat.icp6s_inhist[1]);
2071 + rrddim_set(st, "InType128", icmp6stat.icp6s_inhist[128]);
2072 + rrddim_set(st, "InType129", icmp6stat.icp6s_inhist[129]);
2073 + rrddim_set(st, "InType136", icmp6stat.icp6s_inhist[136]);
2074 + rrddim_set(st, "OutType1", icmp6stat.icp6s_outhist[1]);
2075 + rrddim_set(st, "OutType128", icmp6stat.icp6s_outhist[128]);
2076 + rrddim_set(st, "OutType129", icmp6stat.icp6s_outhist[129]);
2077 + rrddim_set(st, "OutType133", icmp6stat.icp6s_outhist[133]);
2078 + rrddim_set(st, "OutType135", icmp6stat.icp6s_outhist[135]);
2079 + rrddim_set(st, "OutType143", icmp6stat.icp6s_outhist[143]);
2080 + rrdset_done(st);
2081 + }
2082 + }
2083 + }
2084 +
2085 return 0;
2086 }