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) {
126 static int do_all_processes = -1, do_processes = -1, do_committed = -1;
128 if (unlikely(do_all_processes == -1)) {
129 do_all_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "enable total processes", 1);
130 do_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "processes running", 1);
131 do_committed = config_get_boolean("plugin:freebsd:vm.vmtotal", "committed memory", 1);
134 if (likely(do_all_processes | do_processes | do_committed)) {
135 static int mib[2] = {0, 0};
136 struct vmtotal vmtotal_data;
138 if (unlikely(GETSYSCTL_SIMPLE("vm.vmtotal", mib, vmtotal_data))) {
139 do_all_processes = 0;
140 error("DISABLED: system.active_processes chart");
142 error("DISABLED: system.processes chart");
144 error("DISABLED: mem.committed chart");
145 error("DISABLED: vm.vmtotal module");
149 // --------------------------------------------------------------------
151 if (likely(do_all_processes)) {
152 static RRDSET *st = NULL;
153 static RRDDIM *rd = NULL;
156 st = rrdset_create_localhost("system",
161 "System Active Processes",
167 rd = rrddim_add(st, "active", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
169 else rrdset_next(st);
171 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));
175 // --------------------------------------------------------------------
177 if (likely(do_processes)) {
178 static RRDSET *st = NULL;
179 static RRDDIM *rd_running = NULL, *rd_blocked = NULL;
182 st = rrdset_create_localhost("system",
194 rd_running = rrddim_add(st, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
195 rd_blocked = rrddim_add(st, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
197 else rrdset_next(st);
199 rrddim_set_by_pointer(st, rd_running, vmtotal_data.t_rq);
200 rrddim_set_by_pointer(st, rd_blocked, (vmtotal_data.t_dw + vmtotal_data.t_pw));
204 // --------------------------------------------------------------------
206 if (likely(do_committed)) {
207 static RRDSET *st = NULL;
208 static RRDDIM *rd = NULL;
211 st = rrdset_create_localhost("mem",
216 "Committed (Allocated) Memory",
222 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
224 rd = rrddim_add(st, "Committed_AS", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
226 else rrdset_next(st);
228 rrddim_set_by_pointer(st, rd, vmtotal_data.t_rm);
233 error("DISABLED: vm.vmtotal module");
240 // --------------------------------------------------------------------------------------------------------------------
243 int do_kern_cp_time(int update_every, usec_t dt) {
246 if (unlikely(CPUSTATES != 5)) {
247 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
248 error("DISABLED: system.cpu chart");
249 error("DISABLED: kern.cp_time module");
252 static int mib[2] = {0, 0};
253 long cp_time[CPUSTATES];
255 if (unlikely(GETSYSCTL_SIMPLE("kern.cp_time", mib, cp_time))) {
256 error("DISABLED: system.cpu chart");
257 error("DISABLED: kern.cp_time module");
261 // --------------------------------------------------------------------
263 static RRDSET *st = NULL;
264 static RRDDIM *rd_nice = NULL, *rd_system = NULL, *rd_user = NULL, *rd_interrupt = NULL, *rd_idle = NULL;
267 st = rrdset_create_localhost("system",
272 "Total CPU utilization",
278 rd_nice = rrddim_add(st, "nice", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
279 rd_system = rrddim_add(st, "system", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
280 rd_user = rrddim_add(st, "user", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
281 rd_interrupt = rrddim_add(st, "interrupt", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
282 rd_idle = rrddim_add(st, "idle", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
283 rrddim_hide(st, "idle");
285 else rrdset_next(st);
287 rrddim_set_by_pointer(st, rd_nice, cp_time[1]);
288 rrddim_set_by_pointer(st, rd_system, cp_time[2]);
289 rrddim_set_by_pointer(st, rd_user, cp_time[0]);
290 rrddim_set_by_pointer(st, rd_interrupt, cp_time[3]);
291 rrddim_set_by_pointer(st, rd_idle, cp_time[4]);
299 // --------------------------------------------------------------------------------------------------------------------
302 int do_kern_cp_times(int update_every, usec_t dt) {
305 if (unlikely(CPUSTATES != 5)) {
306 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
307 error("DISABLED: cpu.cpuXX charts");
308 error("DISABLED: kern.cp_times module");
311 static int mib[2] = {0, 0};
312 long cp_time[CPUSTATES];
313 static long *pcpu_cp_time = NULL;
315 pcpu_cp_time = reallocz(pcpu_cp_time, sizeof(cp_time) * number_of_cpus);
316 if (unlikely(GETSYSCTL_WSIZE("kern.cp_times", mib, pcpu_cp_time, sizeof(cp_time) * number_of_cpus))) {
317 error("DISABLED: cpu.cpuXX charts");
318 error("DISABLED: kern.cp_times module");
322 // --------------------------------------------------------------------
325 static struct cpu_chart {
326 char cpuid[MAX_INT_DIGITS + 4];
331 RRDDIM *rd_interrupt;
333 } *all_cpu_charts = NULL;
334 static int old_number_of_cpus = 0;
336 if(unlikely(number_of_cpus > old_number_of_cpus)) {
337 all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus);
338 memset(&all_cpu_charts[old_number_of_cpus], 0, sizeof(struct cpu_chart) * (number_of_cpus - old_number_of_cpus));
339 old_number_of_cpus = number_of_cpus;
342 for (i = 0; i < number_of_cpus; i++) {
343 if (unlikely(!all_cpu_charts[i].st)) {
344 snprintfz(all_cpu_charts[i].cpuid, MAX_INT_DIGITS, "cpu%d", i);
345 all_cpu_charts[i].st = rrdset_create_localhost("cpu",
346 all_cpu_charts[i].cpuid,
357 all_cpu_charts[i].rd_nice = rrddim_add(all_cpu_charts[i].st, "nice", NULL, 1, 1,
358 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
359 all_cpu_charts[i].rd_system = rrddim_add(all_cpu_charts[i].st, "system", NULL, 1, 1,
360 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
361 all_cpu_charts[i].rd_user = rrddim_add(all_cpu_charts[i].st, "user", NULL, 1, 1,
362 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
363 all_cpu_charts[i].rd_interrupt = rrddim_add(all_cpu_charts[i].st, "interrupt", NULL, 1, 1,
364 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
365 all_cpu_charts[i].rd_idle = rrddim_add(all_cpu_charts[i].st, "idle", NULL, 1, 1,
366 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
367 rrddim_hide(all_cpu_charts[i].st, "idle");
368 } else rrdset_next(all_cpu_charts[i].st);
370 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_nice, pcpu_cp_time[i * 5 + 1]);
371 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_system, pcpu_cp_time[i * 5 + 2]);
372 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_user, pcpu_cp_time[i * 5 + 0]);
373 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_interrupt, pcpu_cp_time[i * 5 + 3]);
374 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_idle, pcpu_cp_time[i * 5 + 4]);
375 rrdset_done(all_cpu_charts[i].st);
383 // --------------------------------------------------------------------------------------------------------------------
386 int do_hw_intcnt(int update_every, usec_t dt) {
388 static int mib_hw_intrcnt[2] = {0, 0};
389 size_t intrcnt_size = sizeof(mib_hw_intrcnt);
392 if (unlikely(GETSYSCTL_SIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt_size))) {
393 error("DISABLED: system.intr chart");
394 error("DISABLED: system.interrupts chart");
395 error("DISABLED: hw.intrcnt module");
398 unsigned long nintr = 0;
399 static unsigned long *intrcnt = NULL;
400 unsigned long long totalintr = 0;
402 nintr = intrcnt_size / sizeof(u_long);
403 intrcnt = reallocz(intrcnt, nintr * sizeof(u_long));
404 if (unlikely(GETSYSCTL_WSIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt, nintr * sizeof(u_long)))) {
405 error("DISABLED: system.intr chart");
406 error("DISABLED: system.interrupts chart");
407 error("DISABLED: hw.intrcnt module");
410 for (i = 0; i < nintr; i++)
411 totalintr += intrcnt[i];
413 // --------------------------------------------------------------------
415 static RRDSET *st_intr = NULL;
416 static RRDDIM *rd_intr = NULL;
418 if (unlikely(!st_intr)) {
419 st_intr = rrdset_create_localhost("system",
424 "Total Hardware Interrupts",
430 rrdset_flag_set(st_intr, RRDSET_FLAG_DETAIL);
432 rd_intr = rrddim_add(st_intr, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
434 rrdset_next(st_intr);
436 rrddim_set_by_pointer(st_intr, rd_intr, totalintr);
437 rrdset_done(st_intr);
439 // --------------------------------------------------------------------
442 static int mib_hw_intrnames[2] = {0, 0};
443 static char *intrnames = NULL;
445 size = nintr * (MAXCOMLEN + 1);
446 intrnames = reallocz(intrnames, size);
447 if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) {
448 error("DISABLED: system.intr chart");
449 error("DISABLED: system.interrupts chart");
450 error("DISABLED: hw.intrcnt module");
454 // --------------------------------------------------------------------
456 static RRDSET *st_interrupts = NULL;
457 RRDDIM *rd_interrupts = NULL;
460 if (unlikely(!st_interrupts))
461 st_interrupts = rrdset_create_localhost("system",
473 rrdset_next(st_interrupts);
475 for (i = 0; i < nintr; i++) {
476 p = intrnames + i * (MAXCOMLEN + 1);
477 if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
478 rd_interrupts = rrddim_find(st_interrupts, p);
479 if (unlikely(!rd_interrupts))
480 rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
481 rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
484 rrdset_done(st_interrupts);
492 // --------------------------------------------------------------------------------------------------------------------
493 // vm.stats.sys.v_intr
495 int do_vm_stats_sys_v_intr(int update_every, usec_t dt) {
497 static int mib[4] = {0, 0, 0, 0};
500 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_intr", mib, int_number))) {
501 error("DISABLED: system.dev_intr chart");
502 error("DISABLED: vm.stats.sys.v_intr module");
506 // --------------------------------------------------------------------
508 static RRDSET *st = NULL;
509 static RRDDIM *rd = NULL;
512 st = rrdset_create_localhost("system",
524 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
526 else rrdset_next(st);
528 rrddim_set_by_pointer(st, rd, int_number);
535 // --------------------------------------------------------------------------------------------------------------------
536 // vm.stats.sys.v_soft
538 int do_vm_stats_sys_v_soft(int update_every, usec_t dt) {
540 static int mib[4] = {0, 0, 0, 0};
541 u_int soft_intr_number;
543 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_soft", mib, soft_intr_number))) {
544 error("DISABLED: system.dev_intr chart");
545 error("DISABLED: vm.stats.sys.v_soft module");
549 // --------------------------------------------------------------------
551 static RRDSET *st = NULL;
552 static RRDDIM *rd = NULL;
555 st = rrdset_create_localhost("system",
560 "Software Interrupts",
567 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
569 else rrdset_next(st);
571 rrddim_set_by_pointer(st, rd, soft_intr_number);
578 // --------------------------------------------------------------------------------------------------------------------
579 // vm.stats.sys.v_swtch
581 int do_vm_stats_sys_v_swtch(int update_every, usec_t dt) {
583 static int mib[4] = {0, 0, 0, 0};
586 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_swtch", mib, ctxt_number))) {
587 error("DISABLED: system.ctxt chart");
588 error("DISABLED: vm.stats.sys.v_swtch module");
592 // --------------------------------------------------------------------
594 static RRDSET *st = NULL;
595 static RRDDIM *rd = NULL;
598 st = rrdset_create_localhost("system",
603 "CPU Context Switches",
604 "context switches/s",
610 rd = rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
612 else rrdset_next(st);
614 rrddim_set_by_pointer(st, rd, ctxt_number);
621 // --------------------------------------------------------------------------------------------------------------------
622 // vm.stats.vm.v_forks
624 int do_vm_stats_sys_v_forks(int update_every, usec_t dt) {
626 static int mib[4] = {0, 0, 0, 0};
629 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_forks", mib, forks_number))) {
630 error("DISABLED: system.forks chart");
631 error("DISABLED: vm.stats.sys.v_swtch module");
635 // --------------------------------------------------------------------
637 static RRDSET *st = NULL;
638 static RRDDIM *rd = NULL;
641 st = rrdset_create_localhost("system",
653 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
655 rd = rrddim_add(st, "started", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
657 else rrdset_next(st);
659 rrddim_set_by_pointer(st, rd, forks_number);
666 // --------------------------------------------------------------------------------------------------------------------
669 int do_vm_swap_info(int update_every, usec_t dt) {
671 static int mib[3] = {0, 0, 0};
673 if (unlikely(getsysctl_mib("vm.swap_info", mib, 2))) {
674 error("DISABLED: system.swap chart");
675 error("DISABLED: vm.swap_info module");
681 collected_number bytes_used;
682 collected_number bytes_total;
683 } total_xsw = {0, 0};
690 if (unlikely(sysctl(mib, 3, &xsw, &size, NULL, 0) == -1 )) {
691 if (unlikely(errno != ENOENT)) {
692 error("FREEBSD: sysctl(%s...) failed: %s", "vm.swap_info", strerror(errno));
693 error("DISABLED: system.swap chart");
694 error("DISABLED: vm.swap_info module");
697 if (unlikely(size != sizeof(xsw))) {
698 error("FREEBSD: sysctl(%s...) expected %lu, got %lu", "vm.swap_info", (unsigned long)sizeof(xsw), (unsigned long)size);
699 error("DISABLED: system.swap chart");
700 error("DISABLED: vm.swap_info module");
705 total_xsw.bytes_used += xsw.xsw_used;
706 total_xsw.bytes_total += xsw.xsw_nblks;
709 // --------------------------------------------------------------------
711 static RRDSET *st = NULL;
712 static RRDDIM *rd_free = NULL, *rd_used = NULL;
715 st = rrdset_create_localhost("system",
727 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
729 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
730 rd_used = rrddim_add(st, "used", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
732 else rrdset_next(st);
734 rrddim_set_by_pointer(st, rd_free, total_xsw.bytes_total - total_xsw.bytes_used);
735 rrddim_set_by_pointer(st, rd_used, total_xsw.bytes_used);
742 // --------------------------------------------------------------------------------------------------------------------
745 int do_system_ram(int update_every, usec_t dt) {
747 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},
748 mib_cache_count[4] = {0, 0, 0, 0}, mib_vfs_bufspace[2] = {0, 0}, mib_free_count[4] = {0, 0, 0, 0};
749 struct vmmeter vmmeter_data;
750 int vfs_bufspace_count;
752 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_active_count", mib_active_count, vmmeter_data.v_active_count) ||
753 GETSYSCTL_SIMPLE("vm.stats.vm.v_inactive_count", mib_inactive_count, vmmeter_data.v_inactive_count) ||
754 GETSYSCTL_SIMPLE("vm.stats.vm.v_wire_count", mib_wire_count, vmmeter_data.v_wire_count) ||
755 #if __FreeBSD_version < 1200016
756 GETSYSCTL_SIMPLE("vm.stats.vm.v_cache_count", mib_cache_count, vmmeter_data.v_cache_count) ||
758 GETSYSCTL_SIMPLE("vfs.bufspace", mib_vfs_bufspace, vfs_bufspace_count) ||
759 GETSYSCTL_SIMPLE("vm.stats.vm.v_free_count", mib_free_count, vmmeter_data.v_free_count))) {
760 error("DISABLED: system.ram chart");
761 error("DISABLED: System.ram module");
765 // --------------------------------------------------------------------
767 static RRDSET *st = NULL;
768 static RRDDIM *rd_free = NULL, *rd_active = NULL, *rd_inactive = NULL,
769 *rd_wired = NULL, *rd_cache = NULL, *rd_buffers = NULL;
771 st = rrdset_find_localhost("system.ram");
773 st = rrdset_create_localhost("system",
785 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
786 rd_active = rrddim_add(st, "active", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
787 rd_inactive = rrddim_add(st, "inactive", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
788 rd_wired = rrddim_add(st, "wired", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
789 #if __FreeBSD_version < 1200016
790 rd_cache = rrddim_add(st, "cache", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
792 rd_buffers = rrddim_add(st, "buffers", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
794 else rrdset_next(st);
796 rrddim_set_by_pointer(st, rd_free, vmmeter_data.v_free_count);
797 rrddim_set_by_pointer(st, rd_active, vmmeter_data.v_active_count);
798 rrddim_set_by_pointer(st, rd_inactive, vmmeter_data.v_inactive_count);
799 rrddim_set_by_pointer(st, rd_wired, vmmeter_data.v_wire_count);
800 #if __FreeBSD_version < 1200016
801 rrddim_set_by_pointer(st, rd_cache, vmmeter_data.v_cache_count);
803 rrddim_set_by_pointer(st, rd_buffers, vfs_bufspace_count);
810 // --------------------------------------------------------------------------------------------------------------------
811 // vm.stats.vm.v_swappgs
813 int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt) {
815 static int mib_swappgsin[4] = {0, 0, 0, 0}, mib_swappgsout[4] = {0, 0, 0, 0};
816 struct vmmeter vmmeter_data;
818 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsin", mib_swappgsin, vmmeter_data.v_swappgsin) ||
819 GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsout", mib_swappgsout, vmmeter_data.v_swappgsout))) {
820 error("DISABLED: system.swapio chart");
821 error("DISABLED: vm.stats.vm.v_swappgs module");
825 // --------------------------------------------------------------------
827 static RRDSET *st = NULL;
828 static RRDDIM *rd_in = NULL, *rd_out = NULL;
831 st = rrdset_create_localhost("system",
843 rd_in = rrddim_add(st, "in", NULL, system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
844 rd_out = rrddim_add(st, "out", NULL, -system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
846 else rrdset_next(st);
848 rrddim_set_by_pointer(st, rd_in, vmmeter_data.v_swappgsin);
849 rrddim_set_by_pointer(st, rd_out, vmmeter_data.v_swappgsout);
856 // --------------------------------------------------------------------------------------------------------------------
857 // vm.stats.vm.v_pgfaults
859 int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt) {
861 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},
862 mib_cow_optim[4] = {0, 0, 0, 0}, mib_intrans[4] = {0, 0, 0, 0};
863 struct vmmeter vmmeter_data;
865 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_vm_faults", mib_vm_faults, vmmeter_data.v_vm_faults) ||
866 GETSYSCTL_SIMPLE("vm.stats.vm.v_io_faults", mib_io_faults, vmmeter_data.v_io_faults) ||
867 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_faults", mib_cow_faults, vmmeter_data.v_cow_faults) ||
868 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_optim", mib_cow_optim, vmmeter_data.v_cow_optim) ||
869 GETSYSCTL_SIMPLE("vm.stats.vm.v_intrans", mib_intrans, vmmeter_data.v_intrans))) {
870 error("DISABLED: mem.pgfaults chart");
871 error("DISABLED: vm.stats.vm.v_pgfaults module");
875 // --------------------------------------------------------------------
877 static RRDSET *st = NULL;
878 static RRDDIM *rd_memory = NULL, *rd_io_requiring = NULL, *rd_cow = NULL,
879 *rd_cow_optimized = NULL, *rd_in_transit = NULL;
882 st = rrdset_create_localhost("mem",
887 "Memory Page Faults",
894 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
896 rd_memory = rrddim_add(st, "memory", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
897 rd_io_requiring = rrddim_add(st, "io_requiring", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
898 rd_cow = rrddim_add(st, "cow", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
899 rd_cow_optimized = rrddim_add(st, "cow_optimized", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
900 rd_in_transit = rrddim_add(st, "in_transit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
902 else rrdset_next(st);
904 rrddim_set_by_pointer(st, rd_memory, vmmeter_data.v_vm_faults);
905 rrddim_set_by_pointer(st, rd_io_requiring, vmmeter_data.v_io_faults);
906 rrddim_set_by_pointer(st, rd_cow, vmmeter_data.v_cow_faults);
907 rrddim_set_by_pointer(st, rd_cow_optimized, vmmeter_data.v_cow_optim);
908 rrddim_set_by_pointer(st, rd_in_transit, vmmeter_data.v_intrans);
915 // --------------------------------------------------------------------------------------------------------------------
918 int do_kern_ipc_sem(int update_every, usec_t dt) {
920 static int mib_semmni[3] = {0, 0, 0}, mib_sema[3] = {0, 0, 0};
923 collected_number sets;
924 collected_number semaphores;
925 } ipc_sem = {0, 0, 0};
927 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.semmni", mib_semmni, ipc_sem.semmni))) {
928 error("DISABLED: system.ipc_semaphores chart");
929 error("DISABLED: system.ipc_semaphore_arrays chart");
930 error("DISABLED: kern.ipc.sem module");
933 static struct semid_kernel *ipc_sem_data = NULL;
935 ipc_sem_data = reallocz(ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni);
936 if (unlikely(GETSYSCTL_WSIZE("kern.ipc.sema", mib_sema, ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni))) {
937 error("DISABLED: system.ipc_semaphores chart");
938 error("DISABLED: system.ipc_semaphore_arrays chart");
939 error("DISABLED: kern.ipc.sem module");
944 for (i = 0; i < ipc_sem.semmni; i++) {
945 if (unlikely(ipc_sem_data[i].u.sem_perm.mode & SEM_ALLOC)) {
947 ipc_sem.semaphores += ipc_sem_data[i].u.sem_nsems;
951 // --------------------------------------------------------------------
953 static RRDSET *st_semaphores = NULL, *st_semaphore_arrays = NULL;
954 static RRDDIM *rd_semaphores = NULL, *rd_semaphore_arrays = NULL;
956 if (unlikely(!st_semaphores)) {
957 st_semaphores = rrdset_create_localhost("system",
969 rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
971 else rrdset_next(st_semaphores);
973 rrddim_set_by_pointer(st_semaphores, rd_semaphores, ipc_sem.semaphores);
974 rrdset_done(st_semaphores);
976 // --------------------------------------------------------------------
978 if (unlikely(!st_semaphore_arrays)) {
979 st_semaphore_arrays = rrdset_create_localhost("system",
980 "ipc_semaphore_arrays",
984 "IPC Semaphore Arrays",
991 rd_semaphore_arrays = rrddim_add(st_semaphore_arrays, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
993 else rrdset_next(st_semaphore_arrays);
995 rrddim_set_by_pointer(st_semaphore_arrays, rd_semaphore_arrays, ipc_sem.sets);
996 rrdset_done(st_semaphore_arrays);
1003 // --------------------------------------------------------------------------------------------------------------------
1006 int do_kern_ipc_shm(int update_every, usec_t dt) {
1008 static int mib_shmmni[3] = {0, 0, 0}, mib_shmsegs[3] = {0, 0, 0};
1011 collected_number segs;
1012 collected_number segsize;
1013 } ipc_shm = {0, 0, 0};
1015 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.shmmni", mib_shmmni, ipc_shm.shmmni))) {
1016 error("DISABLED: system.ipc_shared_mem_segs chart");
1017 error("DISABLED: system.ipc_shared_mem_size chart");
1018 error("DISABLED: kern.ipc.shmmodule");
1021 static struct shmid_kernel *ipc_shm_data = NULL;
1023 ipc_shm_data = reallocz(ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni);
1025 GETSYSCTL_WSIZE("kern.ipc.shmsegs", mib_shmsegs, ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni))) {
1026 error("DISABLED: system.ipc_shared_mem_segs chart");
1027 error("DISABLED: system.ipc_shared_mem_size chart");
1028 error("DISABLED: kern.ipc.shmmodule");
1033 for (i = 0; i < ipc_shm.shmmni; i++) {
1034 if (unlikely(ipc_shm_data[i].u.shm_perm.mode & 0x0800)) {
1036 ipc_shm.segsize += ipc_shm_data[i].u.shm_segsz;
1040 // --------------------------------------------------------------------
1042 static RRDSET *st_segs = NULL, *st_size = NULL;
1043 static RRDDIM *rd_segments = NULL, *rd_allocated = NULL;
1045 if (unlikely(!st_segs)) {
1046 st_segs = rrdset_create_localhost("system",
1047 "ipc_shared_mem_segs",
1049 "ipc shared memory",
1051 "IPC Shared Memory Segments",
1058 rd_segments = rrddim_add(st_segs, "segments", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1060 else rrdset_next(st_segs);
1062 rrddim_set_by_pointer(st_segs, rd_segments, ipc_shm.segs);
1063 rrdset_done(st_segs);
1065 // --------------------------------------------------------------------
1067 if (unlikely(!st_size)) {
1068 st_size = rrdset_create_localhost("system",
1069 "ipc_shared_mem_size",
1071 "ipc shared memory",
1073 "IPC Shared Memory Segments Size",
1080 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, KILO_FACTOR, RRD_ALGORITHM_ABSOLUTE);
1082 else rrdset_next(st_size);
1084 rrddim_set_by_pointer(st_size, rd_allocated, ipc_shm.segsize);
1085 rrdset_done(st_size);
1092 // --------------------------------------------------------------------------------------------------------------------
1095 int do_kern_ipc_msq(int update_every, usec_t dt) {
1097 static int mib_msgmni[3] = {0, 0, 0}, mib_msqids[3] = {0, 0, 0};
1100 collected_number queues;
1101 collected_number messages;
1102 collected_number usedsize;
1103 collected_number allocsize;
1104 } ipc_msq = {0, 0, 0, 0, 0};
1106 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.msgmni", mib_msgmni, ipc_msq.msgmni))) {
1107 error("DISABLED: system.ipc_msq_queues chart");
1108 error("DISABLED: system.ipc_msq_messages chart");
1109 error("DISABLED: system.ipc_msq_size chart");
1110 error("DISABLED: kern.ipc.msg module");
1113 static struct msqid_kernel *ipc_msq_data = NULL;
1115 ipc_msq_data = reallocz(ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni);
1117 GETSYSCTL_WSIZE("kern.ipc.msqids", mib_msqids, ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni))) {
1118 error("DISABLED: system.ipc_msq_queues chart");
1119 error("DISABLED: system.ipc_msq_messages chart");
1120 error("DISABLED: system.ipc_msq_size chart");
1121 error("DISABLED: kern.ipc.msg module");
1126 for (i = 0; i < ipc_msq.msgmni; i++) {
1127 if (unlikely(ipc_msq_data[i].u.msg_qbytes != 0)) {
1128 ipc_msq.queues += 1;
1129 ipc_msq.messages += ipc_msq_data[i].u.msg_qnum;
1130 ipc_msq.usedsize += ipc_msq_data[i].u.msg_cbytes;
1131 ipc_msq.allocsize += ipc_msq_data[i].u.msg_qbytes;
1135 // --------------------------------------------------------------------
1137 static RRDSET *st_queues = NULL, *st_messages = NULL, *st_size = NULL;
1138 static RRDDIM *rd_queues = NULL, *rd_messages = NULL, *rd_allocated = NULL, *rd_used = NULL;
1140 if (unlikely(!st_queues)) {
1141 st_queues = rrdset_create_localhost("system",
1144 "ipc message queues",
1146 "Number of IPC Message Queues",
1153 rd_queues = rrddim_add(st_queues, "queues", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1155 else rrdset_next(st_queues);
1157 rrddim_set_by_pointer(st_queues, rd_queues, ipc_msq.queues);
1158 rrdset_done(st_queues);
1160 // --------------------------------------------------------------------
1162 if (unlikely(!st_messages)) {
1163 st_messages = rrdset_create_localhost("system",
1166 "ipc message queues",
1168 "Number of Messages in IPC Message Queues",
1175 rd_messages = rrddim_add(st_messages, "messages", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1177 else rrdset_next(st_messages);
1179 rrddim_set_by_pointer(st_messages, rd_messages, ipc_msq.messages);
1180 rrdset_done(st_messages);
1182 // --------------------------------------------------------------------
1184 if (unlikely(!st_size)) {
1185 st_size = rrdset_create_localhost("system",
1188 "ipc message queues",
1190 "Size of IPC Message Queues",
1197 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1198 rd_used = rrddim_add(st_size, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1200 else rrdset_next(st_size);
1202 rrddim_set_by_pointer(st_size, rd_allocated, ipc_msq.allocsize);
1203 rrddim_set_by_pointer(st_size, rd_used, ipc_msq.usedsize);
1204 rrdset_done(st_size);
1211 // --------------------------------------------------------------------------------------------------------------------
1214 int do_uptime(int update_every, usec_t dt) {
1216 struct timespec up_time;
1218 clock_gettime(CLOCK_UPTIME, &up_time);
1220 // --------------------------------------------------------------------
1222 static RRDSET *st = NULL;
1223 static RRDDIM *rd = NULL;
1226 st = rrdset_create_localhost("system",
1238 rd = rrddim_add(st, "uptime", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1240 else rrdset_next(st);
1242 rrddim_set_by_pointer(st, rd, up_time.tv_sec);
1248 // --------------------------------------------------------------------------------------------------------------------
1251 int do_net_isr(int update_every, usec_t dt) {
1253 static int do_netisr = -1, do_netisr_per_core = -1;
1255 if (unlikely(do_netisr == -1)) {
1256 do_netisr = config_get_boolean("plugin:freebsd:net.isr", "netisr", 1);
1257 do_netisr_per_core = config_get_boolean("plugin:freebsd:net.isr", "netisr per core", 1);
1260 static int mib_workstream[3] = {0, 0, 0}, mib_work[3] = {0, 0, 0};
1261 int common_error = 0;
1262 size_t netisr_workstream_size = sizeof(mib_workstream), netisr_work_size = sizeof(mib_work);
1263 unsigned long num_netisr_workstreams = 0, num_netisr_works = 0;
1264 static struct sysctl_netisr_workstream *netisr_workstream = NULL;
1265 static struct sysctl_netisr_work *netisr_work = NULL;
1266 static struct netisr_stats {
1267 collected_number dispatched;
1268 collected_number hybrid_dispatched;
1269 collected_number qdrops;
1270 collected_number queued;
1271 } *netisr_stats = NULL;
1273 if (likely(do_netisr || do_netisr_per_core)) {
1274 if (unlikely(GETSYSCTL_SIZE("net.isr.workstream", mib_workstream, netisr_workstream_size))) {
1276 } else if (unlikely(GETSYSCTL_SIZE("net.isr.work", mib_work, netisr_work_size))) {
1279 num_netisr_workstreams = netisr_workstream_size / sizeof(struct sysctl_netisr_workstream);
1280 netisr_workstream = reallocz(netisr_workstream, num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream));
1281 if (unlikely(GETSYSCTL_WSIZE("net.isr.workstream", mib_workstream, netisr_workstream,
1282 num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream)))){
1285 num_netisr_works = netisr_work_size / sizeof(struct sysctl_netisr_work);
1286 netisr_work = reallocz(netisr_work, num_netisr_works * sizeof(struct sysctl_netisr_work));
1287 if (unlikely(GETSYSCTL_WSIZE("net.isr.work", mib_work, netisr_work,
1288 num_netisr_works * sizeof(struct sysctl_netisr_work)))){
1293 if (unlikely(common_error)) {
1295 error("DISABLED: system.softnet_stat chart");
1296 do_netisr_per_core = 0;
1297 error("DISABLED: system.cpuX_softnet_stat chart");
1299 error("DISABLED: net.isr module");
1305 netisr_stats = reallocz(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1306 memset(netisr_stats, 0, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1307 for (i = 0; i < num_netisr_workstreams; i++) {
1308 for (n = 0; n < num_netisr_works; n++) {
1309 if (netisr_workstream[i].snws_wsid == netisr_work[n].snw_wsid) {
1310 netisr_stats[netisr_workstream[i].snws_cpu].dispatched += netisr_work[n].snw_dispatched;
1311 netisr_stats[netisr_workstream[i].snws_cpu].hybrid_dispatched += netisr_work[n].snw_hybrid_dispatched;
1312 netisr_stats[netisr_workstream[i].snws_cpu].qdrops += netisr_work[n].snw_qdrops;
1313 netisr_stats[netisr_workstream[i].snws_cpu].queued += netisr_work[n].snw_queued;
1317 for (j = 0; j < number_of_cpus; j++) {
1318 netisr_stats[number_of_cpus].dispatched += netisr_stats[j].dispatched;
1319 netisr_stats[number_of_cpus].hybrid_dispatched += netisr_stats[j].hybrid_dispatched;
1320 netisr_stats[number_of_cpus].qdrops += netisr_stats[j].qdrops;
1321 netisr_stats[number_of_cpus].queued += netisr_stats[j].queued;
1325 error("DISABLED: net.isr module");
1329 // --------------------------------------------------------------------
1331 if (likely(do_netisr)) {
1332 static RRDSET *st = NULL;
1333 static RRDDIM *rd_dispatched = NULL, *rd_hybrid_dispatched = NULL, *rd_qdrops = NULL, *rd_queued = NULL;
1335 if (unlikely(!st)) {
1336 st = rrdset_create_localhost("system",
1341 "System softnet_stat",
1348 rd_dispatched = rrddim_add(st, "dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1349 rd_hybrid_dispatched = rrddim_add(st, "hybrid_dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1350 rd_qdrops = rrddim_add(st, "qdrops", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1351 rd_queued = rrddim_add(st, "queued", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1353 else rrdset_next(st);
1355 rrddim_set_by_pointer(st, rd_dispatched, netisr_stats[number_of_cpus].dispatched);
1356 rrddim_set_by_pointer(st, rd_hybrid_dispatched, netisr_stats[number_of_cpus].hybrid_dispatched);
1357 rrddim_set_by_pointer(st, rd_qdrops, netisr_stats[number_of_cpus].qdrops);
1358 rrddim_set_by_pointer(st, rd_queued, netisr_stats[number_of_cpus].queued);
1362 // --------------------------------------------------------------------
1364 if (likely(do_netisr_per_core)) {
1365 static struct softnet_chart {
1366 char netisr_cpuid[MAX_INT_DIGITS + 17];
1368 RRDDIM *rd_dispatched;
1369 RRDDIM *rd_hybrid_dispatched;
1372 } *all_softnet_charts = NULL;
1373 static int old_number_of_cpus = 0;
1376 if(unlikely(number_of_cpus > old_number_of_cpus)) {
1377 all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus);
1378 memset(&all_softnet_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus));
1379 old_number_of_cpus = number_of_cpus;
1382 for (i = 0; i < number_of_cpus ;i++) {
1383 snprintfz(all_softnet_charts[i].netisr_cpuid, MAX_INT_DIGITS + 17, "cpu%d_softnet_stat", i);
1385 if (unlikely(!all_softnet_charts[i].st)) {
1386 all_softnet_charts[i].st = rrdset_create_localhost("cpu",
1387 all_softnet_charts[i].netisr_cpuid,
1391 "Per CPU netisr statistics",
1398 all_softnet_charts[i].rd_dispatched = rrddim_add(all_softnet_charts[i].st, "dispatched",
1399 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1400 all_softnet_charts[i].rd_hybrid_dispatched = rrddim_add(all_softnet_charts[i].st, "hybrid_dispatched",
1401 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1402 all_softnet_charts[i].rd_qdrops = rrddim_add(all_softnet_charts[i].st, "qdrops",
1403 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1404 all_softnet_charts[i].rd_queued = rrddim_add(all_softnet_charts[i].st, "queued",
1405 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1407 else rrdset_next(all_softnet_charts[i].st);
1409 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_dispatched,
1410 netisr_stats[i].dispatched);
1411 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_hybrid_dispatched,
1412 netisr_stats[i].hybrid_dispatched);
1413 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_qdrops,
1414 netisr_stats[i].qdrops);
1415 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_queued,
1416 netisr_stats[i].queued);
1417 rrdset_done(all_softnet_charts[i].st);
1424 // --------------------------------------------------------------------------------------------------------------------
1425 // net.inet.tcp.states
1427 int do_net_inet_tcp_states(int update_every, usec_t dt) {
1429 static int mib[4] = {0, 0, 0, 0};
1430 uint64_t tcps_states[TCP_NSTATES];
1432 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1433 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.states", mib, tcps_states))) {
1434 error("DISABLED: ipv4.tcpsock chart");
1435 error("DISABLED: net.inet.tcp.states module");
1439 // --------------------------------------------------------------------
1441 static RRDSET *st = NULL;
1442 static RRDDIM *rd = NULL;
1444 if (unlikely(!st)) {
1445 st = rrdset_create_localhost("ipv4",
1450 "IPv4 TCP Connections",
1451 "active connections",
1457 rd = rrddim_add(st, "CurrEstab", "connections", 1, 1, RRD_ALGORITHM_ABSOLUTE);
1461 rrddim_set_by_pointer(st, rd, tcps_states[TCPS_ESTABLISHED]);
1468 // --------------------------------------------------------------------------------------------------------------------
1469 // net.inet.tcp.stats
1471 int do_net_inet_tcp_stats(int update_every, usec_t dt) {
1473 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;
1475 if (unlikely(do_tcp_packets == -1)) {
1476 do_tcp_packets = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP packets", 1);
1477 do_tcp_errors = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP errors", 1);
1478 do_tcp_handshake = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP handshake issues", 1);
1479 do_tcpext_connaborts = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP connection aborts",
1480 CONFIG_BOOLEAN_AUTO);
1481 do_tcpext_ofo = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP out-of-order queue",
1482 CONFIG_BOOLEAN_AUTO);
1483 do_tcpext_syncookies = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP SYN cookies",
1484 CONFIG_BOOLEAN_AUTO);
1485 do_ecn = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "ECN packets",
1486 CONFIG_BOOLEAN_AUTO);
1489 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1490 if (likely(do_tcp_packets || do_tcp_errors || do_tcp_handshake || do_tcpext_connaborts || do_tcpext_ofo || do_tcpext_syncookies || do_ecn)) {
1491 static int mib[4] = {0, 0, 0, 0};
1492 struct tcpstat tcpstat;
1494 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.stats", mib, tcpstat))) {
1496 error("DISABLED: ipv4.tcppackets chart");
1498 error("DISABLED: ipv4.tcperrors chart");
1499 do_tcp_handshake = 0;
1500 error("DISABLED: ipv4.tcphandshake chart");
1501 do_tcpext_connaborts = 0;
1502 error("DISABLED: ipv4.tcpconnaborts chart");
1504 error("DISABLED: ipv4.tcpofo chart");
1505 do_tcpext_syncookies = 0;
1506 error("DISABLED: ipv4.tcpsyncookies chart");
1508 error("DISABLED: ipv4.ecnpkts chart");
1509 error("DISABLED: net.inet.tcp.stats module");
1513 // --------------------------------------------------------------------
1515 if (likely(do_tcp_packets)) {
1516 static RRDSET *st = NULL;
1517 static RRDDIM *rd_in_segs = NULL, *rd_out_segs = NULL;
1519 if (unlikely(!st)) {
1520 st = rrdset_create_localhost("ipv4",
1532 rd_in_segs = rrddim_add(st, "InSegs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1533 rd_out_segs = rrddim_add(st, "OutSegs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1537 rrddim_set_by_pointer(st, rd_in_segs, tcpstat.tcps_rcvtotal);
1538 rrddim_set_by_pointer(st, rd_out_segs, tcpstat.tcps_sndtotal);
1542 // --------------------------------------------------------------------
1544 if (likely(do_tcp_errors)) {
1545 static RRDSET *st = NULL;
1546 static RRDDIM *rd_in_errs = NULL, *rd_in_csum_errs = NULL, *rd_retrans_segs = NULL;
1548 if (unlikely(!st)) {
1549 st = rrdset_create_localhost("ipv4",
1561 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1563 rd_in_errs = rrddim_add(st, "InErrs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1564 rd_in_csum_errs = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1565 rd_retrans_segs = rrddim_add(st, "RetransSegs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1569 #if __FreeBSD__ >= 11
1570 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvreassfull +
1571 tcpstat.tcps_rcvshort);
1573 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvshort);
1575 rrddim_set_by_pointer(st, rd_in_csum_errs, tcpstat.tcps_rcvbadsum);
1576 rrddim_set_by_pointer(st, rd_retrans_segs, tcpstat.tcps_sndrexmitpack);
1580 // --------------------------------------------------------------------
1582 if (likely(do_tcp_handshake)) {
1583 static RRDSET *st = NULL;
1584 static RRDDIM *rd_estab_resets = NULL, *rd_active_opens = NULL, *rd_passive_opens = NULL,
1585 *rd_attempt_fails = NULL;
1587 if (unlikely(!st)) {
1588 st = rrdset_create_localhost("ipv4",
1593 "IPv4 TCP Handshake Issues",
1600 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1602 rd_estab_resets = rrddim_add(st, "EstabResets", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1603 rd_active_opens = rrddim_add(st, "ActiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1604 rd_passive_opens = rrddim_add(st, "PassiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1605 rd_attempt_fails = rrddim_add(st, "AttemptFails", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1609 rrddim_set_by_pointer(st, rd_estab_resets, tcpstat.tcps_drops);
1610 rrddim_set_by_pointer(st, rd_active_opens, tcpstat.tcps_connattempt);
1611 rrddim_set_by_pointer(st, rd_passive_opens, tcpstat.tcps_accepts);
1612 rrddim_set_by_pointer(st, rd_attempt_fails, tcpstat.tcps_conndrops);
1616 // --------------------------------------------------------------------
1618 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))) {
1619 do_tcpext_connaborts = CONFIG_BOOLEAN_YES;
1621 static RRDSET *st = NULL;
1622 static RRDDIM *rd_on_data = NULL, *rd_on_close = NULL, *rd_on_memory = NULL,
1623 *rd_on_timeout = NULL, *rd_on_linger = NULL;
1625 if (unlikely(!st)) {
1626 st = rrdset_create_localhost("ipv4",
1631 "TCP Connection Aborts",
1638 rd_on_data = rrddim_add(st, "TCPAbortOnData", "baddata", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1639 rd_on_close = rrddim_add(st, "TCPAbortOnClose", "userclosed", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1640 rd_on_memory = rrddim_add(st, "TCPAbortOnMemory", "nomemory", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1641 rd_on_timeout = rrddim_add(st, "TCPAbortOnTimeout", "timeout", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1642 rd_on_linger = rrddim_add(st, "TCPAbortOnLinger", "linger", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1644 else rrdset_next(st);
1646 rrddim_set_by_pointer(st, rd_on_data, tcpstat.tcps_rcvpackafterwin);
1647 rrddim_set_by_pointer(st, rd_on_close, tcpstat.tcps_rcvafterclose);
1648 rrddim_set_by_pointer(st, rd_on_memory, tcpstat.tcps_rcvmemdrop);
1649 rrddim_set_by_pointer(st, rd_on_timeout, tcpstat.tcps_persistdrop);
1650 rrddim_set_by_pointer(st, rd_on_linger, tcpstat.tcps_finwait2_drops);
1654 // --------------------------------------------------------------------
1656 if (do_tcpext_ofo == CONFIG_BOOLEAN_YES || (do_tcpext_ofo == CONFIG_BOOLEAN_AUTO && tcpstat.tcps_rcvoopack)) {
1657 do_tcpext_ofo = CONFIG_BOOLEAN_YES;
1659 static RRDSET *st = NULL;
1660 static RRDDIM *rd_ofo_queue = NULL;
1662 if (unlikely(!st)) {
1663 st = rrdset_create_localhost("ipv4",
1668 "TCP Out-Of-Order Queue",
1675 rd_ofo_queue = rrddim_add(st, "TCPOFOQueue", "inqueue", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1677 else rrdset_next(st);
1679 rrddim_set_by_pointer(st, rd_ofo_queue, tcpstat.tcps_rcvoopack);
1683 // --------------------------------------------------------------------
1685 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))) {
1686 do_tcpext_syncookies = CONFIG_BOOLEAN_YES;
1688 static RRDSET *st = NULL;
1689 static RRDDIM *rd_recv = NULL, *rd_send = NULL, *rd_failed = NULL;
1691 if (unlikely(!st)) {
1692 st = rrdset_create_localhost("ipv4",
1704 rd_recv = rrddim_add(st, "SyncookiesRecv", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1705 rd_send = rrddim_add(st, "SyncookiesSent", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1706 rd_failed = rrddim_add(st, "SyncookiesFailed", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1708 else rrdset_next(st);
1710 rrddim_set_by_pointer(st, rd_recv, tcpstat.tcps_sc_recvcookie);
1711 rrddim_set_by_pointer(st, rd_send, tcpstat.tcps_sc_sendcookie);
1712 rrddim_set_by_pointer(st, rd_failed, tcpstat.tcps_sc_zonefail);
1716 // --------------------------------------------------------------------
1718 if (do_ecn == CONFIG_BOOLEAN_YES || (do_ecn == CONFIG_BOOLEAN_AUTO && (tcpstat.tcps_ecn_ce || tcpstat.tcps_ecn_ect0 || tcpstat.tcps_ecn_ect1))) {
1719 do_ecn = CONFIG_BOOLEAN_YES;
1721 static RRDSET *st = NULL;
1722 static RRDDIM *rd_ce = NULL, *rd_no_ect = NULL, *rd_ect0 = NULL, *rd_ect1 = NULL;
1724 if (unlikely(!st)) {
1725 st = rrdset_create_localhost("ipv4",
1730 "IPv4 ECN Statistics",
1737 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1739 rd_ce = rrddim_add(st, "InCEPkts", "CEP", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1740 rd_no_ect = rrddim_add(st, "InNoECTPkts", "NoECTP", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1741 rd_ect0 = rrddim_add(st, "InECT0Pkts", "ECTP0", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1742 rd_ect1 = rrddim_add(st, "InECT1Pkts", "ECTP1", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1744 else rrdset_next(st);
1746 rrddim_set_by_pointer(st, rd_ce, tcpstat.tcps_ecn_ce);
1747 rrddim_set_by_pointer(st, rd_no_ect, tcpstat.tcps_ecn_ce - (tcpstat.tcps_ecn_ect0 +
1748 tcpstat.tcps_ecn_ect1));
1749 rrddim_set_by_pointer(st, rd_ect0, tcpstat.tcps_ecn_ect0);
1750 rrddim_set_by_pointer(st, rd_ect1, tcpstat.tcps_ecn_ect1);
1756 error("DISABLED: net.inet.tcp.stats module");
1763 // --------------------------------------------------------------------------------------------------------------------
1764 // net.inet.udp.stats
1766 int do_net_inet_udp_stats(int update_every, usec_t dt) {
1768 static int do_udp_packets = -1, do_udp_errors = -1;
1770 if (unlikely(do_udp_packets == -1)) {
1771 do_udp_packets = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP packets", 1);
1772 do_udp_errors = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP errors", 1);
1775 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
1776 if (likely(do_udp_packets || do_udp_errors)) {
1777 static int mib[4] = {0, 0, 0, 0};
1778 struct udpstat udpstat;
1780 if (unlikely(GETSYSCTL_SIMPLE("net.inet.udp.stats", mib, udpstat))) {
1782 error("DISABLED: ipv4.udppackets chart");
1784 error("DISABLED: ipv4.udperrors chart");
1785 error("DISABLED: net.inet.udp.stats module");
1789 // --------------------------------------------------------------------
1791 if (likely(do_udp_packets)) {
1792 static RRDSET *st = NULL;
1793 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1795 if (unlikely(!st)) {
1796 st = rrdset_create_localhost("ipv4",
1808 rd_in = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1809 rd_out = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1813 rrddim_set_by_pointer(st, rd_in, udpstat.udps_ipackets);
1814 rrddim_set_by_pointer(st, rd_out, udpstat.udps_opackets);
1818 // --------------------------------------------------------------------
1820 if (likely(do_udp_errors)) {
1821 static RRDSET *st = NULL;
1822 static RRDDIM *rd_in_errors = NULL, *rd_no_ports = NULL, *rd_recv_buf_errors = NULL,
1823 *rd_in_csum_errors = NULL, *rd_ignored_multi = NULL;
1825 if (unlikely(!st)) {
1826 st = rrdset_create_localhost("ipv4",
1838 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1840 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1841 rd_no_ports = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1842 rd_recv_buf_errors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1843 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1844 rd_ignored_multi = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1848 rrddim_set_by_pointer(st, rd_in_errors, udpstat.udps_hdrops + udpstat.udps_badlen);
1849 rrddim_set_by_pointer(st, rd_no_ports, udpstat.udps_noport);
1850 rrddim_set_by_pointer(st, rd_recv_buf_errors, udpstat.udps_fullsock);
1851 rrddim_set_by_pointer(st, rd_in_csum_errors, udpstat.udps_badsum + udpstat.udps_nosum);
1852 rrddim_set_by_pointer(st, rd_ignored_multi, udpstat.udps_filtermcast);
1857 error("DISABLED: net.inet.udp.stats module");
1864 // --------------------------------------------------------------------------------------------------------------------
1865 // net.inet.icmp.stats
1867 int do_net_inet_icmp_stats(int update_every, usec_t dt) {
1869 static int do_icmp_packets = -1, do_icmp_errors = -1, do_icmpmsg = -1;
1871 if (unlikely(do_icmp_packets == -1)) {
1872 do_icmp_packets = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP packets", 1);
1873 do_icmp_errors = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP errors", 1);
1874 do_icmpmsg = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP messages", 1);
1877 if (likely(do_icmp_packets || do_icmp_errors || do_icmpmsg)) {
1878 static int mib[4] = {0, 0, 0, 0};
1879 struct icmpstat icmpstat;
1884 } icmp_total = {0, 0};
1886 if (unlikely(GETSYSCTL_SIMPLE("net.inet.icmp.stats", mib, icmpstat))) {
1887 do_icmp_packets = 0;
1888 error("DISABLED: ipv4.icmp chart");
1890 error("DISABLED: ipv4.icmp_errors chart");
1892 error("DISABLED: ipv4.icmpmsg chart");
1893 error("DISABLED: net.inet.icmp.stats module");
1896 for (i = 0; i <= ICMP_MAXTYPE; i++) {
1897 icmp_total.msgs_in += icmpstat.icps_inhist[i];
1898 icmp_total.msgs_out += icmpstat.icps_outhist[i];
1900 icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
1902 // --------------------------------------------------------------------
1904 if (likely(do_icmp_packets)) {
1905 static RRDSET *st = NULL;
1906 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1908 if (unlikely(!st)) {
1909 st = rrdset_create_localhost("ipv4",
1914 "IPv4 ICMP Packets",
1921 rd_in = rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1922 rd_out = rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1926 rrddim_set_by_pointer(st, rd_in, icmp_total.msgs_in);
1927 rrddim_set_by_pointer(st, rd_out, icmp_total.msgs_out);
1932 // --------------------------------------------------------------------
1934 if (likely(do_icmp_errors)) {
1935 static RRDSET *st = NULL;
1936 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_csum = NULL;
1938 if (unlikely(!st)) {
1939 st = rrdset_create_localhost("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
1941 2603, update_every, RRDSET_TYPE_LINE);
1943 rd_in = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1944 rd_out = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1945 rd_in_csum = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1949 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_badcode + icmpstat.icps_badlen +
1950 icmpstat.icps_checksum + icmpstat.icps_tooshort);
1951 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_error);
1952 rrddim_set_by_pointer(st, rd_in_csum, icmpstat.icps_checksum);
1957 // --------------------------------------------------------------------
1959 if (likely(do_icmpmsg)) {
1960 static RRDSET *st = NULL;
1961 static RRDDIM *rd_in_reps = NULL, *rd_out_reps = NULL, *rd_in = NULL, *rd_out = NULL;
1963 if (unlikely(!st)) {
1964 st = rrdset_create_localhost("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
1965 "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
1967 rd_in_reps = rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1968 rd_out_reps = rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1969 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1970 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1974 rrddim_set_by_pointer(st, rd_in_reps, icmpstat.icps_inhist[ICMP_ECHOREPLY]);
1975 rrddim_set_by_pointer(st, rd_out_reps, icmpstat.icps_outhist[ICMP_ECHOREPLY]);
1976 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_inhist[ICMP_ECHO]);
1977 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_outhist[ICMP_ECHO]);
1983 error("DISABLED: net.inet.icmp.stats module");
1990 // --------------------------------------------------------------------------------------------------------------------
1991 // net.inet.ip.stats
1993 int do_net_inet_ip_stats(int update_every, usec_t dt) {
1995 static int do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1;
1997 if (unlikely(do_ip_packets == -1)) {
1998 do_ip_packets = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 packets", 1);
1999 do_ip_fragsout = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments sent", 1);
2000 do_ip_fragsin = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments assembly", 1);
2001 do_ip_errors = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 errors", 1);
2004 // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html
2005 if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) {
2006 static int mib[4] = {0, 0, 0, 0};
2007 struct ipstat ipstat;
2009 if (unlikely(GETSYSCTL_SIMPLE("net.inet.ip.stats", mib, ipstat))) {
2011 error("DISABLED: ipv4.packets chart");
2013 error("DISABLED: ipv4.fragsout chart");
2015 error("DISABLED: ipv4.fragsin chart");
2017 error("DISABLED: ipv4.errors chart");
2018 error("DISABLED: net.inet.ip.stats module");
2022 // --------------------------------------------------------------------
2024 if (likely(do_ip_packets)) {
2025 static RRDSET *st = NULL;
2026 static RRDDIM *rd_in_receives = NULL, *rd_out_requests = NULL, *rd_forward_datagrams = NULL,
2027 *rd_in_delivers = NULL;
2029 if (unlikely(!st)) {
2030 st = rrdset_create_localhost("ipv4",
2042 rd_in_receives = rrddim_add(st, "InReceives", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2043 rd_out_requests = rrddim_add(st, "OutRequests", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2044 rd_forward_datagrams = rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2045 rd_in_delivers = rrddim_add(st, "InDelivers", "delivered", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2049 rrddim_set_by_pointer(st, rd_in_receives, ipstat.ips_total);
2050 rrddim_set_by_pointer(st, rd_out_requests, ipstat.ips_localout);
2051 rrddim_set_by_pointer(st, rd_forward_datagrams, ipstat.ips_forward);
2052 rrddim_set_by_pointer(st, rd_in_delivers, ipstat.ips_delivered);
2056 // --------------------------------------------------------------------
2058 if (likely(do_ip_fragsout)) {
2059 static RRDSET *st = NULL;
2060 static RRDDIM *rd_ok = NULL, *rd_fails = NULL, *rd_created = NULL;
2062 if (unlikely(!st)) {
2063 st = rrdset_create_localhost("ipv4",
2068 "IPv4 Fragments Sent",
2075 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2077 rd_ok = rrddim_add(st, "FragOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2078 rd_fails = rrddim_add(st, "FragFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2079 rd_created = rrddim_add(st, "FragCreates", "created", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2083 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragmented);
2084 rrddim_set_by_pointer(st, rd_fails, ipstat.ips_cantfrag);
2085 rrddim_set_by_pointer(st, rd_created, ipstat.ips_ofragments);
2089 // --------------------------------------------------------------------
2091 if (likely(do_ip_fragsin)) {
2092 static RRDSET *st = NULL;
2093 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2095 if (unlikely(!st)) {
2096 st = rrdset_create_localhost("ipv4",
2101 "IPv4 Fragments Reassembly",
2108 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2110 rd_ok = rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2111 rd_failed = rrddim_add(st, "ReasmFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2112 rd_all = rrddim_add(st, "ReasmReqds", "all", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2116 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragments);
2117 rrddim_set_by_pointer(st, rd_failed, ipstat.ips_fragdropped);
2118 rrddim_set_by_pointer(st, rd_all, ipstat.ips_reassembled);
2122 // --------------------------------------------------------------------
2124 if (likely(do_ip_errors)) {
2125 static RRDSET *st = NULL;
2126 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2127 *rd_in_hdr_errors = NULL, *rd_out_no_routes = NULL,
2128 *rd_in_addr_errors = NULL, *rd_in_unknown_protos = NULL;
2130 if (unlikely(!st)) {
2131 st = rrdset_create_localhost("ipv4",
2143 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2145 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2146 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2147 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2148 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2149 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2150 rd_in_unknown_protos = rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2154 rrddim_set_by_pointer(st, rd_in_discards, ipstat.ips_badsum + ipstat.ips_tooshort +
2155 ipstat.ips_toosmall + ipstat.ips_toolong);
2156 rrddim_set_by_pointer(st, rd_out_discards, ipstat.ips_odropped);
2157 rrddim_set_by_pointer(st, rd_in_hdr_errors, ipstat.ips_badhlen + ipstat.ips_badlen +
2158 ipstat.ips_badoptions + ipstat.ips_badvers);
2159 rrddim_set_by_pointer(st, rd_out_no_routes, ipstat.ips_noroute);
2160 rrddim_set_by_pointer(st, rd_in_addr_errors, ipstat.ips_badaddr);
2161 rrddim_set_by_pointer(st, rd_in_unknown_protos, ipstat.ips_noproto);
2166 error("DISABLED: net.inet.ip.stats module");
2173 // --------------------------------------------------------------------------------------------------------------------
2174 // net.inet6.ip6.stats
2176 int do_net_inet6_ip6_stats(int update_every, usec_t dt) {
2178 static int do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1;
2180 if (unlikely(do_ip6_packets == -1)) {
2181 do_ip6_packets = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 packets",
2182 CONFIG_BOOLEAN_AUTO);
2183 do_ip6_fragsout = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments sent",
2184 CONFIG_BOOLEAN_AUTO);
2185 do_ip6_fragsin = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments assembly",
2186 CONFIG_BOOLEAN_AUTO);
2187 do_ip6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 errors",
2188 CONFIG_BOOLEAN_AUTO);
2191 if (likely(do_ip6_packets || do_ip6_fragsout || do_ip6_fragsin || do_ip6_errors)) {
2192 static int mib[4] = {0, 0, 0, 0};
2193 struct ip6stat ip6stat;
2195 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.ip6.stats", mib, ip6stat))) {
2197 error("DISABLED: ipv6.packets chart");
2198 do_ip6_fragsout = 0;
2199 error("DISABLED: ipv6.fragsout chart");
2201 error("DISABLED: ipv6.fragsin chart");
2203 error("DISABLED: ipv6.errors chart");
2204 error("DISABLED: net.inet6.ip6.stats module");
2208 // --------------------------------------------------------------------
2210 if (do_ip6_packets == CONFIG_BOOLEAN_YES || (do_ip6_packets == CONFIG_BOOLEAN_AUTO &&
2211 (ip6stat.ip6s_localout || ip6stat.ip6s_total ||
2212 ip6stat.ip6s_forward || ip6stat.ip6s_delivered))) {
2213 do_ip6_packets = CONFIG_BOOLEAN_YES;
2215 static RRDSET *st = NULL;
2216 static RRDDIM *rd_received = NULL, *rd_sent = NULL, *rd_forwarded = NULL, *rd_delivers = NULL;
2218 if (unlikely(!st)) {
2219 st = rrdset_create_localhost("ipv6",
2231 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2232 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2233 rd_forwarded = rrddim_add(st, "forwarded", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2234 rd_delivers = rrddim_add(st, "delivers", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2238 rrddim_set_by_pointer(st, rd_sent, ip6stat.ip6s_localout);
2239 rrddim_set_by_pointer(st, rd_received, ip6stat.ip6s_total);
2240 rrddim_set_by_pointer(st, rd_forwarded, ip6stat.ip6s_forward);
2241 rrddim_set_by_pointer(st, rd_delivers, ip6stat.ip6s_delivered);
2245 // --------------------------------------------------------------------
2247 if (do_ip6_fragsout == CONFIG_BOOLEAN_YES || (do_ip6_fragsout == CONFIG_BOOLEAN_AUTO &&
2248 (ip6stat.ip6s_fragmented || ip6stat.ip6s_cantfrag ||
2249 ip6stat.ip6s_ofragments))) {
2250 do_ip6_fragsout = CONFIG_BOOLEAN_YES;
2252 static RRDSET *st = NULL;
2253 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2255 if (unlikely(!st)) {
2256 st = rrdset_create_localhost("ipv6",
2261 "IPv6 Fragments Sent",
2268 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2270 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2271 rd_failed = rrddim_add(st, "failed", 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_fragmented);
2277 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_cantfrag);
2278 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_ofragments);
2282 // --------------------------------------------------------------------
2284 if (do_ip6_fragsin == CONFIG_BOOLEAN_YES || (do_ip6_fragsin == CONFIG_BOOLEAN_AUTO &&
2285 (ip6stat.ip6s_reassembled || ip6stat.ip6s_fragdropped ||
2286 ip6stat.ip6s_fragtimeout || ip6stat.ip6s_fragments))) {
2287 do_ip6_fragsin = CONFIG_BOOLEAN_YES;
2289 static RRDSET *st = NULL;
2290 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_timeout = NULL, *rd_all = NULL;
2292 if (unlikely(!st)) {
2293 st = rrdset_create_localhost("ipv6",
2298 "IPv6 Fragments Reassembly",
2305 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2307 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2308 rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2309 rd_timeout = rrddim_add(st, "timeout", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2310 rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2314 rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_reassembled);
2315 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_fragdropped);
2316 rrddim_set_by_pointer(st, rd_timeout, ip6stat.ip6s_fragtimeout);
2317 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_fragments);
2321 // --------------------------------------------------------------------
2323 if (do_ip6_errors == CONFIG_BOOLEAN_YES || (do_ip6_errors == CONFIG_BOOLEAN_AUTO && (
2324 ip6stat.ip6s_toosmall ||
2325 ip6stat.ip6s_odropped ||
2326 ip6stat.ip6s_badoptions ||
2327 ip6stat.ip6s_badvers ||
2328 ip6stat.ip6s_exthdrtoolong ||
2329 ip6stat.ip6s_sources_none ||
2330 ip6stat.ip6s_tooshort ||
2331 ip6stat.ip6s_cantforward ||
2332 ip6stat.ip6s_noroute))) {
2333 do_ip6_errors = CONFIG_BOOLEAN_YES;
2335 static RRDSET *st = NULL;
2336 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2337 *rd_in_hdr_errors = NULL, *rd_in_addr_errors = NULL, *rd_in_truncated_pkts = NULL,
2338 *rd_in_no_routes = NULL, *rd_out_no_routes = NULL;
2340 if (unlikely(!st)) {
2341 st = rrdset_create_localhost("ipv6",
2353 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2355 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2356 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2357 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2358 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2359 rd_in_truncated_pkts = rrddim_add(st, "InTruncatedPkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2360 rd_in_no_routes = rrddim_add(st, "InNoRoutes", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2361 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2365 rrddim_set_by_pointer(st, rd_in_discards, ip6stat.ip6s_toosmall);
2366 rrddim_set_by_pointer(st, rd_out_discards, ip6stat.ip6s_odropped);
2367 rrddim_set_by_pointer(st, rd_in_hdr_errors, ip6stat.ip6s_badoptions + ip6stat.ip6s_badvers +
2368 ip6stat.ip6s_exthdrtoolong);
2369 rrddim_set_by_pointer(st, rd_in_addr_errors, ip6stat.ip6s_sources_none);
2370 rrddim_set_by_pointer(st, rd_in_truncated_pkts, ip6stat.ip6s_tooshort);
2371 rrddim_set_by_pointer(st, rd_in_no_routes, ip6stat.ip6s_cantforward);
2372 rrddim_set_by_pointer(st, rd_out_no_routes, ip6stat.ip6s_noroute);
2377 error("DISABLED: net.inet6.ip6.stats module");
2384 // --------------------------------------------------------------------------------------------------------------------
2385 // net.inet6.icmp6.stats
2387 int do_net_inet6_icmp6_stats(int update_every, usec_t dt) {
2389 static int do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1,
2390 do_icmp6_neighbor = -1, do_icmp6_types = -1;
2392 if (unlikely(do_icmp6 == -1)) {
2393 do_icmp6 = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp",
2394 CONFIG_BOOLEAN_AUTO);
2395 do_icmp6_redir = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp redirects",
2396 CONFIG_BOOLEAN_AUTO);
2397 do_icmp6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp errors",
2398 CONFIG_BOOLEAN_AUTO);
2399 do_icmp6_echos = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp echos",
2400 CONFIG_BOOLEAN_AUTO);
2401 do_icmp6_router = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp router",
2402 CONFIG_BOOLEAN_AUTO);
2403 do_icmp6_neighbor = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp neighbor",
2404 CONFIG_BOOLEAN_AUTO);
2405 do_icmp6_types = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp types",
2406 CONFIG_BOOLEAN_AUTO);
2409 if (likely(do_icmp6 || do_icmp6_redir || do_icmp6_errors || do_icmp6_echos || do_icmp6_router || do_icmp6_neighbor || do_icmp6_types)) {
2410 static int mib[4] = {0, 0, 0, 0};
2411 struct icmp6stat icmp6stat;
2413 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.icmp6.stats", mib, icmp6stat))) {
2415 error("DISABLED: ipv6.icmp chart");
2417 error("DISABLED: ipv6.icmpredir chart");
2418 do_icmp6_errors = 0;
2419 error("DISABLED: ipv6.icmperrors chart");
2421 error("DISABLED: ipv6.icmpechos chart");
2422 do_icmp6_router = 0;
2423 error("DISABLED: ipv6.icmprouter chart");
2424 do_icmp6_neighbor = 0;
2425 error("DISABLED: ipv6.icmpneighbor chart");
2427 error("DISABLED: ipv6.icmptypes chart");
2428 error("DISABLED: net.inet6.icmp6.stats module");
2432 struct icmp6_total {
2435 } icmp6_total = {0, 0};
2437 for (i = 0; i <= ICMP6_MAXTYPE; i++) {
2438 icmp6_total.msgs_in += icmp6stat.icp6s_inhist[i];
2439 icmp6_total.msgs_out += icmp6stat.icp6s_outhist[i];
2441 icmp6_total.msgs_in += icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort;
2443 // --------------------------------------------------------------------
2445 if (do_icmp6 == CONFIG_BOOLEAN_YES || (do_icmp6 == CONFIG_BOOLEAN_AUTO && (icmp6_total.msgs_in || icmp6_total.msgs_out))) {
2446 do_icmp6 = CONFIG_BOOLEAN_YES;
2448 static RRDSET *st = NULL;
2449 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2451 if (unlikely(!st)) {
2452 st = rrdset_create_localhost("ipv6",
2457 "IPv6 ICMP Messages",
2464 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2465 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2469 rrddim_set_by_pointer(st, rd_received, icmp6_total.msgs_out);
2470 rrddim_set_by_pointer(st, rd_sent, icmp6_total.msgs_in);
2475 // --------------------------------------------------------------------
2477 if (do_icmp6_redir == CONFIG_BOOLEAN_YES || (do_icmp6_redir == CONFIG_BOOLEAN_AUTO && (icmp6stat.icp6s_inhist[ND_REDIRECT] || icmp6stat.icp6s_outhist[ND_REDIRECT]))) {
2478 do_icmp6_redir = CONFIG_BOOLEAN_YES;
2480 static RRDSET *st = NULL;
2481 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2483 if (unlikely(!st)) {
2484 st = rrdset_create_localhost("ipv6",
2489 "IPv6 ICMP Redirects",
2496 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2497 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2501 rrddim_set_by_pointer(st, rd_received, icmp6stat.icp6s_outhist[ND_REDIRECT]);
2502 rrddim_set_by_pointer(st, rd_sent, icmp6stat.icp6s_inhist[ND_REDIRECT]);
2506 // --------------------------------------------------------------------
2508 if (do_icmp6_errors == CONFIG_BOOLEAN_YES || (do_icmp6_errors == CONFIG_BOOLEAN_AUTO && (
2509 icmp6stat.icp6s_badcode ||
2510 icmp6stat.icp6s_badlen ||
2511 icmp6stat.icp6s_checksum ||
2512 icmp6stat.icp6s_tooshort ||
2513 icmp6stat.icp6s_error ||
2514 icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH] ||
2515 icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED] ||
2516 icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB] ||
2517 icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH] ||
2518 icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED] ||
2519 icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]))) {
2520 do_icmp6_errors = CONFIG_BOOLEAN_YES;
2522 static RRDSET *st = NULL;
2523 static RRDDIM *rd_in_errors = NULL, *rd_out_errors = NULL, *rd_in_csum_errors = NULL,
2524 *rd_in_dest_unreachs = NULL, *rd_in_pkt_too_bigs = NULL, *rd_in_time_excds = NULL,
2525 *rd_in_parm_problems = NULL, *rd_out_dest_unreachs = NULL, *rd_out_time_excds = NULL,
2526 *rd_out_parm_problems = NULL;
2528 if (unlikely(!st)) {
2529 st = rrdset_create_localhost("ipv6",
2540 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2541 rd_out_errors = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2542 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2543 rd_in_dest_unreachs = rrddim_add(st, "InDestUnreachs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2544 rd_in_pkt_too_bigs = rrddim_add(st, "InPktTooBigs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2545 rd_in_time_excds = rrddim_add(st, "InTimeExcds", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2546 rd_in_parm_problems = rrddim_add(st, "InParmProblems", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2547 rd_out_dest_unreachs = rrddim_add(st, "OutDestUnreachs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2548 rd_out_time_excds = rrddim_add(st, "OutTimeExcds", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2549 rd_out_parm_problems = rrddim_add(st, "OutParmProblems", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2553 rrddim_set_by_pointer(st, rd_in_errors, icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen +
2554 icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort);
2555 rrddim_set_by_pointer(st, rd_out_errors, icmp6stat.icp6s_error);
2556 rrddim_set_by_pointer(st, rd_in_csum_errors, icmp6stat.icp6s_checksum);
2557 rrddim_set_by_pointer(st, rd_in_dest_unreachs, icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH]);
2558 rrddim_set_by_pointer(st, rd_in_pkt_too_bigs, icmp6stat.icp6s_badlen);
2559 rrddim_set_by_pointer(st, rd_in_time_excds, icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED]);
2560 rrddim_set_by_pointer(st, rd_in_parm_problems, icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB]);
2561 rrddim_set_by_pointer(st, rd_out_dest_unreachs, icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH]);
2562 rrddim_set_by_pointer(st, rd_out_time_excds, icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED]);
2563 rrddim_set_by_pointer(st, rd_out_parm_problems, icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]);
2567 // --------------------------------------------------------------------
2569 if (do_icmp6_echos == CONFIG_BOOLEAN_YES || (do_icmp6_echos == CONFIG_BOOLEAN_AUTO && (
2570 icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST] ||
2571 icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST] ||
2572 icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY] ||
2573 icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]))) {
2574 do_icmp6_echos = CONFIG_BOOLEAN_YES;
2576 static RRDSET *st = NULL;
2577 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_replies = NULL, *rd_out_replies = NULL;
2579 if (unlikely(!st)) {
2580 st = rrdset_create_localhost("ipv6",
2592 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2593 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2594 rd_in_replies = rrddim_add(st, "InEchoReplies", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2595 rd_out_replies = rrddim_add(st, "OutEchoReplies", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2599 rrddim_set_by_pointer(st, rd_in, icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST]);
2600 rrddim_set_by_pointer(st, rd_out, icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST]);
2601 rrddim_set_by_pointer(st, rd_in_replies, icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY]);
2602 rrddim_set_by_pointer(st, rd_out_replies, icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]);
2606 // --------------------------------------------------------------------
2608 if (do_icmp6_router == CONFIG_BOOLEAN_YES || (do_icmp6_router == CONFIG_BOOLEAN_AUTO && (
2609 icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT] ||
2610 icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT] ||
2611 icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT] ||
2612 icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]))) {
2613 do_icmp6_router = CONFIG_BOOLEAN_YES;
2615 static RRDSET *st = NULL;
2616 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2617 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2619 if (unlikely(!st)) {
2620 st = rrdset_create_localhost("ipv6",
2625 "IPv6 Router Messages",
2632 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2633 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2634 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2635 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2639 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT]);
2640 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT]);
2641 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT]);
2642 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]);
2646 // --------------------------------------------------------------------
2648 if (do_icmp6_neighbor == CONFIG_BOOLEAN_YES || (do_icmp6_neighbor == CONFIG_BOOLEAN_AUTO && (
2649 icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT] ||
2650 icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT] ||
2651 icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT] ||
2652 icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]))) {
2653 do_icmp6_neighbor = CONFIG_BOOLEAN_YES;
2655 static RRDSET *st = NULL;
2656 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2657 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2659 if (unlikely(!st)) {
2660 st = rrdset_create_localhost("ipv6",
2665 "IPv6 Neighbor Messages",
2672 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2673 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2674 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2675 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2679 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]);
2680 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]);
2681 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT]);
2682 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]);
2686 // --------------------------------------------------------------------
2688 if (do_icmp6_types == CONFIG_BOOLEAN_YES || (do_icmp6_types == CONFIG_BOOLEAN_AUTO && (
2689 icmp6stat.icp6s_inhist[1] ||
2690 icmp6stat.icp6s_inhist[128] ||
2691 icmp6stat.icp6s_inhist[129] ||
2692 icmp6stat.icp6s_inhist[136] ||
2693 icmp6stat.icp6s_outhist[1] ||
2694 icmp6stat.icp6s_outhist[128] ||
2695 icmp6stat.icp6s_outhist[129] ||
2696 icmp6stat.icp6s_outhist[133] ||
2697 icmp6stat.icp6s_outhist[135] ||
2698 icmp6stat.icp6s_outhist[136]))) {
2699 do_icmp6_types = CONFIG_BOOLEAN_YES;
2701 static RRDSET *st = NULL;
2702 static RRDDIM *rd_in_1 = NULL, *rd_in_128 = NULL, *rd_in_129 = NULL, *rd_in_136 = NULL,
2703 *rd_out_1 = NULL, *rd_out_128 = NULL, *rd_out_129 = NULL, *rd_out_133 = NULL,
2704 *rd_out_135 = NULL, *rd_out_143 = NULL;
2706 if (unlikely(!st)) {
2707 st = rrdset_create_localhost("ipv6",
2719 rd_in_1 = rrddim_add(st, "InType1", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2720 rd_in_128 = rrddim_add(st, "InType128", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2721 rd_in_129 = rrddim_add(st, "InType129", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2722 rd_in_136 = rrddim_add(st, "InType136", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2723 rd_out_1 = rrddim_add(st, "OutType1", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2724 rd_out_128 = rrddim_add(st, "OutType128", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2725 rd_out_129 = rrddim_add(st, "OutType129", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2726 rd_out_133 = rrddim_add(st, "OutType133", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2727 rd_out_135 = rrddim_add(st, "OutType135", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2728 rd_out_143 = rrddim_add(st, "OutType143", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2732 rrddim_set_by_pointer(st, rd_in_1, icmp6stat.icp6s_inhist[1]);
2733 rrddim_set_by_pointer(st, rd_in_128, icmp6stat.icp6s_inhist[128]);
2734 rrddim_set_by_pointer(st, rd_in_129, icmp6stat.icp6s_inhist[129]);
2735 rrddim_set_by_pointer(st, rd_in_136, icmp6stat.icp6s_inhist[136]);
2736 rrddim_set_by_pointer(st, rd_out_1, icmp6stat.icp6s_outhist[1]);
2737 rrddim_set_by_pointer(st, rd_out_128, icmp6stat.icp6s_outhist[128]);
2738 rrddim_set_by_pointer(st, rd_out_129, icmp6stat.icp6s_outhist[129]);
2739 rrddim_set_by_pointer(st, rd_out_133, icmp6stat.icp6s_outhist[133]);
2740 rrddim_set_by_pointer(st, rd_out_135, icmp6stat.icp6s_outhist[135]);
2741 rrddim_set_by_pointer(st, rd_out_143, icmp6stat.icp6s_outhist[143]);
2746 error("DISABLED: net.inet6.icmp6.stats module");
2753 // --------------------------------------------------------------------------------------------------------------------
2756 int do_getmntinfo(int update_every, usec_t dt) {
2759 #define DELAULT_EXLUDED_PATHS "/proc/*"
2760 // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
2761 #define DEFAULT_EXCLUDED_FILESYSTEMS "autofs procfs subfs devfs none"
2762 #define CONFIG_SECTION_GETMNTINFO "plugin:freebsd:getmntinfo"
2764 static int do_space = -1, do_inodes = -1;
2766 if (unlikely(do_space == -1)) {
2767 do_space = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2768 do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2771 if (likely(do_space || do_inodes)) {
2772 struct statfs *mntbuf;
2775 // there is no mount info in sysctl MIBs
2776 if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) {
2777 error("FREEBSD: getmntinfo() failed");
2779 error("DISABLED: disk_space.* charts");
2781 error("DISABLED: disk_inodes.* charts");
2782 error("DISABLED: getmntinfo module");
2785 // Data to be stored in DICTIONARY mount_points.
2786 // This DICTIONARY is used to lookup the settings of the mount point on each iteration.
2787 struct mount_point_metadata {
2791 size_t collected; // the number of times this has been collected
2793 // charts and dimensions
2796 RRDDIM *rd_space_used;
2797 RRDDIM *rd_space_avail;
2798 RRDDIM *rd_space_reserved;
2801 RRDDIM *rd_inodes_used;
2802 RRDDIM *rd_inodes_avail;
2804 static DICTIONARY *mount_points = NULL;
2805 static SIMPLE_PATTERN *excluded_mountpoints = NULL;
2806 static SIMPLE_PATTERN *excluded_filesystems = NULL;
2809 if(unlikely(!mount_points)) {
2811 excluded_mountpoints = simple_pattern_create(
2812 config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on paths",
2813 DELAULT_EXLUDED_PATHS),
2814 SIMPLE_PATTERN_EXACT
2817 excluded_filesystems = simple_pattern_create(
2818 config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on filesystems",
2819 DEFAULT_EXCLUDED_FILESYSTEMS),
2820 SIMPLE_PATTERN_EXACT
2823 mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
2826 for (i = 0; i < mntsize; i++) {
2828 char title[4096 + 1];
2829 int def_space, def_inodes, iter_space, iter_inodes;
2831 struct mount_point_metadata *m = dictionary_get(mount_points, mntbuf[i].f_mntonname);
2833 char var_name[4096 + 1];
2834 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETMNTINFO, mntbuf[i].f_mntonname);
2836 def_space = do_space;
2837 def_inodes = do_space;
2839 if(unlikely(simple_pattern_matches(excluded_mountpoints, mntbuf[i].f_mntonname))) {
2840 def_space = CONFIG_BOOLEAN_NO;
2841 def_inodes = CONFIG_BOOLEAN_NO;
2844 if(unlikely(simple_pattern_matches(excluded_filesystems, mntbuf[i].f_fstypename))) {
2845 def_space = CONFIG_BOOLEAN_NO;
2846 def_inodes = CONFIG_BOOLEAN_NO;
2849 iter_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
2850 iter_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
2852 struct mount_point_metadata mp = {
2853 .do_space = iter_space,
2854 .do_inodes = iter_inodes,
2859 .rd_space_avail = NULL,
2860 .rd_space_used = NULL,
2861 .rd_space_reserved = NULL,
2864 .rd_inodes_avail = NULL,
2865 .rd_inodes_used = NULL,
2868 m = dictionary_set(mount_points, mntbuf[i].f_mntonname, &mp, sizeof(struct mount_point_metadata));
2871 if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
2874 if(unlikely(mntbuf[i].f_flags & MNT_RDONLY && !m->collected))
2877 // --------------------------------------------------------------------------
2881 if (m->do_space == CONFIG_BOOLEAN_YES || (m->do_space == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_blocks > 2))) {
2882 if (unlikely(!m->st_space)) {
2883 snprintfz(title, 4096, "Disk Space Usage for %s [%s]",
2884 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2885 m->st_space = rrdset_create_localhost("disk_space",
2886 mntbuf[i].f_mntonname,
2888 mntbuf[i].f_mntonname,
2897 m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL,
2898 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2899 m->rd_space_used = rrddim_add(m->st_space, "used", NULL,
2900 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2901 m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root",
2902 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2904 rrdset_next(m->st_space);
2906 rrddim_set_by_pointer(m->st_space, m->rd_space_avail, (collected_number) mntbuf[i].f_bavail);
2907 rrddim_set_by_pointer(m->st_space, m->rd_space_used, (collected_number) (mntbuf[i].f_blocks -
2908 mntbuf[i].f_bfree));
2909 rrddim_set_by_pointer(m->st_space, m->rd_space_reserved, (collected_number) (mntbuf[i].f_bfree -
2910 mntbuf[i].f_bavail));
2911 rrdset_done(m->st_space);
2916 // --------------------------------------------------------------------------
2918 if (m->do_inodes == CONFIG_BOOLEAN_YES || (m->do_inodes == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_files > 1))) {
2919 if (unlikely(!m->st_inodes)) {
2920 snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]",
2921 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2922 m->st_inodes = rrdset_create_localhost("disk_inodes",
2923 mntbuf[i].f_mntonname,
2925 mntbuf[i].f_mntonname,
2934 m->rd_inodes_avail = rrddim_add(m->st_inodes, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2935 m->rd_inodes_used = rrddim_add(m->st_inodes, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2937 rrdset_next(m->st_inodes);
2939 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_avail, (collected_number) mntbuf[i].f_ffree);
2940 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_used, (collected_number) (mntbuf[i].f_files -
2941 mntbuf[i].f_ffree));
2942 rrdset_done(m->st_inodes);
2947 if(likely(rendered))
2952 error("DISABLED: getmntinfo module");
2959 // --------------------------------------------------------------------------------------------------------------------
2962 int do_getifaddrs(int update_every, usec_t dt) {
2965 #define DELAULT_EXLUDED_INTERFACES "lo*"
2966 #define CONFIG_SECTION_GETIFADDRS "plugin:freebsd:getifaddrs"
2968 static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1,
2969 do_errors = -1, do_drops = -1, do_events = -1;
2971 if (unlikely(do_bandwidth_ipv4 == -1)) {
2972 do_bandwidth_ipv4 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv4 interfaces",
2973 CONFIG_BOOLEAN_AUTO);
2974 do_bandwidth_ipv6 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv6 interfaces",
2975 CONFIG_BOOLEAN_AUTO);
2976 do_bandwidth = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "bandwidth for all interfaces",
2977 CONFIG_BOOLEAN_AUTO);
2978 do_packets = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "packets for all interfaces",
2979 CONFIG_BOOLEAN_AUTO);
2980 do_errors = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "errors for all interfaces",
2981 CONFIG_BOOLEAN_AUTO);
2982 do_drops = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "drops for all interfaces",
2983 CONFIG_BOOLEAN_AUTO);
2984 do_events = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "collisions for all interfaces",
2985 CONFIG_BOOLEAN_AUTO);
2988 if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors ||
2989 do_drops || do_events)) {
2990 struct ifaddrs *ifap;
2992 if (unlikely(getifaddrs(&ifap))) {
2993 error("FREEBSD: getifaddrs() failed");
2994 do_bandwidth_ipv4 = 0;
2995 error("DISABLED: system.ipv4 chart");
2996 do_bandwidth_ipv6 = 0;
2997 error("DISABLED: system.ipv6 chart");
2999 error("DISABLED: net.* charts");
3001 error("DISABLED: net_packets.* charts");
3003 error("DISABLED: net_errors.* charts");
3005 error("DISABLED: net_drops.* charts");
3007 error("DISABLED: net_events.* charts");
3008 error("DISABLED: getifaddrs module");
3011 #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
3012 struct ifaddrs *ifa;
3018 // --------------------------------------------------------------------
3020 if (likely(do_bandwidth_ipv4)) {
3021 iftot.ift_ibytes = iftot.ift_obytes = 0;
3022 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3023 if (ifa->ifa_addr->sa_family != AF_INET)
3025 iftot.ift_ibytes += IFA_DATA(ibytes);
3026 iftot.ift_obytes += IFA_DATA(obytes);
3029 static RRDSET *st = NULL;
3030 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3032 if (unlikely(!st)) {
3033 st = rrdset_create_localhost("system",
3045 rd_in = rrddim_add(st, "InOctets", "received", 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3046 rd_out = rrddim_add(st, "OutOctets", "sent", -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3050 rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3051 rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3055 // --------------------------------------------------------------------
3057 if (likely(do_bandwidth_ipv6)) {
3058 iftot.ift_ibytes = iftot.ift_obytes = 0;
3059 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3060 if (ifa->ifa_addr->sa_family != AF_INET6)
3062 iftot.ift_ibytes += IFA_DATA(ibytes);
3063 iftot.ift_obytes += IFA_DATA(obytes);
3066 static RRDSET *st = NULL;
3067 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3069 if (unlikely(!st)) {
3070 st = rrdset_create_localhost("system",
3082 rd_in = rrddim_add(st, "received", NULL, 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3083 rd_out = rrddim_add(st, "sent", NULL, -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3087 rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3088 rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3092 // --------------------------------------------------------------------
3094 // Data to be stored in DICTIONARY interfaces.
3095 // This DICTIONARY is used to lookup the settings of the interfaces on each iteration.
3096 struct interfaces_metadata {
3103 // charts and dimensions
3105 RRDSET *st_bandwidth;
3106 RRDDIM *rd_bandwidth_in;
3107 RRDDIM *rd_bandwidth_out;
3110 RRDDIM *rd_packets_in;
3111 RRDDIM *rd_packets_out;
3112 RRDDIM *rd_packets_m_in;
3113 RRDDIM *rd_packets_m_out;
3116 RRDDIM *rd_errors_in;
3117 RRDDIM *rd_errors_out;
3120 RRDDIM *rd_drops_in;
3121 RRDDIM *rd_drops_out;
3124 RRDDIM *rd_events_coll;
3126 static DICTIONARY *interfaces = NULL;
3127 static SIMPLE_PATTERN *excluded_interfaces = NULL;
3129 if(unlikely(!interfaces)) {
3131 excluded_interfaces = simple_pattern_create(
3132 config_get(CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching",
3133 DELAULT_EXLUDED_INTERFACES)
3134 , SIMPLE_PATTERN_EXACT
3137 interfaces = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
3140 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3141 if (ifa->ifa_addr->sa_family != AF_LINK)
3144 int def_bandwidth, def_packets, def_errors, def_drops, def_events,
3145 iter_bandwidth, iter_packets, iter_errors, iter_drops, iter_events;
3147 struct interfaces_metadata *ifm = dictionary_get(interfaces, ifa->ifa_name);
3148 if(unlikely(!ifm)) {
3149 char var_name[4096 + 1];
3150 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETIFADDRS, ifa->ifa_name);
3152 def_bandwidth = do_bandwidth;
3153 def_packets = do_packets;
3154 def_errors = do_errors;
3155 def_drops = do_drops;
3156 def_events = do_events;
3158 if(unlikely(simple_pattern_matches(excluded_interfaces, ifa->ifa_name))) {
3159 def_bandwidth = CONFIG_BOOLEAN_NO;
3160 def_packets = CONFIG_BOOLEAN_NO;
3161 def_errors = CONFIG_BOOLEAN_NO;
3162 def_drops = CONFIG_BOOLEAN_NO;
3163 def_events = CONFIG_BOOLEAN_NO;
3166 iter_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", def_bandwidth);
3167 iter_packets = config_get_boolean_ondemand(var_name, "packets", def_packets);
3168 iter_errors = config_get_boolean_ondemand(var_name, "errors", def_errors);
3169 iter_drops = config_get_boolean_ondemand(var_name, "drops", def_drops);
3170 iter_events = config_get_boolean_ondemand(var_name, "events", def_events);
3172 struct interfaces_metadata ifmp = {
3173 .do_bandwidth = iter_bandwidth,
3174 .do_packets = iter_packets,
3175 .do_errors = iter_errors,
3176 .do_drops = iter_drops,
3177 .do_events = iter_events,
3179 .st_bandwidth = NULL,
3180 .rd_bandwidth_in = NULL,
3181 .rd_bandwidth_out = NULL,
3184 .rd_packets_in = NULL,
3185 .rd_packets_out = NULL,
3186 .rd_packets_m_in = NULL,
3187 .rd_packets_m_out = NULL,
3190 .rd_errors_in = NULL,
3191 .rd_errors_out = NULL,
3194 .rd_drops_in = NULL,
3195 .rd_drops_out = NULL,
3198 .rd_events_coll = NULL,
3201 ifm = dictionary_set(interfaces, ifa->ifa_name, &ifmp, sizeof(struct interfaces_metadata));
3204 // --------------------------------------------------------------------
3206 if (ifm->do_bandwidth == CONFIG_BOOLEAN_YES || (ifm->do_bandwidth == CONFIG_BOOLEAN_AUTO &&
3207 (IFA_DATA(ibytes) || IFA_DATA(obytes)))) {
3208 if (unlikely(!ifm->st_bandwidth)) {
3209 ifm->st_bandwidth = rrdset_create_localhost("net",
3221 ifm->rd_bandwidth_in = rrddim_add(ifm->st_bandwidth, "received", NULL, 8, KILO_FACTOR,
3222 RRD_ALGORITHM_INCREMENTAL);
3223 ifm->rd_bandwidth_out = rrddim_add(ifm->st_bandwidth, "sent", NULL, -8, KILO_FACTOR,
3224 RRD_ALGORITHM_INCREMENTAL);
3226 rrdset_next(ifm->st_bandwidth);
3228 rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_in, IFA_DATA(ibytes));
3229 rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_out, IFA_DATA(obytes));
3230 rrdset_done(ifm->st_bandwidth);
3233 // --------------------------------------------------------------------
3235 if (ifm->do_packets == CONFIG_BOOLEAN_YES || (ifm->do_packets == CONFIG_BOOLEAN_AUTO &&
3236 (IFA_DATA(ipackets) || IFA_DATA(opackets) || IFA_DATA(imcasts) || IFA_DATA(omcasts)))) {
3237 if (unlikely(!ifm->st_packets)) {
3238 ifm->st_packets = rrdset_create_localhost("net_packets",
3250 rrdset_flag_set(ifm->st_packets, RRDSET_FLAG_DETAIL);
3252 ifm->rd_packets_in = rrddim_add(ifm->st_packets, "received", NULL, 1, 1,
3253 RRD_ALGORITHM_INCREMENTAL);
3254 ifm->rd_packets_out = rrddim_add(ifm->st_packets, "sent", NULL, -1, 1,
3255 RRD_ALGORITHM_INCREMENTAL);
3256 ifm->rd_packets_m_in = rrddim_add(ifm->st_packets, "multicast_received", NULL, 1, 1,
3257 RRD_ALGORITHM_INCREMENTAL);
3258 ifm->rd_packets_m_out = rrddim_add(ifm->st_packets, "multicast_sent", NULL, -1, 1,
3259 RRD_ALGORITHM_INCREMENTAL);
3261 rrdset_next(ifm->st_packets);
3263 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_in, IFA_DATA(ipackets));
3264 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_out, IFA_DATA(opackets));
3265 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_in, IFA_DATA(imcasts));
3266 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_out, IFA_DATA(omcasts));
3267 rrdset_done(ifm->st_packets);
3270 // --------------------------------------------------------------------
3272 if (ifm->do_errors == CONFIG_BOOLEAN_YES || (ifm->do_errors == CONFIG_BOOLEAN_AUTO &&
3273 (IFA_DATA(ierrors) || IFA_DATA(oerrors)))) {
3274 if (unlikely(!ifm->st_errors)) {
3275 ifm->st_errors = rrdset_create_localhost("net_errors",
3287 rrdset_flag_set(ifm->st_errors, RRDSET_FLAG_DETAIL);
3289 ifm->rd_errors_in = rrddim_add(ifm->st_errors, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3290 ifm->rd_errors_out = rrddim_add(ifm->st_errors, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3292 rrdset_next(ifm->st_errors);
3294 rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_in, IFA_DATA(ierrors));
3295 rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_out, IFA_DATA(oerrors));
3296 rrdset_done(ifm->st_errors);
3298 // --------------------------------------------------------------------
3300 if (ifm->do_drops == CONFIG_BOOLEAN_YES || (ifm->do_drops == CONFIG_BOOLEAN_AUTO &&
3302 #if __FreeBSD__ >= 11
3303 || IFA_DATA(oqdrops)
3306 if (unlikely(!ifm->st_drops)) {
3307 ifm->st_drops = rrdset_create_localhost("net_drops",
3319 rrdset_flag_set(ifm->st_drops, RRDSET_FLAG_DETAIL);
3321 ifm->rd_drops_in = rrddim_add(ifm->st_drops, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3322 #if __FreeBSD__ >= 11
3323 ifm->rd_drops_out = rrddim_add(ifm->st_drops, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3326 rrdset_next(ifm->st_drops);
3328 rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_in, IFA_DATA(iqdrops));
3329 #if __FreeBSD__ >= 11
3330 rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_out, IFA_DATA(oqdrops));
3332 rrdset_done(ifm->st_drops);
3335 // --------------------------------------------------------------------
3337 if (ifm->do_events == CONFIG_BOOLEAN_YES || (ifm->do_events == CONFIG_BOOLEAN_AUTO &&
3338 IFA_DATA(collisions))) {
3339 if (unlikely(!ifm->st_events)) {
3340 ifm->st_events = rrdset_create_localhost("net_events",
3345 "Network Interface Events",
3352 rrdset_flag_set(ifm->st_events, RRDSET_FLAG_DETAIL);
3354 ifm->rd_events_coll = rrddim_add(ifm->st_events, "collisions", NULL, -1, 1,
3355 RRD_ALGORITHM_INCREMENTAL);
3357 rrdset_next(ifm->st_events);
3359 rrddim_set_by_pointer(ifm->st_events, ifm->rd_events_coll, IFA_DATA(collisions));
3360 rrdset_done(ifm->st_events);
3367 error("DISABLED: getifaddrs module");
3374 // --------------------------------------------------------------------------------------------------------------------
3377 int do_kern_devstat(int update_every, usec_t dt) {
3379 #define DELAULT_EXLUDED_DISKS ""
3380 #define CONFIG_SECTION_KERN_DEVSTAT "plugin:freebsd:kern.devstat"
3381 #define BINTIME_SCALE 5.42101086242752217003726400434970855712890625e-17 // this is 1000/2^64
3383 static int enable_pass_devices = -1, do_system_io = -1, do_io = -1, do_ops = -1, do_qops = -1, do_util = -1,
3384 do_iotime = -1, do_await = -1, do_avagsz = -1, do_svctm = -1;
3386 if (unlikely(enable_pass_devices == -1)) {
3387 enable_pass_devices = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT,
3388 "performance metrics for pass devices", CONFIG_BOOLEAN_AUTO);
3390 do_system_io = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "total bandwidth for all disks",
3391 CONFIG_BOOLEAN_YES);
3393 do_io = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "bandwidth for all disks",
3394 CONFIG_BOOLEAN_AUTO);
3395 do_ops = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "operations for all disks",
3396 CONFIG_BOOLEAN_AUTO);
3397 do_qops = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "queued operations for all disks",
3398 CONFIG_BOOLEAN_AUTO);
3399 do_util = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "utilization percentage for all disks",
3400 CONFIG_BOOLEAN_AUTO);
3401 do_iotime = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "i/o time for all disks",
3402 CONFIG_BOOLEAN_AUTO);
3403 do_await = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average completed i/o time for all disks",
3404 CONFIG_BOOLEAN_AUTO);
3405 do_avagsz = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average completed i/o bandwidth for all disks",
3406 CONFIG_BOOLEAN_AUTO);
3407 do_svctm = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average service time for all disks",
3408 CONFIG_BOOLEAN_AUTO);
3411 if (likely(do_system_io || do_io || do_ops || do_qops || do_util || do_iotime || do_await || do_avagsz || do_svctm)) {
3412 static int mib_numdevs[3] = {0, 0, 0};
3414 int common_error = 0;
3416 if (unlikely(GETSYSCTL_SIMPLE("kern.devstat.numdevs", mib_numdevs, numdevs))) {
3419 static int mib_devstat[3] = {0, 0, 0};
3420 static void *devstat_data = NULL;
3422 devstat_data = reallocz(devstat_data, sizeof(long) + sizeof(struct devstat) * numdevs); // there is generation number before devstat structures
3423 if (unlikely(GETSYSCTL_WSIZE("kern.devstat.all", mib_devstat, devstat_data,
3424 sizeof(long) + sizeof(struct devstat) * numdevs))) {
3427 struct devstat *dstat;
3429 collected_number total_disk_kbytes_read = 0;
3430 collected_number total_disk_kbytes_write = 0;
3432 // Data to be stored in DICTIONARY disks.
3433 // This DICTIONARY is used to lookup the settings of the disks on each iteration.
3434 struct disks_metadata {
3445 // data for differential charts
3448 collected_number bytes_read;
3449 collected_number bytes_write;
3450 collected_number operations_read;
3451 collected_number operations_write;
3452 collected_number duration_read_ms;
3453 collected_number duration_write_ms;
3454 collected_number busy_time_ms;
3457 // charts and dimensions
3474 RRDDIM *rd_iotime_in;
3475 RRDDIM *rd_iotime_out;
3478 RRDDIM *rd_await_in;
3479 RRDDIM *rd_await_out;
3482 RRDDIM *rd_avagsz_in;
3483 RRDDIM *rd_avagsz_out;
3489 static DICTIONARY *disks = NULL;
3490 static SIMPLE_PATTERN *excluded_disks = NULL;
3492 if(unlikely(!disks)) {
3494 excluded_disks = simple_pattern_create(
3495 config_get(CONFIG_SECTION_KERN_DEVSTAT, "disable by default disks matching",
3496 DELAULT_EXLUDED_DISKS)
3497 , SIMPLE_PATTERN_EXACT
3500 disks = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
3503 dstat = devstat_data + sizeof(long); // skip generation number
3505 for (i = 0; i < numdevs; i++) {
3506 if (likely(do_system_io)) {
3507 if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
3508 total_disk_kbytes_read += dstat[i].bytes[DEVSTAT_READ] / KILO_FACTOR;
3509 total_disk_kbytes_write += dstat[i].bytes[DEVSTAT_WRITE] / KILO_FACTOR;
3513 if (unlikely(!enable_pass_devices))
3514 if ((dstat[i].device_type & DEVSTAT_TYPE_PASS) == DEVSTAT_TYPE_PASS)
3517 if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
3518 char disk[DEVSTAT_NAME_LEN + MAX_INT_DIGITS + 1];
3519 int def_io, def_ops, def_qops, def_util, def_iotime, def_await, def_avagsz, def_svctm,
3520 iter_io, iter_ops, iter_qops, iter_util, iter_iotime, iter_await, iter_avagsz, iter_svctm;
3522 collected_number duration_read_ms;
3523 collected_number duration_write_ms;
3524 collected_number busy_time_ms;
3527 sprintf(disk, "%s%d", dstat[i].device_name, dstat[i].unit_number);
3529 struct disks_metadata *dm = dictionary_get(disks, disk);
3531 char var_name[4096 + 1];
3532 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_KERN_DEVSTAT, disk);
3538 def_iotime = do_iotime;
3539 def_await = do_await;
3540 def_avagsz = do_avagsz;
3541 def_svctm = do_svctm;
3543 if(unlikely(simple_pattern_matches(excluded_disks, disk))) {
3544 def_io = CONFIG_BOOLEAN_NO;
3545 def_ops = CONFIG_BOOLEAN_NO;
3546 def_qops = CONFIG_BOOLEAN_NO;
3547 def_util = CONFIG_BOOLEAN_NO;
3548 def_iotime = CONFIG_BOOLEAN_NO;
3549 def_await = CONFIG_BOOLEAN_NO;
3550 def_avagsz = CONFIG_BOOLEAN_NO;
3551 def_svctm = CONFIG_BOOLEAN_NO;
3554 iter_io = config_get_boolean_ondemand(var_name, "bandwidth", def_io);
3555 iter_ops = config_get_boolean_ondemand(var_name, "operations", def_ops);
3556 iter_qops = config_get_boolean_ondemand(var_name, "queued operations", def_qops);
3557 iter_util = config_get_boolean_ondemand(var_name, "utilization percentage", def_util);
3558 iter_iotime = config_get_boolean_ondemand(var_name, "i/o time", def_iotime);
3559 iter_await = config_get_boolean_ondemand(var_name, "average completed i/o time", def_await);
3560 iter_avagsz = config_get_boolean_ondemand(var_name, "average completed i/o bandwidth",
3562 iter_svctm = config_get_boolean_ondemand(var_name, "average service time", def_svctm);
3564 struct disks_metadata dmp = {
3567 .do_qops = iter_qops,
3568 .do_util = iter_util,
3569 .do_iotime = iter_iotime,
3570 .do_await = iter_await,
3571 .do_avagsz = iter_avagsz,
3572 .do_svctm = iter_svctm,
3589 .rd_iotime_in = NULL,
3590 .rd_iotime_out = NULL,
3593 .rd_await_in = NULL,
3594 .rd_await_out = NULL,
3597 .rd_avagsz_in = NULL,
3598 .rd_avagsz_out = NULL,
3604 // initialise data for differential charts
3606 dmp.prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ];
3607 dmp.prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE];
3608 dmp.prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ];
3609 dmp.prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE];
3610 dmp.prev_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
3611 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3612 dmp.prev_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
3613 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3614 dmp.prev_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000
3615 + dstat[i].busy_time.frac * BINTIME_SCALE;
3617 dm = dictionary_set(disks, disk, &dmp, sizeof(struct disks_metadata));
3620 cur_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
3621 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3622 cur_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
3623 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3624 cur_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000 + dstat[i].busy_time.frac * BINTIME_SCALE;
3626 // --------------------------------------------------------------------
3628 if(dm->do_io == CONFIG_BOOLEAN_YES || (dm->do_io == CONFIG_BOOLEAN_AUTO &&
3629 (dstat[i].bytes[DEVSTAT_READ] || dstat[i].bytes[DEVSTAT_WRITE]))) {
3630 if (unlikely(!dm->st_io)) {
3631 dm->st_io = rrdset_create_localhost("disk",
3636 "Disk I/O Bandwidth",
3643 dm->rd_io_in = rrddim_add(dm->st_io, "reads", NULL, 1, KILO_FACTOR,
3644 RRD_ALGORITHM_INCREMENTAL);
3645 dm->rd_io_out = rrddim_add(dm->st_io, "writes", NULL, -1, KILO_FACTOR,
3646 RRD_ALGORITHM_INCREMENTAL);
3648 rrdset_next(dm->st_io);
3650 rrddim_set_by_pointer(dm->st_io, dm->rd_io_in, dstat[i].bytes[DEVSTAT_READ]);
3651 rrddim_set_by_pointer(dm->st_io, dm->rd_io_out, dstat[i].bytes[DEVSTAT_WRITE]);
3652 rrdset_done(dm->st_io);
3655 // --------------------------------------------------------------------
3657 if(dm->do_ops == CONFIG_BOOLEAN_YES || (dm->do_ops == CONFIG_BOOLEAN_AUTO &&
3658 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3659 if (unlikely(!dm->st_ops)) {
3660 dm->st_ops = rrdset_create_localhost("disk_ops",
3665 "Disk Completed I/O Operations",
3672 rrdset_flag_set(dm->st_ops, RRDSET_FLAG_DETAIL);
3674 dm->rd_ops_in = rrddim_add(dm->st_ops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3675 dm->rd_ops_out = rrddim_add(dm->st_ops, "writes", NULL, -1, 1,
3676 RRD_ALGORITHM_INCREMENTAL);
3678 rrdset_next(dm->st_ops);
3680 rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_in, dstat[i].operations[DEVSTAT_READ]);
3681 rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_out, dstat[i].operations[DEVSTAT_WRITE]);
3682 rrdset_done(dm->st_ops);
3685 // --------------------------------------------------------------------
3687 if(dm->do_qops == CONFIG_BOOLEAN_YES || (dm->do_qops == CONFIG_BOOLEAN_AUTO &&
3688 (dstat[i].start_count || dstat[i].end_count))) {
3689 if (unlikely(!dm->st_qops)) {
3690 dm->st_qops = rrdset_create_localhost("disk_qops",
3695 "Disk Current I/O Operations",
3702 rrdset_flag_set(dm->st_qops, RRDSET_FLAG_DETAIL);
3704 dm->rd_qops = rrddim_add(dm->st_qops, "operations", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3706 rrdset_next(dm->st_qops);
3708 rrddim_set_by_pointer(dm->st_qops, dm->rd_qops, dstat[i].start_count - dstat[i].end_count);
3709 rrdset_done(dm->st_qops);
3712 // --------------------------------------------------------------------
3714 if(dm->do_util == CONFIG_BOOLEAN_YES || (dm->do_util == CONFIG_BOOLEAN_AUTO &&
3715 cur_dstat.busy_time_ms)) {
3716 if (unlikely(!dm->st_util)) {
3717 dm->st_util = rrdset_create_localhost("disk_util",
3722 "Disk Utilization Time",
3723 "% of time working",
3729 rrdset_flag_set(dm->st_util, RRDSET_FLAG_DETAIL);
3731 dm->rd_util = rrddim_add(dm->st_util, "utilization", NULL, 1, 10,
3732 RRD_ALGORITHM_INCREMENTAL);
3734 rrdset_next(dm->st_util);
3736 rrddim_set_by_pointer(dm->st_util, dm->rd_util, cur_dstat.busy_time_ms);
3737 rrdset_done(dm->st_util);
3740 // --------------------------------------------------------------------
3742 if(dm->do_iotime == CONFIG_BOOLEAN_YES || (dm->do_iotime == CONFIG_BOOLEAN_AUTO &&
3743 (cur_dstat.duration_read_ms || cur_dstat.duration_write_ms))) {
3744 if (unlikely(!dm->st_iotime)) {
3745 dm->st_iotime = rrdset_create_localhost("disk_iotime",
3750 "Disk Total I/O Time",
3757 rrdset_flag_set(dm->st_iotime, RRDSET_FLAG_DETAIL);
3759 dm->rd_iotime_in = rrddim_add(dm->st_iotime, "reads", NULL, 1, 1,
3760 RRD_ALGORITHM_INCREMENTAL);
3761 dm->rd_iotime_out = rrddim_add(dm->st_iotime, "writes", NULL, -1, 1,
3762 RRD_ALGORITHM_INCREMENTAL);
3764 rrdset_next(dm->st_iotime);
3766 rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_in, cur_dstat.duration_read_ms);
3767 rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_out, cur_dstat.duration_write_ms);
3768 rrdset_done(dm->st_iotime);
3771 // --------------------------------------------------------------------
3772 // calculate differential charts
3773 // only if this is not the first time we run
3777 // --------------------------------------------------------------------
3779 if(dm->do_await == CONFIG_BOOLEAN_YES || (dm->do_await == CONFIG_BOOLEAN_AUTO &&
3780 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3781 if (unlikely(!dm->st_await)) {
3782 dm->st_await = rrdset_create_localhost("disk_await",
3787 "Average Completed I/O Operation Time",
3794 rrdset_flag_set(dm->st_await, RRDSET_FLAG_DETAIL);
3796 dm->rd_await_in = rrddim_add(dm->st_await, "reads", NULL, 1, 1,
3797 RRD_ALGORITHM_ABSOLUTE);
3798 dm->rd_await_out = rrddim_add(dm->st_await, "writes", NULL, -1, 1,
3799 RRD_ALGORITHM_ABSOLUTE);
3801 rrdset_next(dm->st_await);
3803 rrddim_set_by_pointer(dm->st_await, dm->rd_await_in,
3804 (dstat[i].operations[DEVSTAT_READ] -
3805 dm->prev_dstat.operations_read) ?
3806 (cur_dstat.duration_read_ms - dm->prev_dstat.duration_read_ms) /
3807 (dstat[i].operations[DEVSTAT_READ] -
3808 dm->prev_dstat.operations_read) :
3810 rrddim_set_by_pointer(dm->st_await, dm->rd_await_out,
3811 (dstat[i].operations[DEVSTAT_WRITE] -
3812 dm->prev_dstat.operations_write) ?
3813 (cur_dstat.duration_write_ms - dm->prev_dstat.duration_write_ms) /
3814 (dstat[i].operations[DEVSTAT_WRITE] -
3815 dm->prev_dstat.operations_write) :
3817 rrdset_done(dm->st_await);
3820 // --------------------------------------------------------------------
3822 if(dm->do_avagsz == CONFIG_BOOLEAN_YES || (dm->do_avagsz == CONFIG_BOOLEAN_AUTO &&
3823 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3824 if (unlikely(!dm->st_avagsz)) {
3825 dm->st_avagsz = rrdset_create_localhost("disk_avgsz",
3830 "Average Completed I/O Operation Bandwidth",
3831 "kilobytes per operation",
3837 rrdset_flag_set(dm->st_avagsz, RRDSET_FLAG_DETAIL);
3839 dm->rd_avagsz_in = rrddim_add(dm->st_avagsz, "reads", NULL, 1, KILO_FACTOR,
3840 RRD_ALGORITHM_ABSOLUTE);
3841 dm->rd_avagsz_out = rrddim_add(dm->st_avagsz, "writes", NULL, -1, KILO_FACTOR,
3842 RRD_ALGORITHM_ABSOLUTE);
3844 rrdset_next(dm->st_avagsz);
3846 rrddim_set_by_pointer(dm->st_avagsz, dm->rd_avagsz_in,
3847 (dstat[i].operations[DEVSTAT_READ] -
3848 dm->prev_dstat.operations_read) ?
3849 (dstat[i].bytes[DEVSTAT_READ] - dm->prev_dstat.bytes_read) /
3850 (dstat[i].operations[DEVSTAT_READ] -
3851 dm->prev_dstat.operations_read) :
3853 rrddim_set_by_pointer(dm->st_avagsz, dm->rd_avagsz_out,
3854 (dstat[i].operations[DEVSTAT_WRITE] -
3855 dm->prev_dstat.operations_write) ?
3856 (dstat[i].bytes[DEVSTAT_WRITE] - dm->prev_dstat.bytes_write) /
3857 (dstat[i].operations[DEVSTAT_WRITE] -
3858 dm->prev_dstat.operations_write) :
3860 rrdset_done(dm->st_avagsz);
3863 // --------------------------------------------------------------------
3865 if(dm->do_svctm == CONFIG_BOOLEAN_YES || (dm->do_svctm == CONFIG_BOOLEAN_AUTO &&
3866 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3867 if (unlikely(!dm->st_svctm)) {
3868 dm->st_svctm = rrdset_create_localhost("disk_svctm",
3873 "Average Service Time",
3880 rrdset_flag_set(dm->st_svctm, RRDSET_FLAG_DETAIL);
3882 dm->rd_svctm = rrddim_add(dm->st_svctm, "svctm", NULL, 1, 1,
3883 RRD_ALGORITHM_ABSOLUTE);
3885 rrdset_next(dm->st_svctm);
3887 rrddim_set_by_pointer(dm->st_svctm, dm->rd_svctm,
3888 ((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
3889 (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) ?
3890 (cur_dstat.busy_time_ms - dm->prev_dstat.busy_time_ms) /
3891 ((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
3892 (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) :
3894 rrdset_done(dm->st_svctm);
3897 // --------------------------------------------------------------------
3899 dm->prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ];
3900 dm->prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE];
3901 dm->prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ];
3902 dm->prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE];
3903 dm->prev_dstat.duration_read_ms = cur_dstat.duration_read_ms;
3904 dm->prev_dstat.duration_write_ms = cur_dstat.duration_write_ms;
3905 dm->prev_dstat.busy_time_ms = cur_dstat.busy_time_ms;
3910 // --------------------------------------------------------------------
3912 if (likely(do_system_io)) {
3913 static RRDSET *st = NULL;
3914 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3916 if (unlikely(!st)) {
3917 st = rrdset_create_localhost("system",
3929 rd_in = rrddim_add(st, "in", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3930 rd_out = rrddim_add(st, "out", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3934 rrddim_set_by_pointer(st, rd_in, total_disk_kbytes_read);
3935 rrddim_set_by_pointer(st, rd_out, total_disk_kbytes_write);
3940 if (unlikely(common_error)) {
3942 error("DISABLED: system.io chart");
3944 error("DISABLED: disk.* charts");
3946 error("DISABLED: disk_ops.* charts");
3948 error("DISABLED: disk_qops.* charts");
3950 error("DISABLED: disk_util.* charts");
3952 error("DISABLED: disk_iotime.* charts");
3954 error("DISABLED: disk_await.* charts");
3956 error("DISABLED: disk_avgsz.* charts");
3958 error("DISABLED: disk_svctm.* charts");
3959 error("DISABLED: kern.devstat module");
3963 error("DISABLED: kern.devstat module");