@cryptotaxi247 / netdata-1 / commits / 330c77106

Add IPv4 packets, errors and fragments charts to macOS plugin

Vladimir Kobal committed Jan 9, 2017 at 14:55 UTC 330c7710624240f433fdb3048c3ef036dbb228cc
1 file changed +118 -1
src/macos_sysctl.c
+118 -1
@@ -29,7 +29,8 @@ 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,
32 - do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1;
32 + do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1,
33 + do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1;
34
35
36 if (unlikely(do_loadavg == -1)) {
@@ -47,6 +48,10 @@ int do_macos_sysctl(int update_every, usec_t dt) {
48 do_udp_errors = config_get_boolean("plugin:macos:sysctl", "ipv4 UDP errors", 1);
49 do_icmp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP packets", 1);
50 do_icmpmsg = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP messages", 1);
51 + do_ip_packets = config_get_boolean("plugin:freebsd:sysctl", "ipv4 packets", 1);
52 + do_ip_fragsout = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments sent", 1);
53 + do_ip_fragsin = config_get_boolean("plugin:freebsd:sysctl", "ipv4 fragments assembly", 1);
54 + do_ip_errors = config_get_boolean("plugin:freebsd:sysctl", "ipv4 errors", 1);
55 }
56
57 RRDSET *st;
@@ -87,6 +92,9 @@ int do_macos_sysctl(int update_every, usec_t dt) {
92 u_long msgs_out;
93 } icmp_total = {0, 0};
94
95 + // NEEDED BY: do_ip...
96 + struct ipstat ipstat;
97 +
98 // --------------------------------------------------------------------
99
100 if (last_loadavg_usec <= dt) {
@@ -486,6 +494,115 @@ int do_macos_sysctl(int update_every, usec_t dt) {
494 }
495 }
496
497 + // --------------------------------------------------------------------
498 +
499 + // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html
500 + if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) {
501 + if (unlikely(GETSYSCTL("net.inet.ip.stats", ipstat))) {
502 + do_ip_packets = 0;
503 + error("DISABLED: ipv4.packets");
504 + do_ip_fragsout = 0;
505 + error("DISABLED: ipv4.fragsout");
506 + do_ip_fragsin = 0;
507 + error("DISABLED: ipv4.fragsin");
508 + do_ip_errors = 0;
509 + error("DISABLED: ipv4.errors");
510 + } else {
511 + if (likely(do_ip_packets)) {
512 + st = rrdset_find("ipv4.packets");
513 + if (unlikely(!st)) {
514 + st = rrdset_create("ipv4", "packets", NULL, "packets", NULL, "IPv4 Packets", "packets/s",
515 + 3000, update_every, RRDSET_TYPE_LINE);
516 +
517 + rrddim_add(st, "InReceives", "received", 1, 1, RRDDIM_INCREMENTAL);
518 + rrddim_add(st, "OutRequests", "sent", -1, 1, RRDDIM_INCREMENTAL);
519 + rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRDDIM_INCREMENTAL);
520 + rrddim_add(st, "InDelivers", "delivered", 1, 1, RRDDIM_INCREMENTAL);
521 + } else
522 + rrdset_next(st);
523 +
524 + rrddim_set(st, "OutRequests", ipstat.ips_localout);
525 + rrddim_set(st, "InReceives", ipstat.ips_total);
526 + rrddim_set(st, "ForwDatagrams", ipstat.ips_forward);
527 + rrddim_set(st, "InDelivers", ipstat.ips_delivered);
528 + rrdset_done(st);
529 + }
530 +
531 + // --------------------------------------------------------------------
532 +
533 + if (likely(do_ip_fragsout)) {
534 + st = rrdset_find("ipv4.fragsout");
535 + if (unlikely(!st)) {
536 + st = rrdset_create("ipv4", "fragsout", NULL, "fragments", NULL, "IPv4 Fragments Sent",
537 + "packets/s", 3010, update_every, RRDSET_TYPE_LINE);
538 + st->isdetail = 1;
539 +
540 + rrddim_add(st, "FragOKs", "ok", 1, 1, RRDDIM_INCREMENTAL);
541 + rrddim_add(st, "FragFails", "failed", -1, 1, RRDDIM_INCREMENTAL);
542 + rrddim_add(st, "FragCreates", "created", 1, 1, RRDDIM_INCREMENTAL);
543 + } else
544 + rrdset_next(st);
545 +
546 + rrddim_set(st, "FragOKs", ipstat.ips_fragmented);
547 + rrddim_set(st, "FragFails", ipstat.ips_cantfrag);
548 + rrddim_set(st, "FragCreates", ipstat.ips_ofragments);
549 + rrdset_done(st);
550 + }
551 +
552 + // --------------------------------------------------------------------
553 +
554 + if (likely(do_ip_fragsin)) {
555 + st = rrdset_find("ipv4.fragsin");
556 + if (unlikely(!st)) {
557 + st = rrdset_create("ipv4", "fragsin", NULL, "fragments", NULL,
558 + "IPv4 Fragments Reassembly",
559 + "packets/s", 3011, update_every, RRDSET_TYPE_LINE);
560 + st->isdetail = 1;
561 +
562 + rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRDDIM_INCREMENTAL);
563 + rrddim_add(st, "ReasmFails", "failed", -1, 1, RRDDIM_INCREMENTAL);
564 + rrddim_add(st, "ReasmReqds", "all", 1, 1, RRDDIM_INCREMENTAL);
565 + } else
566 + rrdset_next(st);
567 +
568 + rrddim_set(st, "ReasmOKs", ipstat.ips_fragments);
569 + rrddim_set(st, "ReasmFails", ipstat.ips_fragdropped);
570 + rrddim_set(st, "ReasmReqds", ipstat.ips_reassembled);
571 + rrdset_done(st);
572 + }
573 +
574 + // --------------------------------------------------------------------
575 +
576 + if (likely(do_ip_errors)) {
577 + st = rrdset_find("ipv4.errors");
578 + if (unlikely(!st)) {
579 + st = rrdset_create("ipv4", "errors", NULL, "errors", NULL, "IPv4 Errors", "packets/s",
580 + 3002,
581 + update_every, RRDSET_TYPE_LINE);
582 + st->isdetail = 1;
583 +
584 + rrddim_add(st, "InDiscards", NULL, 1, 1, RRDDIM_INCREMENTAL);
585 + rrddim_add(st, "OutDiscards", NULL, -1, 1, RRDDIM_INCREMENTAL);
586 +
587 + rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
588 + rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRDDIM_INCREMENTAL);
589 +
590 + rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRDDIM_INCREMENTAL);
591 + rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRDDIM_INCREMENTAL);
592 + } else
593 + rrdset_next(st);
594 +
595 + rrddim_set(st, "InDiscards", ipstat.ips_badsum + ipstat.ips_tooshort + ipstat.ips_toosmall + ipstat.ips_toolong);
596 + rrddim_set(st, "OutDiscards", ipstat.ips_odropped);
597 + rrddim_set(st, "InHdrErrors", ipstat.ips_badhlen + ipstat.ips_badlen + ipstat.ips_badoptions + ipstat.ips_badvers);
598 + rrddim_set(st, "InAddrErrors", ipstat.ips_badaddr);
599 + rrddim_set(st, "InUnknownProtos", ipstat.ips_noproto);
600 + rrddim_set(st, "OutNoRoutes", ipstat.ips_noroute);
601 + rrdset_done(st);
602 + }
603 + }
604 + }
605 +
606 return 0;
607 }
608