@cryptotaxi247 / netdata-1 / commits / cfb7aef0d

Separate net.inet.icmp.stats module

Vladimir Kobal committed Mar 14, 2017 at 15:54 UTC cfb7aef0df3f24660beb6255dcd7ea211147d0ed
3 files changed +133 -97
src/freebsd_sysctl.c
+131 -97
@@ -1454,11 +1454,11 @@ int do_net_inet_tcp_stats(int update_every, usec_t dt) {
1454 CONFIG_BOOLEAN_AUTO);
1455 }
1456
1457 - static int mib[4] = {0, 0, 0, 0};
1458 - struct tcpstat tcpstat;
1459 -
1457 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1458 if (likely(do_tcp_packets || do_tcp_errors || do_tcp_handshake || do_tcpext_connaborts || do_tcpext_ofo || do_tcpext_syncookies || do_ecn)) {
1459 + static int mib[4] = {0, 0, 0, 0};
1460 + struct tcpstat tcpstat;
1461 +
1462 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.stats", mib, tcpstat))) {
1463 do_tcp_packets = 0;
1464 error("DISABLED: ipv4.tcppackets chart");
@@ -1739,11 +1739,11 @@ int do_net_inet_udp_stats(int update_every, usec_t dt) {
1739 do_udp_errors = config_get_boolean("plugin:freebsd:sysctl", "ipv4 UDP errors", 1);
1740 }
1741
1742 - static int mib[4] = {0, 0, 0, 0};
1743 - struct udpstat udpstat;
1744 -
1742 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
1743 if (likely(do_udp_packets || do_udp_errors)) {
1744 + static int mib[4] = {0, 0, 0, 0};
1745 + struct udpstat udpstat;
1746 +
1747 if (unlikely(GETSYSCTL_SIMPLE("net.inet.udp.stats", mib, udpstat))) {
1748 do_udp_packets = 0;
1749 error("DISABLED: ipv4.udppackets chart");
@@ -1828,13 +1828,137 @@ int do_net_inet_udp_stats(int update_every, usec_t dt) {
1828 return 0;
1829 }
1830
1831 +// --------------------------------------------------------------------------------------------------------------------
1832 +// net.inet.icmp.stats
1833 +
1834 +int do_net_inet_icmp_stats(int update_every, usec_t dt) {
1835 + static int do_icmp_packets = -1, do_icmp_errors = -1, do_icmpmsg = -1;
1836 +
1837 + if (unlikely(do_icmp_packets == -1)) {
1838 + do_icmp_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP packets", 1);
1839 + do_icmp_errors = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP errors", 1);
1840 + do_icmpmsg = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP messages", 1);
1841 + }
1842 +
1843 + if (likely(do_icmp_packets || do_icmp_errors || do_icmpmsg)) {
1844 + static int mib[4] = {0, 0, 0, 0};
1845 + struct icmpstat icmpstat;
1846 + int i;
1847 + struct icmp_total {
1848 + u_long msgs_in;
1849 + u_long msgs_out;
1850 + } icmp_total = {0, 0};
1851 +
1852 + if (unlikely(GETSYSCTL_SIMPLE("net.inet.icmp.stats", mib, icmpstat))) {
1853 + do_icmp_packets = 0;
1854 + error("DISABLED: ipv4.icmp chart");
1855 + do_icmp_errors = 0;
1856 + error("DISABLED: ipv4.icmp_errors chart");
1857 + do_icmpmsg = 0;
1858 + error("DISABLED: ipv4.icmpmsg chart");
1859 + error("DISABLED: net.inet.icmp.stats module");
1860 + return 1;
1861 + } else {
1862 + for (i = 0; i <= ICMP_MAXTYPE; i++) {
1863 + icmp_total.msgs_in += icmpstat.icps_inhist[i];
1864 + icmp_total.msgs_out += icmpstat.icps_outhist[i];
1865 + }
1866 + icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
1867 +
1868 + // --------------------------------------------------------------------
1869 +
1870 + if (likely(do_icmp_packets)) {
1871 + static RRDSET *st = NULL;
1872 + static RRDDIM *rd_in = NULL, *rd_out = NULL;
1873 +
1874 + if (unlikely(!st)) {
1875 + st = rrdset_create_localhost("ipv4",
1876 + "icmp",
1877 + NULL,
1878 + "icmp",
1879 + NULL,
1880 + "IPv4 ICMP Packets",
1881 + "packets/s",
1882 + 2602,
1883 + update_every,
1884 + RRDSET_TYPE_LINE
1885 + );
1886 +
1887 + rd_in = rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1888 + rd_out = rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1889 + } else
1890 + rrdset_next(st);
1891 +
1892 + rrddim_set_by_pointer(st, rd_in, icmp_total.msgs_in);
1893 + rrddim_set_by_pointer(st, rd_out, icmp_total.msgs_out);
1894 +
1895 + rrdset_done(st);
1896 + }
1897 +
1898 + // --------------------------------------------------------------------
1899 +
1900 + if (likely(do_icmp_errors)) {
1901 + static RRDSET *st = NULL;
1902 + static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_csum = NULL;
1903 +
1904 + if (unlikely(!st)) {
1905 + st = rrdset_create_localhost("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
1906 + "packets/s",
1907 + 2603, update_every, RRDSET_TYPE_LINE);
1908 +
1909 + rd_in = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1910 + rd_out = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1911 + rd_in_csum = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1912 + } else
1913 + rrdset_next(st);
1914 +
1915 + rrddim_set_by_pointer(st, rd_in, icmpstat.icps_badcode + icmpstat.icps_badlen +
1916 + icmpstat.icps_checksum + icmpstat.icps_tooshort);
1917 + rrddim_set_by_pointer(st, rd_out, icmpstat.icps_error);
1918 + rrddim_set_by_pointer(st, rd_in_csum, icmpstat.icps_checksum);
1919 +
1920 + rrdset_done(st);
1921 + }
1922 +
1923 + // --------------------------------------------------------------------
1924 +
1925 + if (likely(do_icmpmsg)) {
1926 + static RRDSET *st = NULL;
1927 + static RRDDIM *rd_in_reps = NULL, *rd_out_reps = NULL, *rd_in = NULL, *rd_out = NULL;
1928 +
1929 + if (unlikely(!st)) {
1930 + st = rrdset_create_localhost("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
1931 + "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
1932 +
1933 + rd_in_reps = rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1934 + rd_out_reps = rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1935 + rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1936 + rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1937 + } else
1938 + rrdset_next(st);
1939 +
1940 + rrddim_set_by_pointer(st, rd_in_reps, icmpstat.icps_inhist[ICMP_ECHOREPLY]);
1941 + rrddim_set_by_pointer(st, rd_out_reps, icmpstat.icps_outhist[ICMP_ECHOREPLY]);
1942 + rrddim_set_by_pointer(st, rd_in, icmpstat.icps_inhist[ICMP_ECHO]);
1943 + rrddim_set_by_pointer(st, rd_out, icmpstat.icps_outhist[ICMP_ECHO]);
1944 +
1945 + rrdset_done(st);
1946 + }
1947 + }
1948 + } else {
1949 + error("DISABLED: net.inet.icmp.stats module");
1950 + return 1;
1951 + }
1952 +
1953 + return 0;
1954 +}
1955 +
1956 // --------------------------------------------------------------------------------------------------------------------
1957 // old sources
1958
1959 int do_freebsd_sysctl_old(int update_every, usec_t dt) {
1960 static int do_disk_io = -1,
1961 do_bandwidth = -1,
1837 - do_icmp_packets = -1, do_icmpmsg = -1,
1962 do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1,
1963 do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1,
1964 do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1,
@@ -1843,8 +1967,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
1967 if (unlikely(do_disk_io == -1)) {
1968 do_disk_io = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
1969 do_bandwidth = config_get_boolean("plugin:freebsd:sysctl", "bandwidth", 1);
1846 - do_icmp_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP packets", 1);
1847 - do_icmpmsg = config_get_boolean("plugin:freebsd:sysctl", "ipv4 ICMP messages", 1);
1970 do_ip_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 packets", 1);
1971 do_ip_fragsout = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments sent", 1);
1972 do_ip_fragsin = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments assembly", 1);
@@ -1899,13 +2021,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2021 u_long ift_obytes;
2022 } iftot = {0, 0};
2023
1902 - // NEEDED BY: do_icmp...
1903 - struct icmpstat icmpstat;
1904 - struct icmp_total {
1905 - u_long msgs_in;
1906 - u_long msgs_out;
1907 - } icmp_total = {0, 0};
1908 -
2024 // NEEDED BY: do_ip...
2025 struct ipstat ipstat;
2026
@@ -2252,87 +2367,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2367
2368 // --------------------------------------------------------------------
2369
2255 - if (likely(do_icmp_packets || do_icmpmsg)) {
2256 - if (unlikely(GETSYSCTL_BY_NAME("net.inet.icmp.stats", icmpstat))) {
2257 - do_icmp_packets = 0;
2258 - error("DISABLED: ipv4.icmp");
2259 - error("DISABLED: ipv4.icmp_errors");
2260 - do_icmpmsg = 0;
2261 - error("DISABLED: ipv4.icmpmsg");
2262 - } else {
2263 - for (i = 0; i <= ICMP_MAXTYPE; i++) {
2264 - icmp_total.msgs_in += icmpstat.icps_inhist[i];
2265 - icmp_total.msgs_out += icmpstat.icps_outhist[i];
2266 - }
2267 - icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
2268 -
2269 - // --------------------------------------------------------------------
2270 -
2271 - if (likely(do_icmp_packets)) {
2272 - st = rrdset_find_localhost("ipv4.icmp");
2273 - if (unlikely(!st)) {
2274 - st = rrdset_create_localhost("ipv4", "icmp", NULL, "icmp", NULL, "IPv4 ICMP Packets", "packets/s",
2275 - 2602,
2276 - update_every, RRDSET_TYPE_LINE);
2277 -
2278 - rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2279 - rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2280 - } else
2281 - rrdset_next(st);
2282 -
2283 - rrddim_set(st, "InMsgs", icmp_total.msgs_in);
2284 - rrddim_set(st, "OutMsgs", icmp_total.msgs_out);
2285 -
2286 - rrdset_done(st);
2287 -
2288 - // --------------------------------------------------------------------
2289 -
2290 - st = rrdset_find_localhost("ipv4.icmp_errors");
2291 - if (unlikely(!st)) {
2292 - st = rrdset_create_localhost("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
2293 - "packets/s",
2294 - 2603, update_every, RRDSET_TYPE_LINE);
2295 -
2296 - rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2297 - rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2298 - rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2299 - } else
2300 - rrdset_next(st);
2301 -
2302 - rrddim_set(st, "InErrors", icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort);
2303 - rrddim_set(st, "OutErrors", icmpstat.icps_error);
2304 - rrddim_set(st, "InCsumErrors", icmpstat.icps_checksum);
2305 -
2306 - rrdset_done(st);
2307 - }
2308 -
2309 - // --------------------------------------------------------------------
2310 -
2311 - if (likely(do_icmpmsg)) {
2312 - st = rrdset_find_localhost("ipv4.icmpmsg");
2313 - if (unlikely(!st)) {
2314 - st = rrdset_create_localhost("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
2315 - "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
2316 -
2317 - rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2318 - rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2319 - rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2320 - rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2321 - } else
2322 - rrdset_next(st);
2323 -
2324 - rrddim_set(st, "InEchoReps", icmpstat.icps_inhist[ICMP_ECHOREPLY]);
2325 - rrddim_set(st, "OutEchoReps", icmpstat.icps_outhist[ICMP_ECHOREPLY]);
2326 - rrddim_set(st, "InEchos", icmpstat.icps_inhist[ICMP_ECHO]);
2327 - rrddim_set(st, "OutEchos", icmpstat.icps_outhist[ICMP_ECHO]);
2328 -
2329 - rrdset_done(st);
2330 - }
2331 - }
2332 - }
2333 -
2334 - // --------------------------------------------------------------------
2335 -
2370 // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html
2371 if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) {
2372 if (unlikely(GETSYSCTL_BY_NAME("net.inet.ip.stats", ipstat))) {
src/plugin_freebsd.c
+1
@@ -37,6 +37,7 @@ static struct freebsd_module {
37 { .name = "net.inet.tcp.states", .dim = "tcp_states", .enabled = 1, .func = do_net_inet_tcp_states },
38 { .name = "net.inet.tcp.stats", .dim = "tcp_stats", .enabled = 1, .func = do_net_inet_tcp_stats },
39 { .name = "net.inet.udp.stats", .dim = "udp_stats", .enabled = 1, .func = do_net_inet_udp_stats },
40 + { .name = "net.inet.icmp.stats", .dim = "icmp_stats", .enabled = 1, .func = do_net_inet_icmp_stats },
41
42 // CPU metrics
43 { .name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times },
src/plugin_freebsd.h
+1
@@ -28,6 +28,7 @@ extern int do_net_isr(int update_every, usec_t dt);
28 extern int do_net_inet_tcp_states(int update_every, usec_t dt);
29 extern int do_net_inet_tcp_stats(int update_every, usec_t dt);
30 extern int do_net_inet_udp_stats(int update_every, usec_t dt);
31 +extern int do_net_inet_icmp_stats(int update_every, usec_t dt);
32
33 extern int do_freebsd_sysctl_old(int update_every, usec_t dt);
34