3 #include <sys/vmmeter.h>
4 #include <sys/devicestat.h>
6 #include <vm/vm_param.h>
14 #include <net/netisr.h>
18 #include <netinet/ip.h>
19 #include <netinet/ip_var.h>
20 #include <netinet/ip_icmp.h>
21 #include <netinet/icmp_var.h>
22 #include <netinet6/ip6_var.h>
23 #include <netinet/icmp6.h>
24 #include <netinet/tcp_var.h>
25 #include <netinet/tcp_fsm.h>
26 #include <netinet/udp.h>
27 #include <netinet/udp_var.h>
29 // --------------------------------------------------------------------------------------------------------------------
30 // common definitions and variables
32 #define KILO_FACTOR 1024
33 #define MEGA_FACTOR 1048576 // 1024 * 1024
34 #define GIGA_FACTOR 1073741824 // 1024 * 1024 * 1024
36 #define MAX_INT_DIGITS 10 // maximum number of digits for int
38 int system_pagesize = PAGE_SIZE;
39 int number_of_cpus = 1;
41 // --------------------------------------------------------------------------------------------------------------------
42 // FreeBSD plugin initialization
44 int freebsd_plugin_init()
46 system_pagesize = getpagesize();
47 if (system_pagesize <= 0) {
48 error("FREEBSD: can't get system page size");
52 if (unlikely(GETSYSCTL_BY_NAME("kern.smp.cpus", number_of_cpus))) {
53 error("FREEBSD: can't get number of cpus");
57 if (unlikely(!number_of_cpus)) {
58 error("FREEBSD: wrong number of cpus");
65 // --------------------------------------------------------------------------------------------------------------------
68 // FreeBSD calculates load averages once every 5 seconds
69 #define MIN_LOADAVG_UPDATE_EVERY 5
71 int do_vm_loadavg(int update_every, usec_t dt){
72 static usec_t next_loadavg_dt = 0;
74 if (next_loadavg_dt <= dt) {
75 static int mib[2] = {0, 0};
76 struct loadavg sysload;
78 if (unlikely(GETSYSCTL_SIMPLE("vm.loadavg", mib, sysload))) {
79 error("DISABLED: system.load chart");
80 error("DISABLED: vm.loadavg module");
84 // --------------------------------------------------------------------
86 static RRDSET *st = NULL;
87 static RRDDIM *rd_load1 = NULL, *rd_load2 = NULL, *rd_load3 = NULL;
90 st = rrdset_create_localhost("system",
95 "System Load Average",
98 (update_every < MIN_LOADAVG_UPDATE_EVERY) ?
99 MIN_LOADAVG_UPDATE_EVERY : update_every, RRDSET_TYPE_LINE
101 rd_load1 = rrddim_add(st, "load1", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
102 rd_load2 = rrddim_add(st, "load5", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
103 rd_load3 = rrddim_add(st, "load15", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
107 rrddim_set_by_pointer(st, rd_load1, (collected_number) ((double) sysload.ldavg[0] / sysload.fscale * 1000));
108 rrddim_set_by_pointer(st, rd_load2, (collected_number) ((double) sysload.ldavg[1] / sysload.fscale * 1000));
109 rrddim_set_by_pointer(st, rd_load3, (collected_number) ((double) sysload.ldavg[2] / sysload.fscale * 1000));
112 next_loadavg_dt = st->update_every * USEC_PER_SEC;
116 next_loadavg_dt -= dt;
121 // --------------------------------------------------------------------------------------------------------------------
124 int do_vm_vmtotal(int update_every, usec_t dt) {
125 static int do_all_processes = -1, do_processes = -1, do_committed = -1;
127 if (unlikely(do_all_processes == -1)) {
128 do_all_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "enable total processes", 1);
129 do_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "processes running", 1);
130 do_committed = config_get_boolean("plugin:freebsd:vm.vmtotal", "committed memory", 1);
133 if (likely(do_all_processes | do_processes | do_committed)) {
134 static int mib[2] = {0, 0};
135 struct vmtotal vmtotal_data;
137 if (unlikely(GETSYSCTL_SIMPLE("vm.vmtotal", mib, vmtotal_data))) {
138 do_all_processes = 0;
139 error("DISABLED: system.active_processes chart");
141 error("DISABLED: system.processes chart");
143 error("DISABLED: mem.committed chart");
144 error("DISABLED: vm.vmtotal module");
148 // --------------------------------------------------------------------
150 if (likely(do_all_processes)) {
151 static RRDSET *st = NULL;
152 static RRDDIM *rd = NULL;
155 st = rrdset_create_localhost("system",
160 "System Active Processes",
166 rd = rrddim_add(st, "active", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
168 else rrdset_next(st);
170 rrddim_set_by_pointer(st, rd, (vmtotal_data.t_rq + vmtotal_data.t_dw + vmtotal_data.t_pw + vmtotal_data.t_sl + vmtotal_data.t_sw));
174 // --------------------------------------------------------------------
176 if (likely(do_processes)) {
177 static RRDSET *st = NULL;
178 static RRDDIM *rd_running = NULL, *rd_blocked = NULL;
181 st = rrdset_create_localhost("system",
193 rd_running = rrddim_add(st, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
194 rd_blocked = rrddim_add(st, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
196 else rrdset_next(st);
198 rrddim_set_by_pointer(st, rd_running, vmtotal_data.t_rq);
199 rrddim_set_by_pointer(st, rd_blocked, (vmtotal_data.t_dw + vmtotal_data.t_pw));
203 // --------------------------------------------------------------------
205 if (likely(do_committed)) {
206 static RRDSET *st = NULL;
207 static RRDDIM *rd = NULL;
210 st = rrdset_create_localhost("mem",
215 "Committed (Allocated) Memory",
221 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
223 rd = rrddim_add(st, "Committed_AS", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
225 else rrdset_next(st);
227 rrddim_set_by_pointer(st, rd, vmtotal_data.t_rm);
232 error("DISABLED: vm.vmtotal module");
239 // --------------------------------------------------------------------------------------------------------------------
242 int do_kern_cp_time(int update_every, usec_t dt) {
243 if (unlikely(CPUSTATES != 5)) {
244 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
245 error("DISABLED: system.cpu chart");
246 error("DISABLED: kern.cp_time module");
249 static int mib[2] = {0, 0};
250 long cp_time[CPUSTATES];
252 if (unlikely(GETSYSCTL_SIMPLE("kern.cp_time", mib, cp_time))) {
253 error("DISABLED: system.cpu chart");
254 error("DISABLED: kern.cp_time module");
258 // --------------------------------------------------------------------
260 static RRDSET *st = NULL;
261 static RRDDIM *rd_nice = NULL, *rd_system = NULL, *rd_user = NULL, *rd_interrupt = NULL, *rd_idle = NULL;
264 st = rrdset_create_localhost("system",
269 "Total CPU utilization",
275 rd_nice = rrddim_add(st, "nice", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
276 rd_system = rrddim_add(st, "system", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
277 rd_user = rrddim_add(st, "user", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
278 rd_interrupt = rrddim_add(st, "interrupt", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
279 rd_idle = rrddim_add(st, "idle", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
280 rrddim_hide(st, "idle");
282 else rrdset_next(st);
284 rrddim_set_by_pointer(st, rd_nice, cp_time[1]);
285 rrddim_set_by_pointer(st, rd_system, cp_time[2]);
286 rrddim_set_by_pointer(st, rd_user, cp_time[0]);
287 rrddim_set_by_pointer(st, rd_interrupt, cp_time[3]);
288 rrddim_set_by_pointer(st, rd_idle, cp_time[4]);
296 // --------------------------------------------------------------------------------------------------------------------
299 int do_kern_cp_times(int update_every, usec_t dt) {
300 if (unlikely(CPUSTATES != 5)) {
301 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
302 error("DISABLED: cpu.cpuXX charts");
303 error("DISABLED: kern.cp_times module");
306 static int mib[2] = {0, 0};
307 long cp_time[CPUSTATES];
308 static long *pcpu_cp_time = NULL;
310 pcpu_cp_time = reallocz(pcpu_cp_time, sizeof(cp_time) * number_of_cpus);
311 if (unlikely(GETSYSCTL_WSIZE("kern.cp_times", mib, pcpu_cp_time, sizeof(cp_time) * number_of_cpus))) {
312 error("DISABLED: cpu.cpuXX charts");
313 error("DISABLED: kern.cp_times module");
317 // --------------------------------------------------------------------
320 static struct cpu_chart {
321 char cpuid[MAX_INT_DIGITS + 4];
326 RRDDIM *rd_interrupt;
328 } *all_cpu_charts = NULL;
330 all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus);
332 for (i = 0; i < number_of_cpus; i++) {
333 if (unlikely(!all_cpu_charts[i].st)) {
334 snprintfz(all_cpu_charts[i].cpuid, MAX_INT_DIGITS, "cpu%d", i);
335 all_cpu_charts[i].st = rrdset_create_localhost("cpu",
336 all_cpu_charts[i].cpuid,
347 all_cpu_charts[i].rd_nice = rrddim_add(all_cpu_charts[i].st, "nice", NULL, 1, 1,
348 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
349 all_cpu_charts[i].rd_system = rrddim_add(all_cpu_charts[i].st, "system", NULL, 1, 1,
350 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
351 all_cpu_charts[i].rd_user = rrddim_add(all_cpu_charts[i].st, "user", NULL, 1, 1,
352 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
353 all_cpu_charts[i].rd_interrupt = rrddim_add(all_cpu_charts[i].st, "interrupt", NULL, 1, 1,
354 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
355 all_cpu_charts[i].rd_idle = rrddim_add(all_cpu_charts[i].st, "idle", NULL, 1, 1,
356 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
357 rrddim_hide(all_cpu_charts[i].st, "idle");
358 } else rrdset_next(all_cpu_charts[i].st);
360 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_nice, pcpu_cp_time[i * 5 + 1]);
361 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_system, pcpu_cp_time[i * 5 + 2]);
362 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_user, pcpu_cp_time[i * 5 + 0]);
363 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_interrupt, pcpu_cp_time[i * 5 + 3]);
364 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_idle, pcpu_cp_time[i * 5 + 4]);
365 rrdset_done(all_cpu_charts[i].st);
373 // --------------------------------------------------------------------------------------------------------------------
376 int do_hw_intcnt(int update_every, usec_t dt) {
377 static int mib_hw_intrcnt[2] = {0, 0};
381 if (unlikely(GETSYSCTL_SIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt_size))) {
382 error("DISABLED: system.intr chart");
383 error("DISABLED: system.interrupts chart");
384 error("DISABLED: hw.intrcnt module");
387 unsigned long nintr = 0;
388 static unsigned long *intrcnt = NULL;
389 unsigned long long totalintr = 0;
391 nintr = intrcnt_size / sizeof(u_long);
392 intrcnt = reallocz(intrcnt, nintr * sizeof(u_long));
393 if (unlikely(GETSYSCTL_WSIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt, nintr * sizeof(u_long)))) {
394 error("DISABLED: system.intr chart");
395 error("DISABLED: system.interrupts chart");
396 error("DISABLED: hw.intrcnt module");
399 for (i = 0; i < nintr; i++)
400 totalintr += intrcnt[i];
402 // --------------------------------------------------------------------
404 static RRDSET *st_intr = NULL;
405 static RRDDIM *rd_intr = NULL;
407 if (unlikely(!st_intr)) {
408 st_intr = rrdset_create_localhost("system",
413 "Total Hardware Interrupts",
419 rrdset_flag_set(st_intr, RRDSET_FLAG_DETAIL);
421 rd_intr = rrddim_add(st_intr, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
423 rrdset_next(st_intr);
425 rrddim_set_by_pointer(st_intr, rd_intr, totalintr);
426 rrdset_done(st_intr);
428 // --------------------------------------------------------------------
431 static int mib_hw_intrnames[2] = {0, 0};
432 static char *intrnames = NULL;
434 size = nintr * (MAXCOMLEN + 1);
435 intrnames = reallocz(intrnames, size);
436 if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) {
437 error("DISABLED: system.intr chart");
438 error("DISABLED: system.interrupts chart");
439 error("DISABLED: hw.intrcnt module");
443 // --------------------------------------------------------------------
445 static RRDSET *st_interrupts = NULL;
446 RRDDIM *rd_interrupts = NULL;
449 if (unlikely(!st_interrupts))
450 st_interrupts = rrdset_create_localhost("system",
462 rrdset_next(st_interrupts);
464 for (i = 0; i < nintr; i++) {
465 p = intrnames + i * (MAXCOMLEN + 1);
466 if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
467 rd_interrupts = rrddim_find(st_interrupts, p);
468 if (unlikely(!rd_interrupts))
469 rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
470 rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
473 rrdset_done(st_interrupts);
481 // --------------------------------------------------------------------------------------------------------------------
482 // vm.stats.sys.v_intr
484 int do_vm_stats_sys_v_intr(int update_every, usec_t dt) {
485 static int mib[4] = {0, 0, 0, 0};
488 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_intr", mib, int_number))) {
489 error("DISABLED: system.dev_intr chart");
490 error("DISABLED: vm.stats.sys.v_intr module");
494 // --------------------------------------------------------------------
496 static RRDSET *st = NULL;
497 static RRDDIM *rd = NULL;
500 st = rrdset_create_localhost("system",
512 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
514 else rrdset_next(st);
516 rrddim_set_by_pointer(st, rd, int_number);
523 // --------------------------------------------------------------------------------------------------------------------
524 // vm.stats.sys.v_soft
526 int do_vm_stats_sys_v_soft(int update_every, usec_t dt) {
527 static int mib[4] = {0, 0, 0, 0};
528 u_int soft_intr_number;
530 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_soft", mib, soft_intr_number))) {
531 error("DISABLED: system.dev_intr chart");
532 error("DISABLED: vm.stats.sys.v_soft module");
536 // --------------------------------------------------------------------
538 static RRDSET *st = NULL;
539 static RRDDIM *rd = NULL;
542 st = rrdset_create_localhost("system",
547 "Software Interrupts",
554 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
556 else rrdset_next(st);
558 rrddim_set_by_pointer(st, rd, soft_intr_number);
565 // --------------------------------------------------------------------------------------------------------------------
566 // vm.stats.sys.v_swtch
568 int do_vm_stats_sys_v_swtch(int update_every, usec_t dt) {
569 static int mib[4] = {0, 0, 0, 0};
572 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_swtch", mib, ctxt_number))) {
573 error("DISABLED: system.ctxt chart");
574 error("DISABLED: vm.stats.sys.v_swtch module");
578 // --------------------------------------------------------------------
580 static RRDSET *st = NULL;
581 static RRDDIM *rd = NULL;
584 st = rrdset_create_localhost("system",
589 "CPU Context Switches",
590 "context switches/s",
596 rd = rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
598 else rrdset_next(st);
600 rrddim_set_by_pointer(st, rd, ctxt_number);
607 // --------------------------------------------------------------------------------------------------------------------
608 // vm.stats.vm.v_forks
610 int do_vm_stats_sys_v_forks(int update_every, usec_t dt) {
611 static int mib[4] = {0, 0, 0, 0};
614 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_forks", mib, forks_number))) {
615 error("DISABLED: system.forks chart");
616 error("DISABLED: vm.stats.sys.v_swtch module");
620 // --------------------------------------------------------------------
622 static RRDSET *st = NULL;
623 static RRDDIM *rd = NULL;
626 st = rrdset_create_localhost("system",
638 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
640 rd = rrddim_add(st, "started", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
642 else rrdset_next(st);
644 rrddim_set_by_pointer(st, rd, forks_number);
651 // --------------------------------------------------------------------------------------------------------------------
654 int do_vm_swap_info(int update_every, usec_t dt) {
655 static int mib[3] = {0, 0, 0};
657 if (unlikely(getsysctl_mib("vm.swap_info", mib, 2))) {
658 error("DISABLED: system.swap chart");
659 error("DISABLED: vm.swap_info module");
665 collected_number bytes_used;
666 collected_number bytes_total;
667 } total_xsw = {0, 0};
674 if (unlikely(sysctl(mib, 3, &xsw, &size, NULL, 0) == -1 )) {
675 if (unlikely(errno != ENOENT)) {
676 error("FREEBSD: sysctl(%s...) failed: %s", "vm.swap_info", strerror(errno));
677 error("DISABLED: system.swap chart");
678 error("DISABLED: vm.swap_info module");
681 if (unlikely(size != sizeof(xsw))) {
682 error("FREEBSD: sysctl(%s...) expected %lu, got %lu", "vm.swap_info", (unsigned long)sizeof(xsw), (unsigned long)size);
683 error("DISABLED: system.swap chart");
684 error("DISABLED: vm.swap_info module");
689 total_xsw.bytes_used += xsw.xsw_used;
690 total_xsw.bytes_total += xsw.xsw_nblks;
693 // --------------------------------------------------------------------
695 static RRDSET *st = NULL;
696 static RRDDIM *rd_free = NULL, *rd_used = NULL;
699 st = rrdset_create_localhost("system",
711 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
713 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
714 rd_used = rrddim_add(st, "used", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
716 else rrdset_next(st);
718 rrddim_set_by_pointer(st, rd_free, total_xsw.bytes_total - total_xsw.bytes_used);
719 rrddim_set_by_pointer(st, rd_used, total_xsw.bytes_used);
726 // --------------------------------------------------------------------------------------------------------------------
729 int do_system_ram(int update_every, usec_t dt) {
730 static int mib_active_count[4] = {0, 0, 0, 0}, mib_inactive_count[4] = {0, 0, 0, 0}, mib_wire_count[4] = {0, 0, 0, 0},
731 mib_cache_count[4] = {0, 0, 0, 0}, mib_vfs_bufspace[2] = {0, 0}, mib_free_count[4] = {0, 0, 0, 0};
732 struct vmmeter vmmeter_data;
733 int vfs_bufspace_count;
735 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_active_count", mib_active_count, vmmeter_data.v_active_count) ||
736 GETSYSCTL_SIMPLE("vm.stats.vm.v_inactive_count", mib_inactive_count, vmmeter_data.v_inactive_count) ||
737 GETSYSCTL_SIMPLE("vm.stats.vm.v_wire_count", mib_wire_count, vmmeter_data.v_wire_count) ||
738 #if __FreeBSD_version < 1200016
739 GETSYSCTL_SIMPLE("vm.stats.vm.v_cache_count", mib_cache_count, vmmeter_data.v_cache_count) ||
741 GETSYSCTL_SIMPLE("vfs.bufspace", mib_vfs_bufspace, vfs_bufspace_count) ||
742 GETSYSCTL_SIMPLE("vm.stats.vm.v_free_count", mib_free_count, vmmeter_data.v_free_count))) {
743 error("DISABLED: system.ram chart");
744 error("DISABLED: System.ram module");
748 // --------------------------------------------------------------------
750 static RRDSET *st = NULL;
751 static RRDDIM *rd_free = NULL, *rd_active = NULL, *rd_inactive = NULL,
752 *rd_wired = NULL, *rd_cache = NULL, *rd_buffers = NULL;
754 st = rrdset_find_localhost("system.ram");
756 st = rrdset_create_localhost("system",
768 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
769 rd_active = rrddim_add(st, "active", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
770 rd_inactive = rrddim_add(st, "inactive", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
771 rd_wired = rrddim_add(st, "wired", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
772 #if __FreeBSD_version < 1200016
773 rd_cache = rrddim_add(st, "cache", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
775 rd_buffers = rrddim_add(st, "buffers", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
777 else rrdset_next(st);
779 rrddim_set_by_pointer(st, rd_free, vmmeter_data.v_free_count);
780 rrddim_set_by_pointer(st, rd_active, vmmeter_data.v_active_count);
781 rrddim_set_by_pointer(st, rd_inactive, vmmeter_data.v_inactive_count);
782 rrddim_set_by_pointer(st, rd_wired, vmmeter_data.v_wire_count);
783 #if __FreeBSD_version < 1200016
784 rrddim_set_by_pointer(st, rd_cache, vmmeter_data.v_cache_count);
786 rrddim_set_by_pointer(st, rd_buffers, vfs_bufspace_count);
793 // --------------------------------------------------------------------------------------------------------------------
794 // vm.stats.vm.v_swappgs
796 int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt) {
797 static int mib_swappgsin[4] = {0, 0, 0, 0}, mib_swappgsout[4] = {0, 0, 0, 0};
798 struct vmmeter vmmeter_data;
800 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsin", mib_swappgsin, vmmeter_data.v_swappgsin) ||
801 GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsout", mib_swappgsout, vmmeter_data.v_swappgsout))) {
802 error("DISABLED: system.swapio chart");
803 error("DISABLED: vm.stats.vm.v_swappgs module");
807 // --------------------------------------------------------------------
809 static RRDSET *st = NULL;
810 static RRDDIM *rd_in = NULL, *rd_out = NULL;
813 st = rrdset_create_localhost("system",
825 rd_in = rrddim_add(st, "in", NULL, system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
826 rd_out = rrddim_add(st, "out", NULL, -system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
828 else rrdset_next(st);
830 rrddim_set_by_pointer(st, rd_in, vmmeter_data.v_swappgsin);
831 rrddim_set_by_pointer(st, rd_out, vmmeter_data.v_swappgsout);
838 // --------------------------------------------------------------------------------------------------------------------
839 // vm.stats.vm.v_pgfaults
841 int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt) {
842 static int mib_vm_faults[4] = {0, 0, 0, 0}, mib_io_faults[4] = {0, 0, 0, 0}, mib_cow_faults[4] = {0, 0, 0, 0},
843 mib_cow_optim[4] = {0, 0, 0, 0}, mib_intrans[4] = {0, 0, 0, 0};
844 struct vmmeter vmmeter_data;
846 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_vm_faults", mib_vm_faults, vmmeter_data.v_vm_faults) ||
847 GETSYSCTL_SIMPLE("vm.stats.vm.v_io_faults", mib_io_faults, vmmeter_data.v_io_faults) ||
848 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_faults", mib_cow_faults, vmmeter_data.v_cow_faults) ||
849 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_optim", mib_cow_optim, vmmeter_data.v_cow_optim) ||
850 GETSYSCTL_SIMPLE("vm.stats.vm.v_intrans", mib_intrans, vmmeter_data.v_intrans))) {
851 error("DISABLED: mem.pgfaults chart");
852 error("DISABLED: vm.stats.vm.v_pgfaults module");
856 // --------------------------------------------------------------------
858 static RRDSET *st = NULL;
859 static RRDDIM *rd_memory = NULL, *rd_io_requiring = NULL, *rd_cow = NULL,
860 *rd_cow_optimized = NULL, *rd_in_transit = NULL;
863 st = rrdset_create_localhost("mem",
868 "Memory Page Faults",
875 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
877 rd_memory = rrddim_add(st, "memory", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
878 rd_io_requiring = rrddim_add(st, "io_requiring", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
879 rd_cow = rrddim_add(st, "cow", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
880 rd_cow_optimized = rrddim_add(st, "cow_optimized", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
881 rd_in_transit = rrddim_add(st, "in_transit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
883 else rrdset_next(st);
885 rrddim_set_by_pointer(st, rd_memory, vmmeter_data.v_vm_faults);
886 rrddim_set_by_pointer(st, rd_io_requiring, vmmeter_data.v_io_faults);
887 rrddim_set_by_pointer(st, rd_cow, vmmeter_data.v_cow_faults);
888 rrddim_set_by_pointer(st, rd_cow_optimized, vmmeter_data.v_cow_optim);
889 rrddim_set_by_pointer(st, rd_in_transit, vmmeter_data.v_intrans);
896 // --------------------------------------------------------------------------------------------------------------------
899 int do_kern_ipc_sem(int update_every, usec_t dt) {
900 static int mib_semmni[3] = {0, 0, 0}, mib_sema[3] = {0, 0, 0};
903 collected_number sets;
904 collected_number semaphores;
905 } ipc_sem = {0, 0, 0};
907 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.semmni", mib_semmni, ipc_sem.semmni))) {
908 error("DISABLED: system.ipc_semaphores chart");
909 error("DISABLED: system.ipc_semaphore_arrays chart");
910 error("DISABLED: kern.ipc.sem module");
913 static struct semid_kernel *ipc_sem_data = NULL;
915 ipc_sem_data = reallocz(ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni);
916 if (unlikely(GETSYSCTL_WSIZE("kern.ipc.sema", mib_sema, ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni))) {
917 error("DISABLED: system.ipc_semaphores chart");
918 error("DISABLED: system.ipc_semaphore_arrays chart");
919 error("DISABLED: kern.ipc.sem module");
924 for (i = 0; i < ipc_sem.semmni; i++) {
925 if (unlikely(ipc_sem_data[i].u.sem_perm.mode & SEM_ALLOC)) {
927 ipc_sem.semaphores += ipc_sem_data[i].u.sem_nsems;
931 // --------------------------------------------------------------------
933 static RRDSET *st_semaphores = NULL, *st_semaphore_arrays = NULL;
934 static RRDDIM *rd_semaphores = NULL, *rd_semaphore_arrays = NULL;
936 if (unlikely(!st_semaphores)) {
937 st_semaphores = rrdset_create_localhost("system",
945 localhost->rrd_update_every,
949 rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
951 else rrdset_next(st_semaphores);
953 rrddim_set_by_pointer(st_semaphores, rd_semaphores, ipc_sem.semaphores);
954 rrdset_done(st_semaphores);
956 // --------------------------------------------------------------------
958 if (unlikely(!st_semaphore_arrays)) {
959 st_semaphore_arrays = rrdset_create_localhost("system",
960 "ipc_semaphore_arrays",
964 "IPC Semaphore Arrays",
967 localhost->rrd_update_every,
971 rd_semaphore_arrays = rrddim_add(st_semaphore_arrays, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
973 else rrdset_next(st_semaphore_arrays);
975 rrddim_set_by_pointer(st_semaphore_arrays, rd_semaphore_arrays, ipc_sem.sets);
976 rrdset_done(st_semaphore_arrays);
983 // --------------------------------------------------------------------------------------------------------------------
986 int do_kern_ipc_shm(int update_every, usec_t dt) {
987 static int mib_shmmni[3] = {0, 0, 0}, mib_shmsegs[3] = {0, 0, 0};
990 collected_number segs;
991 collected_number segsize;
992 } ipc_shm = {0, 0, 0};
994 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.shmmni", mib_shmmni, ipc_shm.shmmni))) {
995 error("DISABLED: system.ipc_shared_mem_segs chart");
996 error("DISABLED: system.ipc_shared_mem_size chart");
997 error("DISABLED: kern.ipc.shmmodule");
1000 static struct shmid_kernel *ipc_shm_data = NULL;
1002 ipc_shm_data = reallocz(ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni);
1004 GETSYSCTL_WSIZE("kern.ipc.shmsegs", mib_shmsegs, ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni))) {
1005 error("DISABLED: system.ipc_shared_mem_segs chart");
1006 error("DISABLED: system.ipc_shared_mem_size chart");
1007 error("DISABLED: kern.ipc.shmmodule");
1012 for (i = 0; i < ipc_shm.shmmni; i++) {
1013 if (unlikely(ipc_shm_data[i].u.shm_perm.mode & 0x0800)) {
1015 ipc_shm.segsize += ipc_shm_data[i].u.shm_segsz;
1019 // --------------------------------------------------------------------
1021 static RRDSET *st_segs = NULL, *st_size = NULL;
1022 static RRDDIM *rd_segments = NULL, *rd_allocated = NULL;
1024 if (unlikely(!st_segs)) {
1025 st_segs = rrdset_create_localhost("system",
1026 "ipc_shared_mem_segs",
1028 "ipc shared memory",
1030 "IPC Shared Memory Segments",
1033 localhost->rrd_update_every,
1037 rd_segments = rrddim_add(st_segs, "segments", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1039 else rrdset_next(st_segs);
1041 rrddim_set_by_pointer(st_segs, rd_segments, ipc_shm.segs);
1042 rrdset_done(st_segs);
1044 // --------------------------------------------------------------------
1046 if (unlikely(!st_size)) {
1047 st_size = rrdset_create_localhost("system",
1048 "ipc_shared_mem_size",
1050 "ipc shared memory",
1052 "IPC Shared Memory Segments Size",
1055 localhost->rrd_update_every,
1059 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, KILO_FACTOR, RRD_ALGORITHM_ABSOLUTE);
1061 else rrdset_next(st_size);
1063 rrddim_set_by_pointer(st_size, rd_allocated, ipc_shm.segsize);
1064 rrdset_done(st_size);
1071 // --------------------------------------------------------------------------------------------------------------------
1074 int do_kern_ipc_msq(int update_every, usec_t dt) {
1075 static int mib_msgmni[3] = {0, 0, 0}, mib_msqids[3] = {0, 0, 0};
1078 collected_number queues;
1079 collected_number messages;
1080 collected_number usedsize;
1081 collected_number allocsize;
1082 } ipc_msq = {0, 0, 0, 0, 0};
1084 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.msgmni", mib_msgmni, ipc_msq.msgmni))) {
1085 error("DISABLED: system.ipc_msq_queues chart");
1086 error("DISABLED: system.ipc_msq_messages chart");
1087 error("DISABLED: system.ipc_msq_size chart");
1088 error("DISABLED: kern.ipc.msg module");
1091 static struct msqid_kernel *ipc_msq_data = NULL;
1093 ipc_msq_data = reallocz(ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni);
1095 GETSYSCTL_WSIZE("kern.ipc.msqids", mib_msqids, ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni))) {
1096 error("DISABLED: system.ipc_msq_queues chart");
1097 error("DISABLED: system.ipc_msq_messages chart");
1098 error("DISABLED: system.ipc_msq_size chart");
1099 error("DISABLED: kern.ipc.msg module");
1104 for (i = 0; i < ipc_msq.msgmni; i++) {
1105 if (unlikely(ipc_msq_data[i].u.msg_qbytes != 0)) {
1106 ipc_msq.queues += 1;
1107 ipc_msq.messages += ipc_msq_data[i].u.msg_qnum;
1108 ipc_msq.usedsize += ipc_msq_data[i].u.msg_cbytes;
1109 ipc_msq.allocsize += ipc_msq_data[i].u.msg_qbytes;
1113 // --------------------------------------------------------------------
1115 static RRDSET *st_queues = NULL, *st_messages = NULL, *st_size = NULL;
1116 static RRDDIM *rd_queues = NULL, *rd_messages = NULL, *rd_allocated = NULL, *rd_used = NULL;
1118 if (unlikely(!st_queues)) {
1119 st_queues = rrdset_create_localhost("system",
1122 "ipc message queues",
1124 "Number of IPC Message Queues",
1127 localhost->rrd_update_every,
1131 rd_queues = rrddim_add(st_queues, "queues", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1133 else rrdset_next(st_queues);
1135 rrddim_set_by_pointer(st_queues, rd_queues, ipc_msq.queues);
1136 rrdset_done(st_queues);
1138 // --------------------------------------------------------------------
1140 if (unlikely(!st_messages)) {
1141 st_messages = rrdset_create_localhost("system",
1144 "ipc message queues",
1146 "Number of Messages in IPC Message Queues",
1149 localhost->rrd_update_every,
1153 rd_messages = rrddim_add(st_messages, "messages", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1155 else rrdset_next(st_messages);
1157 rrddim_set_by_pointer(st_messages, rd_messages, ipc_msq.messages);
1158 rrdset_done(st_messages);
1160 // --------------------------------------------------------------------
1162 if (unlikely(!st_size)) {
1163 st_size = rrdset_create_localhost("system",
1166 "ipc message queues",
1168 "Size of IPC Message Queues",
1171 localhost->rrd_update_every,
1175 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1176 rd_used = rrddim_add(st_size, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1178 else rrdset_next(st_size);
1180 rrddim_set_by_pointer(st_size, rd_allocated, ipc_msq.allocsize);
1181 rrddim_set_by_pointer(st_size, rd_used, ipc_msq.usedsize);
1182 rrdset_done(st_size);
1189 // --------------------------------------------------------------------------------------------------------------------
1192 int do_uptime(int update_every, usec_t dt) {
1193 struct timespec up_time;
1195 clock_gettime(CLOCK_UPTIME, &up_time);
1197 // --------------------------------------------------------------------
1199 static RRDSET *st = NULL;
1200 static RRDDIM *rd = NULL;
1203 st = rrdset_create_localhost("system",
1215 rd = rrddim_add(st, "uptime", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1217 else rrdset_next(st);
1219 rrddim_set_by_pointer(st, rd, up_time.tv_sec);
1225 // --------------------------------------------------------------------------------------------------------------------
1228 int do_net_isr(int update_every, usec_t dt) {
1229 static int do_netisr = -1, do_netisr_per_core = -1;
1231 if (unlikely(do_netisr == -1)) {
1232 do_netisr = config_get_boolean("plugin:freebsd:net.isr", "netisr", 1);
1233 do_netisr_per_core = config_get_boolean("plugin:freebsd:net.isr", "netisr per core", 1);
1236 static int mib_workstream[3] = {0, 0, 0}, mib_work[3] = {0, 0, 0};
1237 int common_error = 0;
1239 size_t netisr_workstream_size, netisr_work_size;
1240 unsigned long num_netisr_workstreams = 0, num_netisr_works = 0;
1241 static struct sysctl_netisr_workstream *netisr_workstream = NULL;
1242 static struct sysctl_netisr_work *netisr_work = NULL;
1243 static struct netisr_stats {
1244 collected_number dispatched;
1245 collected_number hybrid_dispatched;
1246 collected_number qdrops;
1247 collected_number queued;
1248 } *netisr_stats = NULL;
1250 if (likely(do_netisr || do_netisr_per_core)) {
1251 if (unlikely(GETSYSCTL_SIZE("net.isr.workstream", mib_workstream, netisr_workstream_size))) {
1253 } else if (unlikely(GETSYSCTL_SIZE("net.isr.work", mib_work, netisr_work_size))) {
1256 num_netisr_workstreams = netisr_workstream_size / sizeof(struct sysctl_netisr_workstream);
1257 netisr_workstream = reallocz(netisr_workstream, num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream));
1258 if (unlikely(GETSYSCTL_WSIZE("net.isr.workstream", mib_workstream, netisr_workstream,
1259 num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream)))){
1262 num_netisr_works = netisr_work_size / sizeof(struct sysctl_netisr_work);
1263 netisr_work = reallocz(netisr_work, num_netisr_works * sizeof(struct sysctl_netisr_work));
1264 if (unlikely(GETSYSCTL_WSIZE("net.isr.work", mib_work, netisr_work,
1265 num_netisr_works * sizeof(struct sysctl_netisr_work)))){
1270 if (unlikely(common_error)) {
1272 error("DISABLED: system.softnet_stat chart");
1273 do_netisr_per_core = 0;
1274 error("DISABLED: system.cpuX_softnet_stat chart");
1276 error("DISABLED: net.isr module");
1279 netisr_stats = reallocz(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1280 bzero(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1281 for (i = 0; i < num_netisr_workstreams; i++) {
1282 for (n = 0; n < num_netisr_works; n++) {
1283 if (netisr_workstream[i].snws_wsid == netisr_work[n].snw_wsid) {
1284 netisr_stats[netisr_workstream[i].snws_cpu].dispatched += netisr_work[n].snw_dispatched;
1285 netisr_stats[netisr_workstream[i].snws_cpu].hybrid_dispatched += netisr_work[n].snw_hybrid_dispatched;
1286 netisr_stats[netisr_workstream[i].snws_cpu].qdrops += netisr_work[n].snw_qdrops;
1287 netisr_stats[netisr_workstream[i].snws_cpu].queued += netisr_work[n].snw_queued;
1291 for (i = 0; i < number_of_cpus; i++) {
1292 netisr_stats[number_of_cpus].dispatched += netisr_stats[i].dispatched;
1293 netisr_stats[number_of_cpus].hybrid_dispatched += netisr_stats[i].hybrid_dispatched;
1294 netisr_stats[number_of_cpus].qdrops += netisr_stats[i].qdrops;
1295 netisr_stats[number_of_cpus].queued += netisr_stats[i].queued;
1299 error("DISABLED: net.isr module");
1303 // --------------------------------------------------------------------
1305 if (likely(do_netisr)) {
1306 static RRDSET *st = NULL;
1307 static RRDDIM *rd_dispatched = NULL, *rd_hybrid_dispatched = NULL, *rd_qdrops = NULL, *rd_queued = NULL;
1309 if (unlikely(!st)) {
1310 st = rrdset_create_localhost("system",
1315 "System softnet_stat",
1322 rd_dispatched = rrddim_add(st, "dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1323 rd_hybrid_dispatched = rrddim_add(st, "hybrid_dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1324 rd_qdrops = rrddim_add(st, "qdrops", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1325 rd_queued = rrddim_add(st, "queued", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1327 else rrdset_next(st);
1329 rrddim_set_by_pointer(st, rd_dispatched, netisr_stats[number_of_cpus].dispatched);
1330 rrddim_set_by_pointer(st, rd_hybrid_dispatched, netisr_stats[number_of_cpus].hybrid_dispatched);
1331 rrddim_set_by_pointer(st, rd_qdrops, netisr_stats[number_of_cpus].qdrops);
1332 rrddim_set_by_pointer(st, rd_queued, netisr_stats[number_of_cpus].queued);
1336 // --------------------------------------------------------------------
1338 if (likely(do_netisr_per_core)) {
1339 static struct softnet_chart {
1340 char netisr_cpuid[MAX_INT_DIGITS + 17];
1342 RRDDIM *rd_dispatched;
1343 RRDDIM *rd_hybrid_dispatched;
1346 } *all_softnet_charts = NULL;
1348 all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus);
1350 for (i = 0; i < number_of_cpus ;i++) {
1351 snprintfz(all_softnet_charts[i].netisr_cpuid, MAX_INT_DIGITS + 17, "cpu%d_softnet_stat", i);
1353 if (unlikely(!all_softnet_charts[i].st)) {
1354 all_softnet_charts[i].st = rrdset_create_localhost("cpu",
1355 all_softnet_charts[i].netisr_cpuid,
1359 "Per CPU netisr statistics",
1366 all_softnet_charts[i].rd_dispatched = rrddim_add(all_softnet_charts[i].st, "dispatched",
1367 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1368 all_softnet_charts[i].rd_hybrid_dispatched = rrddim_add(all_softnet_charts[i].st, "hybrid_dispatched",
1369 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1370 all_softnet_charts[i].rd_qdrops = rrddim_add(all_softnet_charts[i].st, "qdrops",
1371 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1372 all_softnet_charts[i].rd_queued = rrddim_add(all_softnet_charts[i].st, "queued",
1373 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1375 else rrdset_next(all_softnet_charts[i].st);
1377 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_dispatched,
1378 netisr_stats[i].dispatched);
1379 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_hybrid_dispatched,
1380 netisr_stats[i].hybrid_dispatched);
1381 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_qdrops,
1382 netisr_stats[i].qdrops);
1383 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_queued,
1384 netisr_stats[i].queued);
1385 rrdset_done(all_softnet_charts[i].st);
1392 // --------------------------------------------------------------------------------------------------------------------
1393 // net.inet.tcp.states
1395 int do_net_inet_tcp_states(int update_every, usec_t dt) {
1396 static int mib[4] = {0, 0, 0, 0};
1397 uint64_t tcps_states[TCP_NSTATES];
1399 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1400 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.states", mib, tcps_states))) {
1401 error("DISABLED: ipv4.tcpsock chart");
1402 error("DISABLED: net.inet.tcp.states module");
1406 // --------------------------------------------------------------------
1408 static RRDSET *st = NULL;
1409 static RRDDIM *rd = NULL;
1411 if (unlikely(!st)) {
1412 st = rrdset_create_localhost("ipv4",
1417 "IPv4 TCP Connections",
1418 "active connections",
1424 rd = rrddim_add(st, "CurrEstab", "connections", 1, 1, RRD_ALGORITHM_ABSOLUTE);
1428 rrddim_set_by_pointer(st, rd, tcps_states[TCPS_ESTABLISHED]);
1435 // --------------------------------------------------------------------------------------------------------------------
1436 // net.inet.tcp.stats
1438 int do_net_inet_tcp_stats(int update_every, usec_t dt) {
1439 static int do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1, do_tcpext_connaborts = -1, do_tcpext_ofo = -1, do_tcpext_syncookies = -1, do_ecn = -1;
1441 if (unlikely(do_tcp_packets == -1)) {
1442 do_tcp_packets = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP packets", 1);
1443 do_tcp_errors = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP errors", 1);
1444 do_tcp_handshake = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP handshake issues", 1);
1445 do_tcpext_connaborts = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP connection aborts",
1446 CONFIG_BOOLEAN_AUTO);
1447 do_tcpext_ofo = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP out-of-order queue",
1448 CONFIG_BOOLEAN_AUTO);
1449 do_tcpext_syncookies = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP SYN cookies",
1450 CONFIG_BOOLEAN_AUTO);
1451 do_ecn = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "ECN packets",
1452 CONFIG_BOOLEAN_AUTO);
1455 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1456 if (likely(do_tcp_packets || do_tcp_errors || do_tcp_handshake || do_tcpext_connaborts || do_tcpext_ofo || do_tcpext_syncookies || do_ecn)) {
1457 static int mib[4] = {0, 0, 0, 0};
1458 struct tcpstat tcpstat;
1460 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.stats", mib, tcpstat))) {
1462 error("DISABLED: ipv4.tcppackets chart");
1464 error("DISABLED: ipv4.tcperrors chart");
1465 do_tcp_handshake = 0;
1466 error("DISABLED: ipv4.tcphandshake chart");
1467 do_tcpext_connaborts = 0;
1468 error("DISABLED: ipv4.tcpconnaborts chart");
1470 error("DISABLED: ipv4.tcpofo chart");
1471 do_tcpext_syncookies = 0;
1472 error("DISABLED: ipv4.tcpsyncookies chart");
1474 error("DISABLED: ipv4.ecnpkts chart");
1475 error("DISABLED: net.inet.tcp.stats module");
1479 // --------------------------------------------------------------------
1481 if (likely(do_tcp_packets)) {
1482 static RRDSET *st = NULL;
1483 static RRDDIM *rd_in_segs = NULL, *rd_out_segs = NULL;
1485 if (unlikely(!st)) {
1486 st = rrdset_create_localhost("ipv4",
1498 rd_in_segs = rrddim_add(st, "InSegs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1499 rd_out_segs = rrddim_add(st, "OutSegs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1503 rrddim_set_by_pointer(st, rd_in_segs, tcpstat.tcps_rcvtotal);
1504 rrddim_set_by_pointer(st, rd_out_segs, tcpstat.tcps_sndtotal);
1508 // --------------------------------------------------------------------
1510 if (likely(do_tcp_errors)) {
1511 static RRDSET *st = NULL;
1512 static RRDDIM *rd_in_errs = NULL, *rd_in_csum_errs = NULL, *rd_retrans_segs = NULL;
1514 if (unlikely(!st)) {
1515 st = rrdset_create_localhost("ipv4",
1527 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1529 rd_in_errs = rrddim_add(st, "InErrs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1530 rd_in_csum_errs = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1531 rd_retrans_segs = rrddim_add(st, "RetransSegs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1535 #if __FreeBSD__ >= 11
1536 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvreassfull +
1537 tcpstat.tcps_rcvshort);
1539 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvshort);
1541 rrddim_set_by_pointer(st, rd_in_csum_errs, tcpstat.tcps_rcvbadsum);
1542 rrddim_set_by_pointer(st, rd_retrans_segs, tcpstat.tcps_sndrexmitpack);
1546 // --------------------------------------------------------------------
1548 if (likely(do_tcp_handshake)) {
1549 static RRDSET *st = NULL;
1550 static RRDDIM *rd_estab_resets = NULL, *rd_active_opens = NULL, *rd_passive_opens = NULL,
1551 *rd_attempt_fails = NULL;
1553 if (unlikely(!st)) {
1554 st = rrdset_create_localhost("ipv4",
1559 "IPv4 TCP Handshake Issues",
1566 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1568 rd_estab_resets = rrddim_add(st, "EstabResets", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1569 rd_active_opens = rrddim_add(st, "ActiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1570 rd_passive_opens = rrddim_add(st, "PassiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1571 rd_attempt_fails = rrddim_add(st, "AttemptFails", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1575 rrddim_set_by_pointer(st, rd_estab_resets, tcpstat.tcps_drops);
1576 rrddim_set_by_pointer(st, rd_active_opens, tcpstat.tcps_connattempt);
1577 rrddim_set_by_pointer(st, rd_passive_opens, tcpstat.tcps_accepts);
1578 rrddim_set_by_pointer(st, rd_attempt_fails, tcpstat.tcps_conndrops);
1582 // --------------------------------------------------------------------
1584 if (do_tcpext_connaborts == CONFIG_BOOLEAN_YES || (do_tcpext_connaborts == CONFIG_BOOLEAN_AUTO && (tcpstat.tcps_rcvpackafterwin || tcpstat.tcps_rcvafterclose || tcpstat.tcps_rcvmemdrop || tcpstat.tcps_persistdrop || tcpstat.tcps_finwait2_drops))) {
1585 do_tcpext_connaborts = CONFIG_BOOLEAN_YES;
1587 static RRDSET *st = NULL;
1588 static RRDDIM *rd_on_data = NULL, *rd_on_close = NULL, *rd_on_memory = NULL,
1589 *rd_on_timeout = NULL, *rd_on_linger = NULL;
1591 if (unlikely(!st)) {
1592 st = rrdset_create_localhost("ipv4",
1597 "TCP Connection Aborts",
1604 rd_on_data = rrddim_add(st, "TCPAbortOnData", "baddata", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1605 rd_on_close = rrddim_add(st, "TCPAbortOnClose", "userclosed", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1606 rd_on_memory = rrddim_add(st, "TCPAbortOnMemory", "nomemory", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1607 rd_on_timeout = rrddim_add(st, "TCPAbortOnTimeout", "timeout", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1608 rd_on_linger = rrddim_add(st, "TCPAbortOnLinger", "linger", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1610 else rrdset_next(st);
1612 rrddim_set_by_pointer(st, rd_on_data, tcpstat.tcps_rcvpackafterwin);
1613 rrddim_set_by_pointer(st, rd_on_close, tcpstat.tcps_rcvafterclose);
1614 rrddim_set_by_pointer(st, rd_on_memory, tcpstat.tcps_rcvmemdrop);
1615 rrddim_set_by_pointer(st, rd_on_timeout, tcpstat.tcps_persistdrop);
1616 rrddim_set_by_pointer(st, rd_on_linger, tcpstat.tcps_finwait2_drops);
1620 // --------------------------------------------------------------------
1622 if (do_tcpext_ofo == CONFIG_BOOLEAN_YES || (do_tcpext_ofo == CONFIG_BOOLEAN_AUTO && tcpstat.tcps_rcvoopack)) {
1623 do_tcpext_ofo = CONFIG_BOOLEAN_YES;
1625 static RRDSET *st = NULL;
1626 static RRDDIM *rd_ofo_queue = NULL;
1628 if (unlikely(!st)) {
1629 st = rrdset_create_localhost("ipv4",
1634 "TCP Out-Of-Order Queue",
1641 rd_ofo_queue = rrddim_add(st, "TCPOFOQueue", "inqueue", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1643 else rrdset_next(st);
1645 rrddim_set_by_pointer(st, rd_ofo_queue, tcpstat.tcps_rcvoopack);
1649 // --------------------------------------------------------------------
1651 if (do_tcpext_syncookies == CONFIG_BOOLEAN_YES || (do_tcpext_syncookies == CONFIG_BOOLEAN_AUTO && (tcpstat.tcps_sc_sendcookie || tcpstat.tcps_sc_recvcookie || tcpstat.tcps_sc_zonefail))) {
1652 do_tcpext_syncookies = CONFIG_BOOLEAN_YES;
1654 static RRDSET *st = NULL;
1655 static RRDDIM *rd_recv = NULL, *rd_send = NULL, *rd_failed = NULL;
1657 if (unlikely(!st)) {
1658 st = rrdset_create_localhost("ipv4",
1670 rd_recv = rrddim_add(st, "SyncookiesRecv", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1671 rd_send = rrddim_add(st, "SyncookiesSent", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1672 rd_failed = rrddim_add(st, "SyncookiesFailed", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1674 else rrdset_next(st);
1676 rrddim_set_by_pointer(st, rd_recv, tcpstat.tcps_sc_recvcookie);
1677 rrddim_set_by_pointer(st, rd_send, tcpstat.tcps_sc_sendcookie);
1678 rrddim_set_by_pointer(st, rd_failed, tcpstat.tcps_sc_zonefail);
1682 // --------------------------------------------------------------------
1684 if (do_ecn == CONFIG_BOOLEAN_YES || (do_ecn == CONFIG_BOOLEAN_AUTO && (tcpstat.tcps_ecn_ce || tcpstat.tcps_ecn_ect0 || tcpstat.tcps_ecn_ect1))) {
1685 do_ecn = CONFIG_BOOLEAN_YES;
1687 static RRDSET *st = NULL;
1688 static RRDDIM *rd_ce = NULL, *rd_no_ect = NULL, *rd_ect0 = NULL, *rd_ect1 = NULL;
1690 if (unlikely(!st)) {
1691 st = rrdset_create_localhost("ipv4",
1696 "IPv4 ECN Statistics",
1703 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1705 rd_ce = rrddim_add(st, "InCEPkts", "CEP", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1706 rd_no_ect = rrddim_add(st, "InNoECTPkts", "NoECTP", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1707 rd_ect0 = rrddim_add(st, "InECT0Pkts", "ECTP0", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1708 rd_ect1 = rrddim_add(st, "InECT1Pkts", "ECTP1", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1710 else rrdset_next(st);
1712 rrddim_set_by_pointer(st, rd_ce, tcpstat.tcps_ecn_ce);
1713 rrddim_set_by_pointer(st, rd_no_ect, tcpstat.tcps_ecn_ce - (tcpstat.tcps_ecn_ect0 +
1714 tcpstat.tcps_ecn_ect1));
1715 rrddim_set_by_pointer(st, rd_ect0, tcpstat.tcps_ecn_ect0);
1716 rrddim_set_by_pointer(st, rd_ect1, tcpstat.tcps_ecn_ect1);
1722 error("DISABLED: net.inet.tcp.stats module");
1729 // --------------------------------------------------------------------------------------------------------------------
1730 // net.inet.udp.stats
1732 int do_net_inet_udp_stats(int update_every, usec_t dt) {
1733 static int do_udp_packets = -1, do_udp_errors = -1;
1735 if (unlikely(do_udp_packets == -1)) {
1736 do_udp_packets = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP packets", 1);
1737 do_udp_errors = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP errors", 1);
1740 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
1741 if (likely(do_udp_packets || do_udp_errors)) {
1742 static int mib[4] = {0, 0, 0, 0};
1743 struct udpstat udpstat;
1745 if (unlikely(GETSYSCTL_SIMPLE("net.inet.udp.stats", mib, udpstat))) {
1747 error("DISABLED: ipv4.udppackets chart");
1749 error("DISABLED: ipv4.udperrors chart");
1750 error("DISABLED: net.inet.udp.stats module");
1754 // --------------------------------------------------------------------
1756 if (likely(do_udp_packets)) {
1757 static RRDSET *st = NULL;
1758 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1760 if (unlikely(!st)) {
1761 st = rrdset_create_localhost("ipv4",
1773 rd_in = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1774 rd_out = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1778 rrddim_set_by_pointer(st, rd_in, udpstat.udps_ipackets);
1779 rrddim_set_by_pointer(st, rd_out, udpstat.udps_opackets);
1783 // --------------------------------------------------------------------
1785 if (likely(do_udp_errors)) {
1786 static RRDSET *st = NULL;
1787 static RRDDIM *rd_in_errors = NULL, *rd_no_ports = NULL, *rd_recv_buf_errors = NULL,
1788 *rd_in_csum_errors = NULL, *rd_ignored_multi = NULL;
1790 if (unlikely(!st)) {
1791 st = rrdset_create_localhost("ipv4",
1803 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1805 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1806 rd_no_ports = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1807 rd_recv_buf_errors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1808 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1809 rd_ignored_multi = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1813 rrddim_set_by_pointer(st, rd_in_errors, udpstat.udps_hdrops + udpstat.udps_badlen);
1814 rrddim_set_by_pointer(st, rd_no_ports, udpstat.udps_noport);
1815 rrddim_set_by_pointer(st, rd_recv_buf_errors, udpstat.udps_fullsock);
1816 rrddim_set_by_pointer(st, rd_in_csum_errors, udpstat.udps_badsum + udpstat.udps_nosum);
1817 rrddim_set_by_pointer(st, rd_ignored_multi, udpstat.udps_filtermcast);
1822 error("DISABLED: net.inet.udp.stats module");
1829 // --------------------------------------------------------------------------------------------------------------------
1830 // net.inet.icmp.stats
1832 int do_net_inet_icmp_stats(int update_every, usec_t dt) {
1833 static int do_icmp_packets = -1, do_icmp_errors = -1, do_icmpmsg = -1;
1835 if (unlikely(do_icmp_packets == -1)) {
1836 do_icmp_packets = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP packets", 1);
1837 do_icmp_errors = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP errors", 1);
1838 do_icmpmsg = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP messages", 1);
1841 if (likely(do_icmp_packets || do_icmp_errors || do_icmpmsg)) {
1842 static int mib[4] = {0, 0, 0, 0};
1843 struct icmpstat icmpstat;
1848 } icmp_total = {0, 0};
1850 if (unlikely(GETSYSCTL_SIMPLE("net.inet.icmp.stats", mib, icmpstat))) {
1851 do_icmp_packets = 0;
1852 error("DISABLED: ipv4.icmp chart");
1854 error("DISABLED: ipv4.icmp_errors chart");
1856 error("DISABLED: ipv4.icmpmsg chart");
1857 error("DISABLED: net.inet.icmp.stats module");
1860 for (i = 0; i <= ICMP_MAXTYPE; i++) {
1861 icmp_total.msgs_in += icmpstat.icps_inhist[i];
1862 icmp_total.msgs_out += icmpstat.icps_outhist[i];
1864 icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
1866 // --------------------------------------------------------------------
1868 if (likely(do_icmp_packets)) {
1869 static RRDSET *st = NULL;
1870 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1872 if (unlikely(!st)) {
1873 st = rrdset_create_localhost("ipv4",
1878 "IPv4 ICMP Packets",
1885 rd_in = rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1886 rd_out = rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1890 rrddim_set_by_pointer(st, rd_in, icmp_total.msgs_in);
1891 rrddim_set_by_pointer(st, rd_out, icmp_total.msgs_out);
1896 // --------------------------------------------------------------------
1898 if (likely(do_icmp_errors)) {
1899 static RRDSET *st = NULL;
1900 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_csum = NULL;
1902 if (unlikely(!st)) {
1903 st = rrdset_create_localhost("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
1905 2603, update_every, RRDSET_TYPE_LINE);
1907 rd_in = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1908 rd_out = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1909 rd_in_csum = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1913 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_badcode + icmpstat.icps_badlen +
1914 icmpstat.icps_checksum + icmpstat.icps_tooshort);
1915 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_error);
1916 rrddim_set_by_pointer(st, rd_in_csum, icmpstat.icps_checksum);
1921 // --------------------------------------------------------------------
1923 if (likely(do_icmpmsg)) {
1924 static RRDSET *st = NULL;
1925 static RRDDIM *rd_in_reps = NULL, *rd_out_reps = NULL, *rd_in = NULL, *rd_out = NULL;
1927 if (unlikely(!st)) {
1928 st = rrdset_create_localhost("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
1929 "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
1931 rd_in_reps = rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1932 rd_out_reps = rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1933 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1934 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1938 rrddim_set_by_pointer(st, rd_in_reps, icmpstat.icps_inhist[ICMP_ECHOREPLY]);
1939 rrddim_set_by_pointer(st, rd_out_reps, icmpstat.icps_outhist[ICMP_ECHOREPLY]);
1940 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_inhist[ICMP_ECHO]);
1941 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_outhist[ICMP_ECHO]);
1947 error("DISABLED: net.inet.icmp.stats module");
1954 // --------------------------------------------------------------------------------------------------------------------
1955 // net.inet.ip.stats
1957 int do_net_inet_ip_stats(int update_every, usec_t dt) {
1958 static int do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1;
1960 if (unlikely(do_ip_packets == -1)) {
1961 do_ip_packets = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 packets", 1);
1962 do_ip_fragsout = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments sent", 1);
1963 do_ip_fragsin = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments assembly", 1);
1964 do_ip_errors = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 errors", 1);
1967 // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html
1968 if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) {
1969 static int mib[4] = {0, 0, 0, 0};
1970 struct ipstat ipstat;
1972 if (unlikely(GETSYSCTL_SIMPLE("net.inet.ip.stats", mib, ipstat))) {
1974 error("DISABLED: ipv4.packets chart");
1976 error("DISABLED: ipv4.fragsout chart");
1978 error("DISABLED: ipv4.fragsin chart");
1980 error("DISABLED: ipv4.errors chart");
1981 error("DISABLED: net.inet.ip.stats module");
1985 // --------------------------------------------------------------------
1987 if (likely(do_ip_packets)) {
1988 static RRDSET *st = NULL;
1989 static RRDDIM *rd_in_receives = NULL, *rd_out_requests = NULL, *rd_forward_datagrams = NULL,
1990 *rd_in_delivers = NULL;
1992 if (unlikely(!st)) {
1993 st = rrdset_create_localhost("ipv4",
2005 rd_in_receives = rrddim_add(st, "InReceives", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2006 rd_out_requests = rrddim_add(st, "OutRequests", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2007 rd_forward_datagrams = rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2008 rd_in_delivers = rrddim_add(st, "InDelivers", "delivered", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2012 rrddim_set_by_pointer(st, rd_in_receives, ipstat.ips_total);
2013 rrddim_set_by_pointer(st, rd_out_requests, ipstat.ips_localout);
2014 rrddim_set_by_pointer(st, rd_forward_datagrams, ipstat.ips_forward);
2015 rrddim_set_by_pointer(st, rd_in_delivers, ipstat.ips_delivered);
2019 // --------------------------------------------------------------------
2021 if (likely(do_ip_fragsout)) {
2022 static RRDSET *st = NULL;
2023 static RRDDIM *rd_ok = NULL, *rd_fails = NULL, *rd_created = NULL;
2025 if (unlikely(!st)) {
2026 st = rrdset_create_localhost("ipv4",
2031 "IPv4 Fragments Sent",
2038 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2040 rd_ok = rrddim_add(st, "FragOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2041 rd_fails = rrddim_add(st, "FragFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2042 rd_created = rrddim_add(st, "FragCreates", "created", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2046 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragmented);
2047 rrddim_set_by_pointer(st, rd_fails, ipstat.ips_cantfrag);
2048 rrddim_set_by_pointer(st, rd_created, ipstat.ips_ofragments);
2052 // --------------------------------------------------------------------
2054 if (likely(do_ip_fragsin)) {
2055 static RRDSET *st = NULL;
2056 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2058 if (unlikely(!st)) {
2059 st = rrdset_create_localhost("ipv4",
2064 "IPv4 Fragments Reassembly",
2071 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2073 rd_ok = rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2074 rd_failed = rrddim_add(st, "ReasmFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2075 rd_all = rrddim_add(st, "ReasmReqds", "all", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2079 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragments);
2080 rrddim_set_by_pointer(st, rd_failed, ipstat.ips_fragdropped);
2081 rrddim_set_by_pointer(st, rd_all, ipstat.ips_reassembled);
2085 // --------------------------------------------------------------------
2087 if (likely(do_ip_errors)) {
2088 static RRDSET *st = NULL;
2089 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2090 *rd_in_hdr_errors = NULL, *rd_out_no_routes = NULL,
2091 *rd_in_addr_errors = NULL, *rd_in_unknown_protos = NULL;
2093 if (unlikely(!st)) {
2094 st = rrdset_create_localhost("ipv4",
2106 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2108 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2109 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2110 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2111 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2112 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2113 rd_in_unknown_protos = rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2117 rrddim_set_by_pointer(st, rd_in_discards, ipstat.ips_badsum + ipstat.ips_tooshort +
2118 ipstat.ips_toosmall + ipstat.ips_toolong);
2119 rrddim_set_by_pointer(st, rd_out_discards, ipstat.ips_odropped);
2120 rrddim_set_by_pointer(st, rd_in_hdr_errors, ipstat.ips_badhlen + ipstat.ips_badlen +
2121 ipstat.ips_badoptions + ipstat.ips_badvers);
2122 rrddim_set_by_pointer(st, rd_out_no_routes, ipstat.ips_noroute);
2123 rrddim_set_by_pointer(st, rd_in_addr_errors, ipstat.ips_badaddr);
2124 rrddim_set_by_pointer(st, rd_in_unknown_protos, ipstat.ips_noproto);
2129 error("DISABLED: net.inet.ip.stats module");
2136 // --------------------------------------------------------------------------------------------------------------------
2137 // net.inet6.ip6.stats
2139 int do_net_inet6_ip6_stats(int update_every, usec_t dt) {
2140 static int do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1;
2142 if (unlikely(do_ip6_packets == -1)) {
2143 do_ip6_packets = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 packets",
2144 CONFIG_BOOLEAN_AUTO);
2145 do_ip6_fragsout = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments sent",
2146 CONFIG_BOOLEAN_AUTO);
2147 do_ip6_fragsin = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments assembly",
2148 CONFIG_BOOLEAN_AUTO);
2149 do_ip6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 errors",
2150 CONFIG_BOOLEAN_AUTO);
2153 if (likely(do_ip6_packets || do_ip6_fragsout || do_ip6_fragsin || do_ip6_errors)) {
2154 static int mib[4] = {0, 0, 0, 0};
2155 struct ip6stat ip6stat;
2157 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.ip6.stats", mib, ip6stat))) {
2159 error("DISABLED: ipv6.packets chart");
2160 do_ip6_fragsout = 0;
2161 error("DISABLED: ipv6.fragsout chart");
2163 error("DISABLED: ipv6.fragsin chart");
2165 error("DISABLED: ipv6.errors chart");
2166 error("DISABLED: net.inet6.ip6.stats module");
2170 // --------------------------------------------------------------------
2172 if (do_ip6_packets == CONFIG_BOOLEAN_YES || (do_ip6_packets == CONFIG_BOOLEAN_AUTO &&
2173 (ip6stat.ip6s_localout || ip6stat.ip6s_total ||
2174 ip6stat.ip6s_forward || ip6stat.ip6s_delivered))) {
2175 do_ip6_packets = CONFIG_BOOLEAN_YES;
2177 static RRDSET *st = NULL;
2178 static RRDDIM *rd_received = NULL, *rd_sent = NULL, *rd_forwarded = NULL, *rd_delivers = NULL;
2180 if (unlikely(!st)) {
2181 st = rrdset_create_localhost("ipv6",
2193 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2194 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2195 rd_forwarded = rrddim_add(st, "forwarded", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2196 rd_delivers = rrddim_add(st, "delivers", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2200 rrddim_set_by_pointer(st, rd_sent, ip6stat.ip6s_localout);
2201 rrddim_set_by_pointer(st, rd_received, ip6stat.ip6s_total);
2202 rrddim_set_by_pointer(st, rd_forwarded, ip6stat.ip6s_forward);
2203 rrddim_set_by_pointer(st, rd_delivers, ip6stat.ip6s_delivered);
2207 // --------------------------------------------------------------------
2209 if (do_ip6_fragsout == CONFIG_BOOLEAN_YES || (do_ip6_fragsout == CONFIG_BOOLEAN_AUTO &&
2210 (ip6stat.ip6s_fragmented || ip6stat.ip6s_cantfrag ||
2211 ip6stat.ip6s_ofragments))) {
2212 do_ip6_fragsout = CONFIG_BOOLEAN_YES;
2214 static RRDSET *st = NULL;
2215 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2217 if (unlikely(!st)) {
2218 st = rrdset_create_localhost("ipv6",
2223 "IPv6 Fragments Sent",
2230 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2232 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2233 rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2234 rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2238 rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_fragmented);
2239 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_cantfrag);
2240 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_ofragments);
2244 // --------------------------------------------------------------------
2246 if (do_ip6_fragsin == CONFIG_BOOLEAN_YES || (do_ip6_fragsin == CONFIG_BOOLEAN_AUTO &&
2247 (ip6stat.ip6s_reassembled || ip6stat.ip6s_fragdropped ||
2248 ip6stat.ip6s_fragtimeout || ip6stat.ip6s_fragments))) {
2249 do_ip6_fragsin = CONFIG_BOOLEAN_YES;
2251 static RRDSET *st = NULL;
2252 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_timeout = NULL, *rd_all = NULL;
2254 if (unlikely(!st)) {
2255 st = rrdset_create_localhost("ipv6",
2260 "IPv6 Fragments Reassembly",
2267 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2269 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2270 rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2271 rd_timeout = rrddim_add(st, "timeout", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2272 rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2276 rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_reassembled);
2277 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_fragdropped);
2278 rrddim_set_by_pointer(st, rd_timeout, ip6stat.ip6s_fragtimeout);
2279 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_fragments);
2283 // --------------------------------------------------------------------
2285 if (do_ip6_errors == CONFIG_BOOLEAN_YES || (do_ip6_errors == CONFIG_BOOLEAN_AUTO && (
2286 ip6stat.ip6s_toosmall ||
2287 ip6stat.ip6s_odropped ||
2288 ip6stat.ip6s_badoptions ||
2289 ip6stat.ip6s_badvers ||
2290 ip6stat.ip6s_exthdrtoolong ||
2291 ip6stat.ip6s_sources_none ||
2292 ip6stat.ip6s_tooshort ||
2293 ip6stat.ip6s_cantforward ||
2294 ip6stat.ip6s_noroute))) {
2295 do_ip6_errors = CONFIG_BOOLEAN_YES;
2297 static RRDSET *st = NULL;
2298 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2299 *rd_in_hdr_errors = NULL, *rd_in_addr_errors = NULL, *rd_in_truncated_pkts = NULL,
2300 *rd_in_no_routes = NULL, *rd_out_no_routes = NULL;
2302 if (unlikely(!st)) {
2303 st = rrdset_create_localhost("ipv6",
2315 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2317 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2318 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2319 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2320 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2321 rd_in_truncated_pkts = rrddim_add(st, "InTruncatedPkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2322 rd_in_no_routes = rrddim_add(st, "InNoRoutes", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2323 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2327 rrddim_set_by_pointer(st, rd_in_discards, ip6stat.ip6s_toosmall);
2328 rrddim_set_by_pointer(st, rd_out_discards, ip6stat.ip6s_odropped);
2329 rrddim_set_by_pointer(st, rd_in_hdr_errors, ip6stat.ip6s_badoptions + ip6stat.ip6s_badvers +
2330 ip6stat.ip6s_exthdrtoolong);
2331 rrddim_set_by_pointer(st, rd_in_addr_errors, ip6stat.ip6s_sources_none);
2332 rrddim_set_by_pointer(st, rd_in_truncated_pkts, ip6stat.ip6s_tooshort);
2333 rrddim_set_by_pointer(st, rd_in_no_routes, ip6stat.ip6s_cantforward);
2334 rrddim_set_by_pointer(st, rd_out_no_routes, ip6stat.ip6s_noroute);
2339 error("DISABLED: net.inet6.ip6.stats module");
2346 // --------------------------------------------------------------------------------------------------------------------
2347 // net.inet6.icmp6.stats
2349 int do_net_inet6_icmp6_stats(int update_every, usec_t dt) {
2350 static int do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1,
2351 do_icmp6_neighbor = -1, do_icmp6_types = -1;
2353 if (unlikely(do_icmp6 == -1)) {
2354 do_icmp6 = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp",
2355 CONFIG_BOOLEAN_AUTO);
2356 do_icmp6_redir = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp redirects",
2357 CONFIG_BOOLEAN_AUTO);
2358 do_icmp6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp errors",
2359 CONFIG_BOOLEAN_AUTO);
2360 do_icmp6_echos = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp echos",
2361 CONFIG_BOOLEAN_AUTO);
2362 do_icmp6_router = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp router",
2363 CONFIG_BOOLEAN_AUTO);
2364 do_icmp6_neighbor = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp neighbor",
2365 CONFIG_BOOLEAN_AUTO);
2366 do_icmp6_types = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp types",
2367 CONFIG_BOOLEAN_AUTO);
2370 if (likely(do_icmp6 || do_icmp6_redir || do_icmp6_errors || do_icmp6_echos || do_icmp6_router || do_icmp6_neighbor || do_icmp6_types)) {
2371 static int mib[4] = {0, 0, 0, 0};
2372 struct icmp6stat icmp6stat;
2374 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.icmp6.stats", mib, icmp6stat))) {
2376 error("DISABLED: ipv6.icmp chart");
2378 error("DISABLED: ipv6.icmpredir chart");
2379 do_icmp6_errors = 0;
2380 error("DISABLED: ipv6.icmperrors chart");
2382 error("DISABLED: ipv6.icmpechos chart");
2383 do_icmp6_router = 0;
2384 error("DISABLED: ipv6.icmprouter chart");
2385 do_icmp6_neighbor = 0;
2386 error("DISABLED: ipv6.icmpneighbor chart");
2388 error("DISABLED: ipv6.icmptypes chart");
2389 error("DISABLED: net.inet6.icmp6.stats module");
2393 struct icmp6_total {
2396 } icmp6_total = {0, 0};
2398 for (i = 0; i <= ICMP6_MAXTYPE; i++) {
2399 icmp6_total.msgs_in += icmp6stat.icp6s_inhist[i];
2400 icmp6_total.msgs_out += icmp6stat.icp6s_outhist[i];
2402 icmp6_total.msgs_in += icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort;
2404 // --------------------------------------------------------------------
2406 if (do_icmp6 == CONFIG_BOOLEAN_YES || (do_icmp6 == CONFIG_BOOLEAN_AUTO && (icmp6_total.msgs_in || icmp6_total.msgs_out))) {
2407 do_icmp6 = CONFIG_BOOLEAN_YES;
2409 static RRDSET *st = NULL;
2410 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2412 if (unlikely(!st)) {
2413 st = rrdset_create_localhost("ipv6",
2418 "IPv6 ICMP Messages",
2425 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2426 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2430 rrddim_set_by_pointer(st, rd_received, icmp6_total.msgs_out);
2431 rrddim_set_by_pointer(st, rd_sent, icmp6_total.msgs_in);
2436 // --------------------------------------------------------------------
2438 if (do_icmp6_redir == CONFIG_BOOLEAN_YES || (do_icmp6_redir == CONFIG_BOOLEAN_AUTO && (icmp6stat.icp6s_inhist[ND_REDIRECT] || icmp6stat.icp6s_outhist[ND_REDIRECT]))) {
2439 do_icmp6_redir = CONFIG_BOOLEAN_YES;
2441 static RRDSET *st = NULL;
2442 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2444 if (unlikely(!st)) {
2445 st = rrdset_create_localhost("ipv6",
2450 "IPv6 ICMP Redirects",
2457 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2458 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2462 rrddim_set_by_pointer(st, rd_received, icmp6stat.icp6s_outhist[ND_REDIRECT]);
2463 rrddim_set_by_pointer(st, rd_sent, icmp6stat.icp6s_inhist[ND_REDIRECT]);
2467 // --------------------------------------------------------------------
2469 if (do_icmp6_errors == CONFIG_BOOLEAN_YES || (do_icmp6_errors == CONFIG_BOOLEAN_AUTO && (
2470 icmp6stat.icp6s_badcode ||
2471 icmp6stat.icp6s_badlen ||
2472 icmp6stat.icp6s_checksum ||
2473 icmp6stat.icp6s_tooshort ||
2474 icmp6stat.icp6s_error ||
2475 icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH] ||
2476 icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED] ||
2477 icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB] ||
2478 icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH] ||
2479 icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED] ||
2480 icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]))) {
2481 do_icmp6_errors = CONFIG_BOOLEAN_YES;
2483 static RRDSET *st = NULL;
2484 static RRDDIM *rd_in_errors = NULL, *rd_out_errors = NULL, *rd_in_csum_errors = NULL,
2485 *rd_in_dest_unreachs = NULL, *rd_in_pkt_too_bigs = NULL, *rd_in_time_excds = NULL,
2486 *rd_in_parm_problems = NULL, *rd_out_dest_unreachs = NULL, *rd_out_time_excds = NULL,
2487 *rd_out_parm_problems = NULL;
2489 if (unlikely(!st)) {
2490 st = rrdset_create_localhost("ipv6",
2501 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2502 rd_out_errors = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2503 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2504 rd_in_dest_unreachs = rrddim_add(st, "InDestUnreachs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2505 rd_in_pkt_too_bigs = rrddim_add(st, "InPktTooBigs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2506 rd_in_time_excds = rrddim_add(st, "InTimeExcds", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2507 rd_in_parm_problems = rrddim_add(st, "InParmProblems", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2508 rd_out_dest_unreachs = rrddim_add(st, "OutDestUnreachs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2509 rd_out_time_excds = rrddim_add(st, "OutTimeExcds", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2510 rd_out_parm_problems = rrddim_add(st, "OutParmProblems", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2514 rrddim_set_by_pointer(st, rd_in_errors, icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen +
2515 icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort);
2516 rrddim_set_by_pointer(st, rd_out_errors, icmp6stat.icp6s_error);
2517 rrddim_set_by_pointer(st, rd_in_csum_errors, icmp6stat.icp6s_checksum);
2518 rrddim_set_by_pointer(st, rd_in_dest_unreachs, icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH]);
2519 rrddim_set_by_pointer(st, rd_in_pkt_too_bigs, icmp6stat.icp6s_badlen);
2520 rrddim_set_by_pointer(st, rd_in_time_excds, icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED]);
2521 rrddim_set_by_pointer(st, rd_in_parm_problems, icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB]);
2522 rrddim_set_by_pointer(st, rd_out_dest_unreachs, icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH]);
2523 rrddim_set_by_pointer(st, rd_out_time_excds, icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED]);
2524 rrddim_set_by_pointer(st, rd_out_parm_problems, icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]);
2528 // --------------------------------------------------------------------
2530 if (do_icmp6_echos == CONFIG_BOOLEAN_YES || (do_icmp6_echos == CONFIG_BOOLEAN_AUTO && (
2531 icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST] ||
2532 icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST] ||
2533 icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY] ||
2534 icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]))) {
2535 do_icmp6_echos = CONFIG_BOOLEAN_YES;
2537 static RRDSET *st = NULL;
2538 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_replies = NULL, *rd_out_replies = NULL;
2540 if (unlikely(!st)) {
2541 st = rrdset_create_localhost("ipv6",
2553 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2554 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2555 rd_in_replies = rrddim_add(st, "InEchoReplies", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2556 rd_out_replies = rrddim_add(st, "OutEchoReplies", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2560 rrddim_set_by_pointer(st, rd_in, icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST]);
2561 rrddim_set_by_pointer(st, rd_out, icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST]);
2562 rrddim_set_by_pointer(st, rd_in_replies, icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY]);
2563 rrddim_set_by_pointer(st, rd_out_replies, icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]);
2567 // --------------------------------------------------------------------
2569 if (do_icmp6_router == CONFIG_BOOLEAN_YES || (do_icmp6_router == CONFIG_BOOLEAN_AUTO && (
2570 icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT] ||
2571 icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT] ||
2572 icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT] ||
2573 icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]))) {
2574 do_icmp6_router = CONFIG_BOOLEAN_YES;
2576 static RRDSET *st = NULL;
2577 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2578 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2580 if (unlikely(!st)) {
2581 st = rrdset_create_localhost("ipv6",
2586 "IPv6 Router Messages",
2593 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2594 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2595 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2596 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2600 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT]);
2601 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT]);
2602 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT]);
2603 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]);
2607 // --------------------------------------------------------------------
2609 if (do_icmp6_neighbor == CONFIG_BOOLEAN_YES || (do_icmp6_neighbor == CONFIG_BOOLEAN_AUTO && (
2610 icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT] ||
2611 icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT] ||
2612 icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT] ||
2613 icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]))) {
2614 do_icmp6_neighbor = CONFIG_BOOLEAN_YES;
2616 static RRDSET *st = NULL;
2617 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2618 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2620 if (unlikely(!st)) {
2621 st = rrdset_create_localhost("ipv6",
2626 "IPv6 Neighbor Messages",
2633 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2634 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2635 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2636 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2640 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]);
2641 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]);
2642 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT]);
2643 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]);
2647 // --------------------------------------------------------------------
2649 if (do_icmp6_types == CONFIG_BOOLEAN_YES || (do_icmp6_types == CONFIG_BOOLEAN_AUTO && (
2650 icmp6stat.icp6s_inhist[1] ||
2651 icmp6stat.icp6s_inhist[128] ||
2652 icmp6stat.icp6s_inhist[129] ||
2653 icmp6stat.icp6s_inhist[136] ||
2654 icmp6stat.icp6s_outhist[1] ||
2655 icmp6stat.icp6s_outhist[128] ||
2656 icmp6stat.icp6s_outhist[129] ||
2657 icmp6stat.icp6s_outhist[133] ||
2658 icmp6stat.icp6s_outhist[135] ||
2659 icmp6stat.icp6s_outhist[136]))) {
2660 do_icmp6_types = CONFIG_BOOLEAN_YES;
2662 static RRDSET *st = NULL;
2663 static RRDDIM *rd_in_1 = NULL, *rd_in_128 = NULL, *rd_in_129 = NULL, *rd_in_136 = NULL,
2664 *rd_out_1 = NULL, *rd_out_128 = NULL, *rd_out_129 = NULL, *rd_out_133 = NULL,
2665 *rd_out_135 = NULL, *rd_out_143 = NULL;
2667 if (unlikely(!st)) {
2668 st = rrdset_create_localhost("ipv6",
2680 rd_in_1 = rrddim_add(st, "InType1", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2681 rd_in_128 = rrddim_add(st, "InType128", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2682 rd_in_129 = rrddim_add(st, "InType129", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2683 rd_in_136 = rrddim_add(st, "InType136", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2684 rd_out_1 = rrddim_add(st, "OutType1", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2685 rd_out_128 = rrddim_add(st, "OutType128", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2686 rd_out_129 = rrddim_add(st, "OutType129", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2687 rd_out_133 = rrddim_add(st, "OutType133", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2688 rd_out_135 = rrddim_add(st, "OutType135", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2689 rd_out_143 = rrddim_add(st, "OutType143", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2693 rrddim_set_by_pointer(st, rd_in_1, icmp6stat.icp6s_inhist[1]);
2694 rrddim_set_by_pointer(st, rd_in_128, icmp6stat.icp6s_inhist[128]);
2695 rrddim_set_by_pointer(st, rd_in_129, icmp6stat.icp6s_inhist[129]);
2696 rrddim_set_by_pointer(st, rd_in_136, icmp6stat.icp6s_inhist[136]);
2697 rrddim_set_by_pointer(st, rd_out_1, icmp6stat.icp6s_outhist[1]);
2698 rrddim_set_by_pointer(st, rd_out_128, icmp6stat.icp6s_outhist[128]);
2699 rrddim_set_by_pointer(st, rd_out_129, icmp6stat.icp6s_outhist[129]);
2700 rrddim_set_by_pointer(st, rd_out_133, icmp6stat.icp6s_outhist[133]);
2701 rrddim_set_by_pointer(st, rd_out_135, icmp6stat.icp6s_outhist[135]);
2702 rrddim_set_by_pointer(st, rd_out_143, icmp6stat.icp6s_outhist[143]);
2707 error("DISABLED: net.inet6.icmp6.stats module");
2714 // --------------------------------------------------------------------------------------------------------------------
2717 int do_getmntinfo(int update_every, usec_t dt) {
2719 #define DELAULT_EXLUDED_PATHS "/proc/*"
2720 // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
2721 #define DEFAULT_EXCLUDED_FILESYSTEMS "autofs procfs subfs devfs none"
2722 #define CONFIG_SECTION_DISKSPACE "plugin:freebsd:getmntinfo"
2724 static int do_space = -1, do_inodes = -1;
2726 if (unlikely(do_space == -1)) {
2727 do_space = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2728 do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2731 if (likely(do_space || do_inodes)) {
2732 struct statfs *mntbuf;
2735 // there is no mount info in sysctl MIBs
2736 if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) {
2737 error("FREEBSD: getmntinfo() failed");
2739 error("DISABLED: disk_space.* charts");
2741 error("DISABLED: disk_inodes.* charts");
2742 error("DISABLED: getmntinfo module");
2745 // Data to be stored in DICTIONARY mount_points.
2746 // This DICTIONARY is used to lookup the settings of the mount point on each iteration.
2747 struct mount_point_metadata {
2751 size_t collected; // the number of times this has been collected
2754 RRDDIM *rd_space_used;
2755 RRDDIM *rd_space_avail;
2756 RRDDIM *rd_space_reserved;
2759 RRDDIM *rd_inodes_used;
2760 RRDDIM *rd_inodes_avail;
2762 static DICTIONARY *mount_points = NULL;
2763 static SIMPLE_PATTERN *excluded_mountpoints = NULL;
2764 static SIMPLE_PATTERN *excluded_filesystems = NULL;
2767 if(unlikely(!mount_points)) {
2769 excluded_mountpoints = simple_pattern_create(
2770 config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths",
2771 DELAULT_EXLUDED_PATHS),
2772 SIMPLE_PATTERN_EXACT
2775 excluded_filesystems = simple_pattern_create(
2776 config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on filesystems",
2777 DEFAULT_EXCLUDED_FILESYSTEMS),
2778 SIMPLE_PATTERN_EXACT
2781 mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
2784 for (i = 0; i < mntsize; i++) {
2786 char title[4096 + 1];
2787 int def_space, def_inodes, iter_space, iter_inodes;
2789 struct mount_point_metadata *m = dictionary_get(mount_points, mntbuf[i].f_mntonname);
2791 char var_name[4096 + 1];
2792 snprintfz(var_name, 4096, "plugin:freebsd:getmntinfo:%s", mntbuf[i].f_mntonname);
2794 def_space = do_space;
2795 def_inodes = do_space;
2797 if(unlikely(simple_pattern_matches(excluded_mountpoints, mntbuf[i].f_mntonname))) {
2798 def_space = CONFIG_BOOLEAN_NO;
2799 def_inodes = CONFIG_BOOLEAN_NO;
2802 if(unlikely(simple_pattern_matches(excluded_filesystems, mntbuf[i].f_fstypename))) {
2803 def_space = CONFIG_BOOLEAN_NO;
2804 def_inodes = CONFIG_BOOLEAN_NO;
2807 iter_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
2808 iter_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
2810 struct mount_point_metadata mp = {
2811 .do_space = iter_space,
2812 .do_inodes = iter_inodes,
2817 .rd_space_avail = NULL,
2818 .rd_space_used = NULL,
2819 .rd_space_reserved = NULL,
2822 .rd_inodes_avail = NULL,
2823 .rd_inodes_used = NULL,
2826 m = dictionary_set(mount_points, mntbuf[i].f_mntonname, &mp, sizeof(struct mount_point_metadata));
2829 if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
2832 if(unlikely(mntbuf[i].f_flags & MNT_RDONLY && !m->collected))
2835 // --------------------------------------------------------------------------
2839 if (m->do_space == CONFIG_BOOLEAN_YES || (m->do_space == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_blocks > 2))) {
2840 if (unlikely(!m->st_space)) {
2841 snprintfz(title, 4096, "Disk Space Usage for %s [%s]",
2842 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2843 m->st_space = rrdset_create_localhost("disk_space",
2844 mntbuf[i].f_mntonname,
2846 mntbuf[i].f_mntonname,
2855 m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL,
2856 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2857 m->rd_space_used = rrddim_add(m->st_space, "used", NULL,
2858 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2859 m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root",
2860 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2862 rrdset_next(m->st_space);
2864 rrddim_set_by_pointer(m->st_space, m->rd_space_avail, (collected_number) mntbuf[i].f_bavail);
2865 rrddim_set_by_pointer(m->st_space, m->rd_space_used, (collected_number) (mntbuf[i].f_blocks -
2866 mntbuf[i].f_bfree));
2867 rrddim_set_by_pointer(m->st_space, m->rd_space_reserved, (collected_number) (mntbuf[i].f_bfree -
2868 mntbuf[i].f_bavail));
2869 rrdset_done(m->st_space);
2874 // --------------------------------------------------------------------------
2876 if (m->do_inodes == CONFIG_BOOLEAN_YES || (m->do_inodes == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_files > 1))) {
2877 if (unlikely(!m->st_inodes)) {
2878 snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]",
2879 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2880 m->st_inodes = rrdset_create_localhost("disk_inodes",
2881 mntbuf[i].f_mntonname,
2883 mntbuf[i].f_mntonname,
2892 m->rd_inodes_avail = rrddim_add(m->st_inodes, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2893 m->rd_inodes_used = rrddim_add(m->st_inodes, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2895 rrdset_next(m->st_inodes);
2897 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_avail, (collected_number) mntbuf[i].f_ffree);
2898 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_used, (collected_number) (mntbuf[i].f_files -
2899 mntbuf[i].f_ffree));
2900 rrdset_done(m->st_inodes);
2905 if(likely(rendered))
2910 error("DISABLED: getmntinfo module");
2917 // --------------------------------------------------------------------------------------------------------------------
2920 int do_freebsd_sysctl_old(int update_every, usec_t dt) {
2921 static int do_disk_io = -1, do_bandwidth = -1;
2923 if (unlikely(do_disk_io == -1)) {
2924 do_disk_io = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
2925 do_bandwidth = config_get_boolean("plugin:freebsd:sysctl", "bandwidth", 1);
2932 // NEEDED BY: do_disk_io
2933 #define RRD_TYPE_DISK "disk"
2934 #define BINTIME_SCALE 5.42101086242752217003726400434970855712890625e-17 // this is 1000/2^64
2936 static void *devstat_data = NULL;
2937 struct devstat *dstat;
2938 char disk[DEVSTAT_NAME_LEN + MAX_INT_DIGITS + 1];
2940 collected_number duration_read_ms;
2941 collected_number duration_write_ms;
2942 collected_number busy_time_ms;
2945 collected_number bytes_read;
2946 collected_number bytes_write;
2947 collected_number operations_read;
2948 collected_number operations_write;
2949 collected_number duration_read_ms;
2950 collected_number duration_write_ms;
2951 collected_number busy_time_ms;
2954 // NEEDED BY: do_bandwidth
2955 #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
2956 struct ifaddrs *ifa, *ifap;
2962 // --------------------------------------------------------------------
2964 if (likely(do_disk_io)) {
2965 if (unlikely(GETSYSCTL_BY_NAME("kern.devstat.numdevs", numdevs))) {
2967 error("DISABLED: disk.io");
2969 devstat_data = reallocz(devstat_data, sizeof(long) + sizeof(struct devstat) * numdevs); // there is generation number before devstat structures
2971 getsysctl_by_name("kern.devstat.all", devstat_data, sizeof(long) + sizeof(struct devstat) * numdevs))) {
2973 error("DISABLED: disk.io");
2975 dstat = devstat_data + sizeof(long); // skip generation number
2976 collected_number total_disk_kbytes_read = 0;
2977 collected_number total_disk_kbytes_write = 0;
2979 for (i = 0; i < numdevs; i++) {
2980 if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
2981 sprintf(disk, "%s%d", dstat[i].device_name, dstat[i].unit_number);
2983 // --------------------------------------------------------------------
2985 st = rrdset_find_bytype_localhost(RRD_TYPE_DISK, disk);
2986 if (unlikely(!st)) {
2987 st = rrdset_create_localhost(RRD_TYPE_DISK, disk, NULL, disk, "disk.io", "Disk I/O Bandwidth", "kilobytes/s", 2000, update_every, RRDSET_TYPE_AREA);
2989 rrddim_add(st, "reads", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL);
2990 rrddim_add(st, "writes", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL);
2992 else rrdset_next(st);
2994 total_disk_kbytes_read += dstat[i].bytes[DEVSTAT_READ]/KILO_FACTOR;
2995 total_disk_kbytes_write += dstat[i].bytes[DEVSTAT_WRITE]/KILO_FACTOR;
2996 prev_dstat.bytes_read = rrddim_set(st, "reads", dstat[i].bytes[DEVSTAT_READ]);
2997 prev_dstat.bytes_write = rrddim_set(st, "writes", dstat[i].bytes[DEVSTAT_WRITE]);
3000 // --------------------------------------------------------------------
3002 st = rrdset_find_bytype_localhost("disk_ops", disk);
3003 if (unlikely(!st)) {
3004 st = rrdset_create_localhost("disk_ops", disk, NULL, disk, "disk.ops", "Disk Completed I/O Operations", "operations/s", 2001, update_every, RRDSET_TYPE_LINE);
3005 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3007 rrddim_add(st, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3008 rrddim_add(st, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3010 else rrdset_next(st);
3012 prev_dstat.operations_read = rrddim_set(st, "reads", dstat[i].operations[DEVSTAT_READ]);
3013 prev_dstat.operations_write = rrddim_set(st, "writes", dstat[i].operations[DEVSTAT_WRITE]);
3016 // --------------------------------------------------------------------
3018 st = rrdset_find_bytype_localhost("disk_qops", disk);
3019 if (unlikely(!st)) {
3020 st = rrdset_create_localhost("disk_qops", disk, NULL, disk, "disk.qops", "Disk Current I/O Operations", "operations", 2002, update_every, RRDSET_TYPE_LINE);
3021 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3023 rrddim_add(st, "operations", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3025 else rrdset_next(st);
3027 rrddim_set(st, "operations", dstat[i].start_count - dstat[i].end_count);
3030 // --------------------------------------------------------------------
3032 st = rrdset_find_bytype_localhost("disk_util", disk);
3033 if (unlikely(!st)) {
3034 st = rrdset_create_localhost("disk_util", disk, NULL, disk, "disk.util", "Disk Utilization Time", "% of time working", 2004, update_every, RRDSET_TYPE_AREA);
3035 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3037 rrddim_add(st, "utilization", NULL, 1, 10, RRD_ALGORITHM_INCREMENTAL);
3039 else rrdset_next(st);
3041 cur_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000 + dstat[i].busy_time.frac * BINTIME_SCALE;
3042 prev_dstat.busy_time_ms = rrddim_set(st, "utilization", cur_dstat.busy_time_ms);
3045 // --------------------------------------------------------------------
3047 st = rrdset_find_bytype_localhost("disk_iotime", disk);
3048 if (unlikely(!st)) {
3049 st = rrdset_create_localhost("disk_iotime", disk, NULL, disk, "disk.iotime", "Disk Total I/O Time", "milliseconds/s", 2022, update_every, RRDSET_TYPE_LINE);
3050 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3052 rrddim_add(st, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3053 rrddim_add(st, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3055 else rrdset_next(st);
3057 cur_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3058 cur_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3059 prev_dstat.duration_read_ms = rrddim_set(st, "reads", cur_dstat.duration_read_ms);
3060 prev_dstat.duration_write_ms = rrddim_set(st, "writes", cur_dstat.duration_write_ms);
3063 // --------------------------------------------------------------------
3064 // calculate differential charts
3065 // only if this is not the first time we run
3069 // --------------------------------------------------------------------
3071 st = rrdset_find_bytype_localhost("disk_await", disk);
3072 if (unlikely(!st)) {
3073 st = rrdset_create_localhost("disk_await", disk, NULL, disk, "disk.await", "Average Completed I/O Operation Time", "ms per operation", 2005, update_every, RRDSET_TYPE_LINE);
3074 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3076 rrddim_add(st, "reads", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3077 rrddim_add(st, "writes", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
3079 else rrdset_next(st);
3081 rrddim_set(st, "reads", (dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) ?
3082 (cur_dstat.duration_read_ms - prev_dstat.duration_read_ms) / (dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) : 0);
3083 rrddim_set(st, "writes", (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write) ?
3084 (cur_dstat.duration_write_ms - prev_dstat.duration_write_ms) / (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write) : 0);
3087 // --------------------------------------------------------------------
3089 st = rrdset_find_bytype_localhost("disk_avgsz", disk);
3090 if (unlikely(!st)) {
3091 st = rrdset_create_localhost("disk_avgsz", disk, NULL, disk, "disk.avgsz", "Average Completed I/O Operation Bandwidth", "kilobytes per operation", 2006, update_every, RRDSET_TYPE_AREA);
3092 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3094 rrddim_add(st, "reads", NULL, 1, 1024, RRD_ALGORITHM_ABSOLUTE);
3095 rrddim_add(st, "writes", NULL, -1, 1024, RRD_ALGORITHM_ABSOLUTE);
3097 else rrdset_next(st);
3099 rrddim_set(st, "reads", (dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) ?
3100 (dstat[i].bytes[DEVSTAT_READ] - prev_dstat.bytes_read) / (dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) : 0);
3101 rrddim_set(st, "writes", (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write) ?
3102 (dstat[i].bytes[DEVSTAT_WRITE] - prev_dstat.bytes_write) / (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write) : 0);
3105 // --------------------------------------------------------------------
3107 st = rrdset_find_bytype_localhost("disk_svctm", disk);
3108 if (unlikely(!st)) {
3109 st = rrdset_create_localhost("disk_svctm", disk, NULL, disk, "disk.svctm", "Average Service Time", "ms per operation", 2007, update_every, RRDSET_TYPE_LINE);
3110 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3112 rrddim_add(st, "svctm", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3114 else rrdset_next(st);
3116 rrddim_set(st, "svctm", ((dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) + (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write)) ?
3117 (cur_dstat.busy_time_ms - prev_dstat.busy_time_ms) / ((dstat[i].operations[DEVSTAT_READ] - prev_dstat.operations_read) + (dstat[i].operations[DEVSTAT_WRITE] - prev_dstat.operations_write)) : 0);
3123 // --------------------------------------------------------------------
3125 st = rrdset_find_bytype_localhost("system", "io");
3126 if (unlikely(!st)) {
3127 st = rrdset_create_localhost("system", "io", NULL, "disk", NULL, "Disk I/O", "kilobytes/s", 150, update_every, RRDSET_TYPE_AREA);
3128 rrddim_add(st, "in", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3129 rrddim_add(st, "out", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3131 else rrdset_next(st);
3133 rrddim_set(st, "in", total_disk_kbytes_read);
3134 rrddim_set(st, "out", total_disk_kbytes_write);
3140 // --------------------------------------------------------------------
3142 if (likely(do_bandwidth)) {
3143 if (unlikely(getifaddrs(&ifap))) {
3144 error("FREEBSD: getifaddrs()");
3146 error("DISABLED: system.ipv4");
3148 iftot.ift_ibytes = iftot.ift_obytes = 0;
3149 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3150 if (ifa->ifa_addr->sa_family != AF_INET)
3152 iftot.ift_ibytes += IFA_DATA(ibytes);
3153 iftot.ift_obytes += IFA_DATA(obytes);
3156 st = rrdset_find_localhost("system.ipv4");
3157 if (unlikely(!st)) {
3158 st = rrdset_create_localhost("system", "ipv4", NULL, "network", NULL, "IPv4 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
3160 rrddim_add(st, "InOctets", "received", 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3161 rrddim_add(st, "OutOctets", "sent", -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3163 else rrdset_next(st);
3165 rrddim_set(st, "InOctets", iftot.ift_ibytes);
3166 rrddim_set(st, "OutOctets", iftot.ift_obytes);
3169 // --------------------------------------------------------------------
3171 iftot.ift_ibytes = iftot.ift_obytes = 0;
3172 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3173 if (ifa->ifa_addr->sa_family != AF_INET6)
3175 iftot.ift_ibytes += IFA_DATA(ibytes);
3176 iftot.ift_obytes += IFA_DATA(obytes);
3179 st = rrdset_find_localhost("system.ipv6");
3180 if (unlikely(!st)) {
3181 st = rrdset_create_localhost("system", "ipv6", NULL, "network", NULL, "IPv6 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
3183 rrddim_add(st, "received", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3184 rrddim_add(st, "sent", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3186 else rrdset_next(st);
3188 rrddim_set(st, "sent", iftot.ift_obytes);
3189 rrddim_set(st, "received", iftot.ift_ibytes);
3192 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3193 if (ifa->ifa_addr->sa_family != AF_LINK)
3196 // --------------------------------------------------------------------
3198 st = rrdset_find_bytype_localhost("net", ifa->ifa_name);
3199 if (unlikely(!st)) {
3200 st = rrdset_create_localhost("net", ifa->ifa_name, NULL, ifa->ifa_name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
3202 rrddim_add(st, "received", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL);
3203 rrddim_add(st, "sent", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL);
3205 else rrdset_next(st);
3207 rrddim_set(st, "received", IFA_DATA(ibytes));
3208 rrddim_set(st, "sent", IFA_DATA(obytes));
3211 // --------------------------------------------------------------------
3213 st = rrdset_find_bytype_localhost("net_packets", ifa->ifa_name);
3214 if (unlikely(!st)) {
3215 st = rrdset_create_localhost("net_packets", ifa->ifa_name, NULL, ifa->ifa_name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
3216 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3218 rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3219 rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3220 rrddim_add(st, "multicast_received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3221 rrddim_add(st, "multicast_sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3223 else rrdset_next(st);
3225 rrddim_set(st, "received", IFA_DATA(ipackets));
3226 rrddim_set(st, "sent", IFA_DATA(opackets));
3227 rrddim_set(st, "multicast_received", IFA_DATA(imcasts));
3228 rrddim_set(st, "multicast_sent", IFA_DATA(omcasts));
3231 // --------------------------------------------------------------------
3233 st = rrdset_find_bytype_localhost("net_errors", ifa->ifa_name);
3234 if (unlikely(!st)) {
3235 st = rrdset_create_localhost("net_errors", ifa->ifa_name, NULL, ifa->ifa_name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
3236 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3238 rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3239 rrddim_add(st, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3241 else rrdset_next(st);
3243 rrddim_set(st, "inbound", IFA_DATA(ierrors));
3244 rrddim_set(st, "outbound", IFA_DATA(oerrors));
3247 // --------------------------------------------------------------------
3249 st = rrdset_find_bytype_localhost("net_drops", ifa->ifa_name);
3250 if (unlikely(!st)) {
3251 st = rrdset_create_localhost("net_drops", ifa->ifa_name, NULL, ifa->ifa_name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
3252 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3254 rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3255 #if __FreeBSD__ >= 11
3256 rrddim_add(st, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3259 else rrdset_next(st);
3261 rrddim_set(st, "inbound", IFA_DATA(iqdrops));
3262 #if __FreeBSD__ >= 11
3263 rrddim_set(st, "outbound", IFA_DATA(oqdrops));
3267 // --------------------------------------------------------------------
3269 st = rrdset_find_bytype_localhost("net_events", ifa->ifa_name);
3270 if (unlikely(!st)) {
3271 st = rrdset_create_localhost("net_events", ifa->ifa_name, NULL, ifa->ifa_name, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
3272 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
3274 rrddim_add(st, "frames", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3275 rrddim_add(st, "collisions", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3276 rrddim_add(st, "carrier", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3278 else rrdset_next(st);
3280 rrddim_set(st, "collisions", IFA_DATA(collisions));