3 #include <sys/vmmeter.h>
4 #include <sys/devicestat.h>
6 #include <vm/vm_param.h>
14 #include <net/netisr.h>
18 #include <netinet/ip.h>
19 #include <netinet/ip_var.h>
20 #include <netinet/ip_icmp.h>
21 #include <netinet/icmp_var.h>
22 #include <netinet6/ip6_var.h>
23 #include <netinet/icmp6.h>
24 #include <netinet/tcp_var.h>
25 #include <netinet/tcp_fsm.h>
26 #include <netinet/udp.h>
27 #include <netinet/udp_var.h>
29 // --------------------------------------------------------------------------------------------------------------------
30 // common definitions and variables
32 #define KILO_FACTOR 1024
33 #define MEGA_FACTOR 1048576 // 1024 * 1024
34 #define GIGA_FACTOR 1073741824 // 1024 * 1024 * 1024
36 #define MAX_INT_DIGITS 10 // maximum number of digits for int
38 int system_pagesize = PAGE_SIZE;
39 int number_of_cpus = 1;
41 // --------------------------------------------------------------------------------------------------------------------
42 // FreeBSD plugin initialization
44 int freebsd_plugin_init()
46 system_pagesize = getpagesize();
47 if (system_pagesize <= 0) {
48 error("FREEBSD: can't get system page size");
52 if (unlikely(GETSYSCTL_BY_NAME("kern.smp.cpus", number_of_cpus))) {
53 error("FREEBSD: can't get number of cpus");
57 if (unlikely(!number_of_cpus)) {
58 error("FREEBSD: wrong number of cpus");
65 // --------------------------------------------------------------------------------------------------------------------
68 // FreeBSD calculates load averages once every 5 seconds
69 #define MIN_LOADAVG_UPDATE_EVERY 5
71 int do_vm_loadavg(int update_every, usec_t dt){
72 static usec_t next_loadavg_dt = 0;
74 if (next_loadavg_dt <= dt) {
75 static int mib[2] = {0, 0};
76 struct loadavg sysload;
78 if (unlikely(GETSYSCTL_SIMPLE("vm.loadavg", mib, sysload))) {
79 error("DISABLED: system.load chart");
80 error("DISABLED: vm.loadavg module");
84 // --------------------------------------------------------------------
86 static RRDSET *st = NULL;
87 static RRDDIM *rd_load1 = NULL, *rd_load2 = NULL, *rd_load3 = NULL;
90 st = rrdset_create_localhost("system",
95 "System Load Average",
98 (update_every < MIN_LOADAVG_UPDATE_EVERY) ?
99 MIN_LOADAVG_UPDATE_EVERY : update_every, RRDSET_TYPE_LINE
101 rd_load1 = rrddim_add(st, "load1", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
102 rd_load2 = rrddim_add(st, "load5", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
103 rd_load3 = rrddim_add(st, "load15", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
107 rrddim_set_by_pointer(st, rd_load1, (collected_number) ((double) sysload.ldavg[0] / sysload.fscale * 1000));
108 rrddim_set_by_pointer(st, rd_load2, (collected_number) ((double) sysload.ldavg[1] / sysload.fscale * 1000));
109 rrddim_set_by_pointer(st, rd_load3, (collected_number) ((double) sysload.ldavg[2] / sysload.fscale * 1000));
112 next_loadavg_dt = st->update_every * USEC_PER_SEC;
116 next_loadavg_dt -= dt;
121 // --------------------------------------------------------------------------------------------------------------------
124 int do_vm_vmtotal(int update_every, usec_t dt) {
125 static int do_all_processes = -1, do_processes = -1, do_committed = -1;
127 if (unlikely(do_all_processes == -1)) {
128 do_all_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "enable total processes", 1);
129 do_processes = config_get_boolean("plugin:freebsd:vm.vmtotal", "processes running", 1);
130 do_committed = config_get_boolean("plugin:freebsd:vm.vmtotal", "committed memory", 1);
133 if (likely(do_all_processes | do_processes | do_committed)) {
134 static int mib[2] = {0, 0};
135 struct vmtotal vmtotal_data;
137 if (unlikely(GETSYSCTL_SIMPLE("vm.vmtotal", mib, vmtotal_data))) {
138 do_all_processes = 0;
139 error("DISABLED: system.active_processes chart");
141 error("DISABLED: system.processes chart");
143 error("DISABLED: mem.committed chart");
144 error("DISABLED: vm.vmtotal module");
148 // --------------------------------------------------------------------
150 if (likely(do_all_processes)) {
151 static RRDSET *st = NULL;
152 static RRDDIM *rd = NULL;
155 st = rrdset_create_localhost("system",
160 "System Active Processes",
166 rd = rrddim_add(st, "active", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
168 else rrdset_next(st);
170 rrddim_set_by_pointer(st, rd, (vmtotal_data.t_rq + vmtotal_data.t_dw + vmtotal_data.t_pw + vmtotal_data.t_sl + vmtotal_data.t_sw));
174 // --------------------------------------------------------------------
176 if (likely(do_processes)) {
177 static RRDSET *st = NULL;
178 static RRDDIM *rd_running = NULL, *rd_blocked = NULL;
181 st = rrdset_create_localhost("system",
193 rd_running = rrddim_add(st, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
194 rd_blocked = rrddim_add(st, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
196 else rrdset_next(st);
198 rrddim_set_by_pointer(st, rd_running, vmtotal_data.t_rq);
199 rrddim_set_by_pointer(st, rd_blocked, (vmtotal_data.t_dw + vmtotal_data.t_pw));
203 // --------------------------------------------------------------------
205 if (likely(do_committed)) {
206 static RRDSET *st = NULL;
207 static RRDDIM *rd = NULL;
210 st = rrdset_create_localhost("mem",
215 "Committed (Allocated) Memory",
221 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
223 rd = rrddim_add(st, "Committed_AS", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
225 else rrdset_next(st);
227 rrddim_set_by_pointer(st, rd, vmtotal_data.t_rm);
232 error("DISABLED: vm.vmtotal module");
239 // --------------------------------------------------------------------------------------------------------------------
242 int do_kern_cp_time(int update_every, usec_t dt) {
243 if (unlikely(CPUSTATES != 5)) {
244 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
245 error("DISABLED: system.cpu chart");
246 error("DISABLED: kern.cp_time module");
249 static int mib[2] = {0, 0};
250 long cp_time[CPUSTATES];
252 if (unlikely(GETSYSCTL_SIMPLE("kern.cp_time", mib, cp_time))) {
253 error("DISABLED: system.cpu chart");
254 error("DISABLED: kern.cp_time module");
258 // --------------------------------------------------------------------
260 static RRDSET *st = NULL;
261 static RRDDIM *rd_nice = NULL, *rd_system = NULL, *rd_user = NULL, *rd_interrupt = NULL, *rd_idle = NULL;
264 st = rrdset_create_localhost("system",
269 "Total CPU utilization",
275 rd_nice = rrddim_add(st, "nice", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
276 rd_system = rrddim_add(st, "system", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
277 rd_user = rrddim_add(st, "user", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
278 rd_interrupt = rrddim_add(st, "interrupt", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
279 rd_idle = rrddim_add(st, "idle", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
280 rrddim_hide(st, "idle");
282 else rrdset_next(st);
284 rrddim_set_by_pointer(st, rd_nice, cp_time[1]);
285 rrddim_set_by_pointer(st, rd_system, cp_time[2]);
286 rrddim_set_by_pointer(st, rd_user, cp_time[0]);
287 rrddim_set_by_pointer(st, rd_interrupt, cp_time[3]);
288 rrddim_set_by_pointer(st, rd_idle, cp_time[4]);
296 // --------------------------------------------------------------------------------------------------------------------
299 int do_kern_cp_times(int update_every, usec_t dt) {
300 if (unlikely(CPUSTATES != 5)) {
301 error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
302 error("DISABLED: cpu.cpuXX charts");
303 error("DISABLED: kern.cp_times module");
306 static int mib[2] = {0, 0};
307 long cp_time[CPUSTATES];
308 static long *pcpu_cp_time = NULL;
310 pcpu_cp_time = reallocz(pcpu_cp_time, sizeof(cp_time) * number_of_cpus);
311 if (unlikely(GETSYSCTL_WSIZE("kern.cp_times", mib, pcpu_cp_time, sizeof(cp_time) * number_of_cpus))) {
312 error("DISABLED: cpu.cpuXX charts");
313 error("DISABLED: kern.cp_times module");
317 // --------------------------------------------------------------------
320 static struct cpu_chart {
321 char cpuid[MAX_INT_DIGITS + 4];
326 RRDDIM *rd_interrupt;
328 } *all_cpu_charts = NULL;
329 static int old_number_of_cpus = 0;
331 if(unlikely(number_of_cpus > old_number_of_cpus)) {
332 all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus);
333 memset(&all_cpu_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus));
334 old_number_of_cpus = number_of_cpus;
337 for (i = 0; i < number_of_cpus; i++) {
338 if (unlikely(!all_cpu_charts[i].st)) {
339 snprintfz(all_cpu_charts[i].cpuid, MAX_INT_DIGITS, "cpu%d", i);
340 all_cpu_charts[i].st = rrdset_create_localhost("cpu",
341 all_cpu_charts[i].cpuid,
352 all_cpu_charts[i].rd_nice = rrddim_add(all_cpu_charts[i].st, "nice", NULL, 1, 1,
353 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
354 all_cpu_charts[i].rd_system = rrddim_add(all_cpu_charts[i].st, "system", NULL, 1, 1,
355 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
356 all_cpu_charts[i].rd_user = rrddim_add(all_cpu_charts[i].st, "user", NULL, 1, 1,
357 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
358 all_cpu_charts[i].rd_interrupt = rrddim_add(all_cpu_charts[i].st, "interrupt", NULL, 1, 1,
359 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
360 all_cpu_charts[i].rd_idle = rrddim_add(all_cpu_charts[i].st, "idle", NULL, 1, 1,
361 RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
362 rrddim_hide(all_cpu_charts[i].st, "idle");
363 } else rrdset_next(all_cpu_charts[i].st);
365 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_nice, pcpu_cp_time[i * 5 + 1]);
366 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_system, pcpu_cp_time[i * 5 + 2]);
367 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_user, pcpu_cp_time[i * 5 + 0]);
368 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_interrupt, pcpu_cp_time[i * 5 + 3]);
369 rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_idle, pcpu_cp_time[i * 5 + 4]);
370 rrdset_done(all_cpu_charts[i].st);
378 // --------------------------------------------------------------------------------------------------------------------
381 int do_hw_intcnt(int update_every, usec_t dt) {
382 static int mib_hw_intrcnt[2] = {0, 0};
386 if (unlikely(GETSYSCTL_SIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt_size))) {
387 error("DISABLED: system.intr chart");
388 error("DISABLED: system.interrupts chart");
389 error("DISABLED: hw.intrcnt module");
392 unsigned long nintr = 0;
393 static unsigned long *intrcnt = NULL;
394 unsigned long long totalintr = 0;
396 nintr = intrcnt_size / sizeof(u_long);
397 intrcnt = reallocz(intrcnt, nintr * sizeof(u_long));
398 if (unlikely(GETSYSCTL_WSIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt, nintr * sizeof(u_long)))) {
399 error("DISABLED: system.intr chart");
400 error("DISABLED: system.interrupts chart");
401 error("DISABLED: hw.intrcnt module");
404 for (i = 0; i < nintr; i++)
405 totalintr += intrcnt[i];
407 // --------------------------------------------------------------------
409 static RRDSET *st_intr = NULL;
410 static RRDDIM *rd_intr = NULL;
412 if (unlikely(!st_intr)) {
413 st_intr = rrdset_create_localhost("system",
418 "Total Hardware Interrupts",
424 rrdset_flag_set(st_intr, RRDSET_FLAG_DETAIL);
426 rd_intr = rrddim_add(st_intr, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
428 rrdset_next(st_intr);
430 rrddim_set_by_pointer(st_intr, rd_intr, totalintr);
431 rrdset_done(st_intr);
433 // --------------------------------------------------------------------
436 static int mib_hw_intrnames[2] = {0, 0};
437 static char *intrnames = NULL;
439 size = nintr * (MAXCOMLEN + 1);
440 intrnames = reallocz(intrnames, size);
441 if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) {
442 error("DISABLED: system.intr chart");
443 error("DISABLED: system.interrupts chart");
444 error("DISABLED: hw.intrcnt module");
448 // --------------------------------------------------------------------
450 static RRDSET *st_interrupts = NULL;
451 RRDDIM *rd_interrupts = NULL;
454 if (unlikely(!st_interrupts))
455 st_interrupts = rrdset_create_localhost("system",
467 rrdset_next(st_interrupts);
469 for (i = 0; i < nintr; i++) {
470 p = intrnames + i * (MAXCOMLEN + 1);
471 if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
472 rd_interrupts = rrddim_find(st_interrupts, p);
473 if (unlikely(!rd_interrupts))
474 rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
475 rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
478 rrdset_done(st_interrupts);
486 // --------------------------------------------------------------------------------------------------------------------
487 // vm.stats.sys.v_intr
489 int do_vm_stats_sys_v_intr(int update_every, usec_t dt) {
490 static int mib[4] = {0, 0, 0, 0};
493 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_intr", mib, int_number))) {
494 error("DISABLED: system.dev_intr chart");
495 error("DISABLED: vm.stats.sys.v_intr module");
499 // --------------------------------------------------------------------
501 static RRDSET *st = NULL;
502 static RRDDIM *rd = NULL;
505 st = rrdset_create_localhost("system",
517 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
519 else rrdset_next(st);
521 rrddim_set_by_pointer(st, rd, int_number);
528 // --------------------------------------------------------------------------------------------------------------------
529 // vm.stats.sys.v_soft
531 int do_vm_stats_sys_v_soft(int update_every, usec_t dt) {
532 static int mib[4] = {0, 0, 0, 0};
533 u_int soft_intr_number;
535 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_soft", mib, soft_intr_number))) {
536 error("DISABLED: system.dev_intr chart");
537 error("DISABLED: vm.stats.sys.v_soft module");
541 // --------------------------------------------------------------------
543 static RRDSET *st = NULL;
544 static RRDDIM *rd = NULL;
547 st = rrdset_create_localhost("system",
552 "Software Interrupts",
559 rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
561 else rrdset_next(st);
563 rrddim_set_by_pointer(st, rd, soft_intr_number);
570 // --------------------------------------------------------------------------------------------------------------------
571 // vm.stats.sys.v_swtch
573 int do_vm_stats_sys_v_swtch(int update_every, usec_t dt) {
574 static int mib[4] = {0, 0, 0, 0};
577 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_swtch", mib, ctxt_number))) {
578 error("DISABLED: system.ctxt chart");
579 error("DISABLED: vm.stats.sys.v_swtch module");
583 // --------------------------------------------------------------------
585 static RRDSET *st = NULL;
586 static RRDDIM *rd = NULL;
589 st = rrdset_create_localhost("system",
594 "CPU Context Switches",
595 "context switches/s",
601 rd = rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
603 else rrdset_next(st);
605 rrddim_set_by_pointer(st, rd, ctxt_number);
612 // --------------------------------------------------------------------------------------------------------------------
613 // vm.stats.vm.v_forks
615 int do_vm_stats_sys_v_forks(int update_every, usec_t dt) {
616 static int mib[4] = {0, 0, 0, 0};
619 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_forks", mib, forks_number))) {
620 error("DISABLED: system.forks chart");
621 error("DISABLED: vm.stats.sys.v_swtch module");
625 // --------------------------------------------------------------------
627 static RRDSET *st = NULL;
628 static RRDDIM *rd = NULL;
631 st = rrdset_create_localhost("system",
643 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
645 rd = rrddim_add(st, "started", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
647 else rrdset_next(st);
649 rrddim_set_by_pointer(st, rd, forks_number);
656 // --------------------------------------------------------------------------------------------------------------------
659 int do_vm_swap_info(int update_every, usec_t dt) {
660 static int mib[3] = {0, 0, 0};
662 if (unlikely(getsysctl_mib("vm.swap_info", mib, 2))) {
663 error("DISABLED: system.swap chart");
664 error("DISABLED: vm.swap_info module");
670 collected_number bytes_used;
671 collected_number bytes_total;
672 } total_xsw = {0, 0};
679 if (unlikely(sysctl(mib, 3, &xsw, &size, NULL, 0) == -1 )) {
680 if (unlikely(errno != ENOENT)) {
681 error("FREEBSD: sysctl(%s...) failed: %s", "vm.swap_info", strerror(errno));
682 error("DISABLED: system.swap chart");
683 error("DISABLED: vm.swap_info module");
686 if (unlikely(size != sizeof(xsw))) {
687 error("FREEBSD: sysctl(%s...) expected %lu, got %lu", "vm.swap_info", (unsigned long)sizeof(xsw), (unsigned long)size);
688 error("DISABLED: system.swap chart");
689 error("DISABLED: vm.swap_info module");
694 total_xsw.bytes_used += xsw.xsw_used;
695 total_xsw.bytes_total += xsw.xsw_nblks;
698 // --------------------------------------------------------------------
700 static RRDSET *st = NULL;
701 static RRDDIM *rd_free = NULL, *rd_used = NULL;
704 st = rrdset_create_localhost("system",
716 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
718 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
719 rd_used = rrddim_add(st, "used", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
721 else rrdset_next(st);
723 rrddim_set_by_pointer(st, rd_free, total_xsw.bytes_total - total_xsw.bytes_used);
724 rrddim_set_by_pointer(st, rd_used, total_xsw.bytes_used);
731 // --------------------------------------------------------------------------------------------------------------------
734 int do_system_ram(int update_every, usec_t dt) {
735 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},
736 mib_cache_count[4] = {0, 0, 0, 0}, mib_vfs_bufspace[2] = {0, 0}, mib_free_count[4] = {0, 0, 0, 0};
737 struct vmmeter vmmeter_data;
738 int vfs_bufspace_count;
740 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_active_count", mib_active_count, vmmeter_data.v_active_count) ||
741 GETSYSCTL_SIMPLE("vm.stats.vm.v_inactive_count", mib_inactive_count, vmmeter_data.v_inactive_count) ||
742 GETSYSCTL_SIMPLE("vm.stats.vm.v_wire_count", mib_wire_count, vmmeter_data.v_wire_count) ||
743 #if __FreeBSD_version < 1200016
744 GETSYSCTL_SIMPLE("vm.stats.vm.v_cache_count", mib_cache_count, vmmeter_data.v_cache_count) ||
746 GETSYSCTL_SIMPLE("vfs.bufspace", mib_vfs_bufspace, vfs_bufspace_count) ||
747 GETSYSCTL_SIMPLE("vm.stats.vm.v_free_count", mib_free_count, vmmeter_data.v_free_count))) {
748 error("DISABLED: system.ram chart");
749 error("DISABLED: System.ram module");
753 // --------------------------------------------------------------------
755 static RRDSET *st = NULL;
756 static RRDDIM *rd_free = NULL, *rd_active = NULL, *rd_inactive = NULL,
757 *rd_wired = NULL, *rd_cache = NULL, *rd_buffers = NULL;
759 st = rrdset_find_localhost("system.ram");
761 st = rrdset_create_localhost("system",
773 rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
774 rd_active = rrddim_add(st, "active", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
775 rd_inactive = rrddim_add(st, "inactive", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
776 rd_wired = rrddim_add(st, "wired", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
777 #if __FreeBSD_version < 1200016
778 rd_cache = rrddim_add(st, "cache", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
780 rd_buffers = rrddim_add(st, "buffers", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
782 else rrdset_next(st);
784 rrddim_set_by_pointer(st, rd_free, vmmeter_data.v_free_count);
785 rrddim_set_by_pointer(st, rd_active, vmmeter_data.v_active_count);
786 rrddim_set_by_pointer(st, rd_inactive, vmmeter_data.v_inactive_count);
787 rrddim_set_by_pointer(st, rd_wired, vmmeter_data.v_wire_count);
788 #if __FreeBSD_version < 1200016
789 rrddim_set_by_pointer(st, rd_cache, vmmeter_data.v_cache_count);
791 rrddim_set_by_pointer(st, rd_buffers, vfs_bufspace_count);
798 // --------------------------------------------------------------------------------------------------------------------
799 // vm.stats.vm.v_swappgs
801 int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt) {
802 static int mib_swappgsin[4] = {0, 0, 0, 0}, mib_swappgsout[4] = {0, 0, 0, 0};
803 struct vmmeter vmmeter_data;
805 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsin", mib_swappgsin, vmmeter_data.v_swappgsin) ||
806 GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsout", mib_swappgsout, vmmeter_data.v_swappgsout))) {
807 error("DISABLED: system.swapio chart");
808 error("DISABLED: vm.stats.vm.v_swappgs module");
812 // --------------------------------------------------------------------
814 static RRDSET *st = NULL;
815 static RRDDIM *rd_in = NULL, *rd_out = NULL;
818 st = rrdset_create_localhost("system",
830 rd_in = rrddim_add(st, "in", NULL, system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
831 rd_out = rrddim_add(st, "out", NULL, -system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
833 else rrdset_next(st);
835 rrddim_set_by_pointer(st, rd_in, vmmeter_data.v_swappgsin);
836 rrddim_set_by_pointer(st, rd_out, vmmeter_data.v_swappgsout);
843 // --------------------------------------------------------------------------------------------------------------------
844 // vm.stats.vm.v_pgfaults
846 int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt) {
847 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},
848 mib_cow_optim[4] = {0, 0, 0, 0}, mib_intrans[4] = {0, 0, 0, 0};
849 struct vmmeter vmmeter_data;
851 if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_vm_faults", mib_vm_faults, vmmeter_data.v_vm_faults) ||
852 GETSYSCTL_SIMPLE("vm.stats.vm.v_io_faults", mib_io_faults, vmmeter_data.v_io_faults) ||
853 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_faults", mib_cow_faults, vmmeter_data.v_cow_faults) ||
854 GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_optim", mib_cow_optim, vmmeter_data.v_cow_optim) ||
855 GETSYSCTL_SIMPLE("vm.stats.vm.v_intrans", mib_intrans, vmmeter_data.v_intrans))) {
856 error("DISABLED: mem.pgfaults chart");
857 error("DISABLED: vm.stats.vm.v_pgfaults module");
861 // --------------------------------------------------------------------
863 static RRDSET *st = NULL;
864 static RRDDIM *rd_memory = NULL, *rd_io_requiring = NULL, *rd_cow = NULL,
865 *rd_cow_optimized = NULL, *rd_in_transit = NULL;
868 st = rrdset_create_localhost("mem",
873 "Memory Page Faults",
880 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
882 rd_memory = rrddim_add(st, "memory", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
883 rd_io_requiring = rrddim_add(st, "io_requiring", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
884 rd_cow = rrddim_add(st, "cow", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
885 rd_cow_optimized = rrddim_add(st, "cow_optimized", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
886 rd_in_transit = rrddim_add(st, "in_transit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
888 else rrdset_next(st);
890 rrddim_set_by_pointer(st, rd_memory, vmmeter_data.v_vm_faults);
891 rrddim_set_by_pointer(st, rd_io_requiring, vmmeter_data.v_io_faults);
892 rrddim_set_by_pointer(st, rd_cow, vmmeter_data.v_cow_faults);
893 rrddim_set_by_pointer(st, rd_cow_optimized, vmmeter_data.v_cow_optim);
894 rrddim_set_by_pointer(st, rd_in_transit, vmmeter_data.v_intrans);
901 // --------------------------------------------------------------------------------------------------------------------
904 int do_kern_ipc_sem(int update_every, usec_t dt) {
905 static int mib_semmni[3] = {0, 0, 0}, mib_sema[3] = {0, 0, 0};
908 collected_number sets;
909 collected_number semaphores;
910 } ipc_sem = {0, 0, 0};
912 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.semmni", mib_semmni, ipc_sem.semmni))) {
913 error("DISABLED: system.ipc_semaphores chart");
914 error("DISABLED: system.ipc_semaphore_arrays chart");
915 error("DISABLED: kern.ipc.sem module");
918 static struct semid_kernel *ipc_sem_data = NULL;
920 ipc_sem_data = reallocz(ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni);
921 if (unlikely(GETSYSCTL_WSIZE("kern.ipc.sema", mib_sema, ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni))) {
922 error("DISABLED: system.ipc_semaphores chart");
923 error("DISABLED: system.ipc_semaphore_arrays chart");
924 error("DISABLED: kern.ipc.sem module");
929 for (i = 0; i < ipc_sem.semmni; i++) {
930 if (unlikely(ipc_sem_data[i].u.sem_perm.mode & SEM_ALLOC)) {
932 ipc_sem.semaphores += ipc_sem_data[i].u.sem_nsems;
936 // --------------------------------------------------------------------
938 static RRDSET *st_semaphores = NULL, *st_semaphore_arrays = NULL;
939 static RRDDIM *rd_semaphores = NULL, *rd_semaphore_arrays = NULL;
941 if (unlikely(!st_semaphores)) {
942 st_semaphores = rrdset_create_localhost("system",
950 localhost->rrd_update_every,
954 rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
956 else rrdset_next(st_semaphores);
958 rrddim_set_by_pointer(st_semaphores, rd_semaphores, ipc_sem.semaphores);
959 rrdset_done(st_semaphores);
961 // --------------------------------------------------------------------
963 if (unlikely(!st_semaphore_arrays)) {
964 st_semaphore_arrays = rrdset_create_localhost("system",
965 "ipc_semaphore_arrays",
969 "IPC Semaphore Arrays",
972 localhost->rrd_update_every,
976 rd_semaphore_arrays = rrddim_add(st_semaphore_arrays, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
978 else rrdset_next(st_semaphore_arrays);
980 rrddim_set_by_pointer(st_semaphore_arrays, rd_semaphore_arrays, ipc_sem.sets);
981 rrdset_done(st_semaphore_arrays);
988 // --------------------------------------------------------------------------------------------------------------------
991 int do_kern_ipc_shm(int update_every, usec_t dt) {
992 static int mib_shmmni[3] = {0, 0, 0}, mib_shmsegs[3] = {0, 0, 0};
995 collected_number segs;
996 collected_number segsize;
997 } ipc_shm = {0, 0, 0};
999 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.shmmni", mib_shmmni, ipc_shm.shmmni))) {
1000 error("DISABLED: system.ipc_shared_mem_segs chart");
1001 error("DISABLED: system.ipc_shared_mem_size chart");
1002 error("DISABLED: kern.ipc.shmmodule");
1005 static struct shmid_kernel *ipc_shm_data = NULL;
1007 ipc_shm_data = reallocz(ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni);
1009 GETSYSCTL_WSIZE("kern.ipc.shmsegs", mib_shmsegs, ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni))) {
1010 error("DISABLED: system.ipc_shared_mem_segs chart");
1011 error("DISABLED: system.ipc_shared_mem_size chart");
1012 error("DISABLED: kern.ipc.shmmodule");
1017 for (i = 0; i < ipc_shm.shmmni; i++) {
1018 if (unlikely(ipc_shm_data[i].u.shm_perm.mode & 0x0800)) {
1020 ipc_shm.segsize += ipc_shm_data[i].u.shm_segsz;
1024 // --------------------------------------------------------------------
1026 static RRDSET *st_segs = NULL, *st_size = NULL;
1027 static RRDDIM *rd_segments = NULL, *rd_allocated = NULL;
1029 if (unlikely(!st_segs)) {
1030 st_segs = rrdset_create_localhost("system",
1031 "ipc_shared_mem_segs",
1033 "ipc shared memory",
1035 "IPC Shared Memory Segments",
1038 localhost->rrd_update_every,
1042 rd_segments = rrddim_add(st_segs, "segments", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1044 else rrdset_next(st_segs);
1046 rrddim_set_by_pointer(st_segs, rd_segments, ipc_shm.segs);
1047 rrdset_done(st_segs);
1049 // --------------------------------------------------------------------
1051 if (unlikely(!st_size)) {
1052 st_size = rrdset_create_localhost("system",
1053 "ipc_shared_mem_size",
1055 "ipc shared memory",
1057 "IPC Shared Memory Segments Size",
1060 localhost->rrd_update_every,
1064 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, KILO_FACTOR, RRD_ALGORITHM_ABSOLUTE);
1066 else rrdset_next(st_size);
1068 rrddim_set_by_pointer(st_size, rd_allocated, ipc_shm.segsize);
1069 rrdset_done(st_size);
1076 // --------------------------------------------------------------------------------------------------------------------
1079 int do_kern_ipc_msq(int update_every, usec_t dt) {
1080 static int mib_msgmni[3] = {0, 0, 0}, mib_msqids[3] = {0, 0, 0};
1083 collected_number queues;
1084 collected_number messages;
1085 collected_number usedsize;
1086 collected_number allocsize;
1087 } ipc_msq = {0, 0, 0, 0, 0};
1089 if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.msgmni", mib_msgmni, ipc_msq.msgmni))) {
1090 error("DISABLED: system.ipc_msq_queues chart");
1091 error("DISABLED: system.ipc_msq_messages chart");
1092 error("DISABLED: system.ipc_msq_size chart");
1093 error("DISABLED: kern.ipc.msg module");
1096 static struct msqid_kernel *ipc_msq_data = NULL;
1098 ipc_msq_data = reallocz(ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni);
1100 GETSYSCTL_WSIZE("kern.ipc.msqids", mib_msqids, ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni))) {
1101 error("DISABLED: system.ipc_msq_queues chart");
1102 error("DISABLED: system.ipc_msq_messages chart");
1103 error("DISABLED: system.ipc_msq_size chart");
1104 error("DISABLED: kern.ipc.msg module");
1109 for (i = 0; i < ipc_msq.msgmni; i++) {
1110 if (unlikely(ipc_msq_data[i].u.msg_qbytes != 0)) {
1111 ipc_msq.queues += 1;
1112 ipc_msq.messages += ipc_msq_data[i].u.msg_qnum;
1113 ipc_msq.usedsize += ipc_msq_data[i].u.msg_cbytes;
1114 ipc_msq.allocsize += ipc_msq_data[i].u.msg_qbytes;
1118 // --------------------------------------------------------------------
1120 static RRDSET *st_queues = NULL, *st_messages = NULL, *st_size = NULL;
1121 static RRDDIM *rd_queues = NULL, *rd_messages = NULL, *rd_allocated = NULL, *rd_used = NULL;
1123 if (unlikely(!st_queues)) {
1124 st_queues = rrdset_create_localhost("system",
1127 "ipc message queues",
1129 "Number of IPC Message Queues",
1132 localhost->rrd_update_every,
1136 rd_queues = rrddim_add(st_queues, "queues", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1138 else rrdset_next(st_queues);
1140 rrddim_set_by_pointer(st_queues, rd_queues, ipc_msq.queues);
1141 rrdset_done(st_queues);
1143 // --------------------------------------------------------------------
1145 if (unlikely(!st_messages)) {
1146 st_messages = rrdset_create_localhost("system",
1149 "ipc message queues",
1151 "Number of Messages in IPC Message Queues",
1154 localhost->rrd_update_every,
1158 rd_messages = rrddim_add(st_messages, "messages", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1160 else rrdset_next(st_messages);
1162 rrddim_set_by_pointer(st_messages, rd_messages, ipc_msq.messages);
1163 rrdset_done(st_messages);
1165 // --------------------------------------------------------------------
1167 if (unlikely(!st_size)) {
1168 st_size = rrdset_create_localhost("system",
1171 "ipc message queues",
1173 "Size of IPC Message Queues",
1176 localhost->rrd_update_every,
1180 rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1181 rd_used = rrddim_add(st_size, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1183 else rrdset_next(st_size);
1185 rrddim_set_by_pointer(st_size, rd_allocated, ipc_msq.allocsize);
1186 rrddim_set_by_pointer(st_size, rd_used, ipc_msq.usedsize);
1187 rrdset_done(st_size);
1194 // --------------------------------------------------------------------------------------------------------------------
1197 int do_uptime(int update_every, usec_t dt) {
1198 struct timespec up_time;
1200 clock_gettime(CLOCK_UPTIME, &up_time);
1202 // --------------------------------------------------------------------
1204 static RRDSET *st = NULL;
1205 static RRDDIM *rd = NULL;
1208 st = rrdset_create_localhost("system",
1220 rd = rrddim_add(st, "uptime", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1222 else rrdset_next(st);
1224 rrddim_set_by_pointer(st, rd, up_time.tv_sec);
1230 // --------------------------------------------------------------------------------------------------------------------
1233 int do_net_isr(int update_every, usec_t dt) {
1234 static int do_netisr = -1, do_netisr_per_core = -1;
1236 if (unlikely(do_netisr == -1)) {
1237 do_netisr = config_get_boolean("plugin:freebsd:net.isr", "netisr", 1);
1238 do_netisr_per_core = config_get_boolean("plugin:freebsd:net.isr", "netisr per core", 1);
1241 static int mib_workstream[3] = {0, 0, 0}, mib_work[3] = {0, 0, 0};
1242 int common_error = 0;
1244 size_t netisr_workstream_size, netisr_work_size;
1245 unsigned long num_netisr_workstreams = 0, num_netisr_works = 0;
1246 static struct sysctl_netisr_workstream *netisr_workstream = NULL;
1247 static struct sysctl_netisr_work *netisr_work = NULL;
1248 static struct netisr_stats {
1249 collected_number dispatched;
1250 collected_number hybrid_dispatched;
1251 collected_number qdrops;
1252 collected_number queued;
1253 } *netisr_stats = NULL;
1255 if (likely(do_netisr || do_netisr_per_core)) {
1256 if (unlikely(GETSYSCTL_SIZE("net.isr.workstream", mib_workstream, netisr_workstream_size))) {
1258 } else if (unlikely(GETSYSCTL_SIZE("net.isr.work", mib_work, netisr_work_size))) {
1261 num_netisr_workstreams = netisr_workstream_size / sizeof(struct sysctl_netisr_workstream);
1262 netisr_workstream = reallocz(netisr_workstream, num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream));
1263 if (unlikely(GETSYSCTL_WSIZE("net.isr.workstream", mib_workstream, netisr_workstream,
1264 num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream)))){
1267 num_netisr_works = netisr_work_size / sizeof(struct sysctl_netisr_work);
1268 netisr_work = reallocz(netisr_work, num_netisr_works * sizeof(struct sysctl_netisr_work));
1269 if (unlikely(GETSYSCTL_WSIZE("net.isr.work", mib_work, netisr_work,
1270 num_netisr_works * sizeof(struct sysctl_netisr_work)))){
1275 if (unlikely(common_error)) {
1277 error("DISABLED: system.softnet_stat chart");
1278 do_netisr_per_core = 0;
1279 error("DISABLED: system.cpuX_softnet_stat chart");
1281 error("DISABLED: net.isr module");
1284 netisr_stats = reallocz(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1285 memset(netisr_stats, 0, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1286 for (i = 0; i < num_netisr_workstreams; i++) {
1287 for (n = 0; n < num_netisr_works; n++) {
1288 if (netisr_workstream[i].snws_wsid == netisr_work[n].snw_wsid) {
1289 netisr_stats[netisr_workstream[i].snws_cpu].dispatched += netisr_work[n].snw_dispatched;
1290 netisr_stats[netisr_workstream[i].snws_cpu].hybrid_dispatched += netisr_work[n].snw_hybrid_dispatched;
1291 netisr_stats[netisr_workstream[i].snws_cpu].qdrops += netisr_work[n].snw_qdrops;
1292 netisr_stats[netisr_workstream[i].snws_cpu].queued += netisr_work[n].snw_queued;
1296 for (i = 0; i < number_of_cpus; i++) {
1297 netisr_stats[number_of_cpus].dispatched += netisr_stats[i].dispatched;
1298 netisr_stats[number_of_cpus].hybrid_dispatched += netisr_stats[i].hybrid_dispatched;
1299 netisr_stats[number_of_cpus].qdrops += netisr_stats[i].qdrops;
1300 netisr_stats[number_of_cpus].queued += netisr_stats[i].queued;
1304 error("DISABLED: net.isr module");
1308 // --------------------------------------------------------------------
1310 if (likely(do_netisr)) {
1311 static RRDSET *st = NULL;
1312 static RRDDIM *rd_dispatched = NULL, *rd_hybrid_dispatched = NULL, *rd_qdrops = NULL, *rd_queued = NULL;
1314 if (unlikely(!st)) {
1315 st = rrdset_create_localhost("system",
1320 "System softnet_stat",
1327 rd_dispatched = rrddim_add(st, "dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1328 rd_hybrid_dispatched = rrddim_add(st, "hybrid_dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1329 rd_qdrops = rrddim_add(st, "qdrops", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1330 rd_queued = rrddim_add(st, "queued", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1332 else rrdset_next(st);
1334 rrddim_set_by_pointer(st, rd_dispatched, netisr_stats[number_of_cpus].dispatched);
1335 rrddim_set_by_pointer(st, rd_hybrid_dispatched, netisr_stats[number_of_cpus].hybrid_dispatched);
1336 rrddim_set_by_pointer(st, rd_qdrops, netisr_stats[number_of_cpus].qdrops);
1337 rrddim_set_by_pointer(st, rd_queued, netisr_stats[number_of_cpus].queued);
1341 // --------------------------------------------------------------------
1343 if (likely(do_netisr_per_core)) {
1344 static struct softnet_chart {
1345 char netisr_cpuid[MAX_INT_DIGITS + 17];
1347 RRDDIM *rd_dispatched;
1348 RRDDIM *rd_hybrid_dispatched;
1351 } *all_softnet_charts = NULL;
1352 static int old_number_of_cpus = 0;
1354 if(unlikely(number_of_cpus > old_number_of_cpus)) {
1355 all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus);
1356 memset(&all_softnet_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus));
1357 old_number_of_cpus = number_of_cpus;
1360 for (i = 0; i < number_of_cpus ;i++) {
1361 snprintfz(all_softnet_charts[i].netisr_cpuid, MAX_INT_DIGITS + 17, "cpu%d_softnet_stat", i);
1363 if (unlikely(!all_softnet_charts[i].st)) {
1364 all_softnet_charts[i].st = rrdset_create_localhost("cpu",
1365 all_softnet_charts[i].netisr_cpuid,
1369 "Per CPU netisr statistics",
1376 all_softnet_charts[i].rd_dispatched = rrddim_add(all_softnet_charts[i].st, "dispatched",
1377 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1378 all_softnet_charts[i].rd_hybrid_dispatched = rrddim_add(all_softnet_charts[i].st, "hybrid_dispatched",
1379 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1380 all_softnet_charts[i].rd_qdrops = rrddim_add(all_softnet_charts[i].st, "qdrops",
1381 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1382 all_softnet_charts[i].rd_queued = rrddim_add(all_softnet_charts[i].st, "queued",
1383 NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1385 else rrdset_next(all_softnet_charts[i].st);
1387 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_dispatched,
1388 netisr_stats[i].dispatched);
1389 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_hybrid_dispatched,
1390 netisr_stats[i].hybrid_dispatched);
1391 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_qdrops,
1392 netisr_stats[i].qdrops);
1393 rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_queued,
1394 netisr_stats[i].queued);
1395 rrdset_done(all_softnet_charts[i].st);
1402 // --------------------------------------------------------------------------------------------------------------------
1403 // net.inet.tcp.states
1405 int do_net_inet_tcp_states(int update_every, usec_t dt) {
1406 static int mib[4] = {0, 0, 0, 0};
1407 uint64_t tcps_states[TCP_NSTATES];
1409 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1410 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.states", mib, tcps_states))) {
1411 error("DISABLED: ipv4.tcpsock chart");
1412 error("DISABLED: net.inet.tcp.states module");
1416 // --------------------------------------------------------------------
1418 static RRDSET *st = NULL;
1419 static RRDDIM *rd = NULL;
1421 if (unlikely(!st)) {
1422 st = rrdset_create_localhost("ipv4",
1427 "IPv4 TCP Connections",
1428 "active connections",
1434 rd = rrddim_add(st, "CurrEstab", "connections", 1, 1, RRD_ALGORITHM_ABSOLUTE);
1438 rrddim_set_by_pointer(st, rd, tcps_states[TCPS_ESTABLISHED]);
1445 // --------------------------------------------------------------------------------------------------------------------
1446 // net.inet.tcp.stats
1448 int do_net_inet_tcp_stats(int update_every, usec_t dt) {
1449 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;
1451 if (unlikely(do_tcp_packets == -1)) {
1452 do_tcp_packets = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP packets", 1);
1453 do_tcp_errors = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP errors", 1);
1454 do_tcp_handshake = config_get_boolean("plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP handshake issues", 1);
1455 do_tcpext_connaborts = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP connection aborts",
1456 CONFIG_BOOLEAN_AUTO);
1457 do_tcpext_ofo = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP out-of-order queue",
1458 CONFIG_BOOLEAN_AUTO);
1459 do_tcpext_syncookies = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "TCP SYN cookies",
1460 CONFIG_BOOLEAN_AUTO);
1461 do_ecn = config_get_boolean_ondemand("plugin:freebsd:net.inet.tcp.stats", "ECN packets",
1462 CONFIG_BOOLEAN_AUTO);
1465 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
1466 if (likely(do_tcp_packets || do_tcp_errors || do_tcp_handshake || do_tcpext_connaborts || do_tcpext_ofo || do_tcpext_syncookies || do_ecn)) {
1467 static int mib[4] = {0, 0, 0, 0};
1468 struct tcpstat tcpstat;
1470 if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.stats", mib, tcpstat))) {
1472 error("DISABLED: ipv4.tcppackets chart");
1474 error("DISABLED: ipv4.tcperrors chart");
1475 do_tcp_handshake = 0;
1476 error("DISABLED: ipv4.tcphandshake chart");
1477 do_tcpext_connaborts = 0;
1478 error("DISABLED: ipv4.tcpconnaborts chart");
1480 error("DISABLED: ipv4.tcpofo chart");
1481 do_tcpext_syncookies = 0;
1482 error("DISABLED: ipv4.tcpsyncookies chart");
1484 error("DISABLED: ipv4.ecnpkts chart");
1485 error("DISABLED: net.inet.tcp.stats module");
1489 // --------------------------------------------------------------------
1491 if (likely(do_tcp_packets)) {
1492 static RRDSET *st = NULL;
1493 static RRDDIM *rd_in_segs = NULL, *rd_out_segs = NULL;
1495 if (unlikely(!st)) {
1496 st = rrdset_create_localhost("ipv4",
1508 rd_in_segs = rrddim_add(st, "InSegs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1509 rd_out_segs = rrddim_add(st, "OutSegs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1513 rrddim_set_by_pointer(st, rd_in_segs, tcpstat.tcps_rcvtotal);
1514 rrddim_set_by_pointer(st, rd_out_segs, tcpstat.tcps_sndtotal);
1518 // --------------------------------------------------------------------
1520 if (likely(do_tcp_errors)) {
1521 static RRDSET *st = NULL;
1522 static RRDDIM *rd_in_errs = NULL, *rd_in_csum_errs = NULL, *rd_retrans_segs = NULL;
1524 if (unlikely(!st)) {
1525 st = rrdset_create_localhost("ipv4",
1537 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1539 rd_in_errs = rrddim_add(st, "InErrs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1540 rd_in_csum_errs = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1541 rd_retrans_segs = rrddim_add(st, "RetransSegs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1545 #if __FreeBSD__ >= 11
1546 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvreassfull +
1547 tcpstat.tcps_rcvshort);
1549 rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvshort);
1551 rrddim_set_by_pointer(st, rd_in_csum_errs, tcpstat.tcps_rcvbadsum);
1552 rrddim_set_by_pointer(st, rd_retrans_segs, tcpstat.tcps_sndrexmitpack);
1556 // --------------------------------------------------------------------
1558 if (likely(do_tcp_handshake)) {
1559 static RRDSET *st = NULL;
1560 static RRDDIM *rd_estab_resets = NULL, *rd_active_opens = NULL, *rd_passive_opens = NULL,
1561 *rd_attempt_fails = NULL;
1563 if (unlikely(!st)) {
1564 st = rrdset_create_localhost("ipv4",
1569 "IPv4 TCP Handshake Issues",
1576 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1578 rd_estab_resets = rrddim_add(st, "EstabResets", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1579 rd_active_opens = rrddim_add(st, "ActiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1580 rd_passive_opens = rrddim_add(st, "PassiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1581 rd_attempt_fails = rrddim_add(st, "AttemptFails", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1585 rrddim_set_by_pointer(st, rd_estab_resets, tcpstat.tcps_drops);
1586 rrddim_set_by_pointer(st, rd_active_opens, tcpstat.tcps_connattempt);
1587 rrddim_set_by_pointer(st, rd_passive_opens, tcpstat.tcps_accepts);
1588 rrddim_set_by_pointer(st, rd_attempt_fails, tcpstat.tcps_conndrops);
1592 // --------------------------------------------------------------------
1594 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))) {
1595 do_tcpext_connaborts = CONFIG_BOOLEAN_YES;
1597 static RRDSET *st = NULL;
1598 static RRDDIM *rd_on_data = NULL, *rd_on_close = NULL, *rd_on_memory = NULL,
1599 *rd_on_timeout = NULL, *rd_on_linger = NULL;
1601 if (unlikely(!st)) {
1602 st = rrdset_create_localhost("ipv4",
1607 "TCP Connection Aborts",
1614 rd_on_data = rrddim_add(st, "TCPAbortOnData", "baddata", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1615 rd_on_close = rrddim_add(st, "TCPAbortOnClose", "userclosed", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1616 rd_on_memory = rrddim_add(st, "TCPAbortOnMemory", "nomemory", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1617 rd_on_timeout = rrddim_add(st, "TCPAbortOnTimeout", "timeout", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1618 rd_on_linger = rrddim_add(st, "TCPAbortOnLinger", "linger", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1620 else rrdset_next(st);
1622 rrddim_set_by_pointer(st, rd_on_data, tcpstat.tcps_rcvpackafterwin);
1623 rrddim_set_by_pointer(st, rd_on_close, tcpstat.tcps_rcvafterclose);
1624 rrddim_set_by_pointer(st, rd_on_memory, tcpstat.tcps_rcvmemdrop);
1625 rrddim_set_by_pointer(st, rd_on_timeout, tcpstat.tcps_persistdrop);
1626 rrddim_set_by_pointer(st, rd_on_linger, tcpstat.tcps_finwait2_drops);
1630 // --------------------------------------------------------------------
1632 if (do_tcpext_ofo == CONFIG_BOOLEAN_YES || (do_tcpext_ofo == CONFIG_BOOLEAN_AUTO && tcpstat.tcps_rcvoopack)) {
1633 do_tcpext_ofo = CONFIG_BOOLEAN_YES;
1635 static RRDSET *st = NULL;
1636 static RRDDIM *rd_ofo_queue = NULL;
1638 if (unlikely(!st)) {
1639 st = rrdset_create_localhost("ipv4",
1644 "TCP Out-Of-Order Queue",
1651 rd_ofo_queue = rrddim_add(st, "TCPOFOQueue", "inqueue", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1653 else rrdset_next(st);
1655 rrddim_set_by_pointer(st, rd_ofo_queue, tcpstat.tcps_rcvoopack);
1659 // --------------------------------------------------------------------
1661 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))) {
1662 do_tcpext_syncookies = CONFIG_BOOLEAN_YES;
1664 static RRDSET *st = NULL;
1665 static RRDDIM *rd_recv = NULL, *rd_send = NULL, *rd_failed = NULL;
1667 if (unlikely(!st)) {
1668 st = rrdset_create_localhost("ipv4",
1680 rd_recv = rrddim_add(st, "SyncookiesRecv", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1681 rd_send = rrddim_add(st, "SyncookiesSent", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1682 rd_failed = rrddim_add(st, "SyncookiesFailed", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1684 else rrdset_next(st);
1686 rrddim_set_by_pointer(st, rd_recv, tcpstat.tcps_sc_recvcookie);
1687 rrddim_set_by_pointer(st, rd_send, tcpstat.tcps_sc_sendcookie);
1688 rrddim_set_by_pointer(st, rd_failed, tcpstat.tcps_sc_zonefail);
1692 // --------------------------------------------------------------------
1694 if (do_ecn == CONFIG_BOOLEAN_YES || (do_ecn == CONFIG_BOOLEAN_AUTO && (tcpstat.tcps_ecn_ce || tcpstat.tcps_ecn_ect0 || tcpstat.tcps_ecn_ect1))) {
1695 do_ecn = CONFIG_BOOLEAN_YES;
1697 static RRDSET *st = NULL;
1698 static RRDDIM *rd_ce = NULL, *rd_no_ect = NULL, *rd_ect0 = NULL, *rd_ect1 = NULL;
1700 if (unlikely(!st)) {
1701 st = rrdset_create_localhost("ipv4",
1706 "IPv4 ECN Statistics",
1713 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1715 rd_ce = rrddim_add(st, "InCEPkts", "CEP", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1716 rd_no_ect = rrddim_add(st, "InNoECTPkts", "NoECTP", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1717 rd_ect0 = rrddim_add(st, "InECT0Pkts", "ECTP0", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1718 rd_ect1 = rrddim_add(st, "InECT1Pkts", "ECTP1", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1720 else rrdset_next(st);
1722 rrddim_set_by_pointer(st, rd_ce, tcpstat.tcps_ecn_ce);
1723 rrddim_set_by_pointer(st, rd_no_ect, tcpstat.tcps_ecn_ce - (tcpstat.tcps_ecn_ect0 +
1724 tcpstat.tcps_ecn_ect1));
1725 rrddim_set_by_pointer(st, rd_ect0, tcpstat.tcps_ecn_ect0);
1726 rrddim_set_by_pointer(st, rd_ect1, tcpstat.tcps_ecn_ect1);
1732 error("DISABLED: net.inet.tcp.stats module");
1739 // --------------------------------------------------------------------------------------------------------------------
1740 // net.inet.udp.stats
1742 int do_net_inet_udp_stats(int update_every, usec_t dt) {
1743 static int do_udp_packets = -1, do_udp_errors = -1;
1745 if (unlikely(do_udp_packets == -1)) {
1746 do_udp_packets = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP packets", 1);
1747 do_udp_errors = config_get_boolean("plugin:freebsd:net.inet.udp.stats", "ipv4 UDP errors", 1);
1750 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
1751 if (likely(do_udp_packets || do_udp_errors)) {
1752 static int mib[4] = {0, 0, 0, 0};
1753 struct udpstat udpstat;
1755 if (unlikely(GETSYSCTL_SIMPLE("net.inet.udp.stats", mib, udpstat))) {
1757 error("DISABLED: ipv4.udppackets chart");
1759 error("DISABLED: ipv4.udperrors chart");
1760 error("DISABLED: net.inet.udp.stats module");
1764 // --------------------------------------------------------------------
1766 if (likely(do_udp_packets)) {
1767 static RRDSET *st = NULL;
1768 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1770 if (unlikely(!st)) {
1771 st = rrdset_create_localhost("ipv4",
1783 rd_in = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1784 rd_out = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1788 rrddim_set_by_pointer(st, rd_in, udpstat.udps_ipackets);
1789 rrddim_set_by_pointer(st, rd_out, udpstat.udps_opackets);
1793 // --------------------------------------------------------------------
1795 if (likely(do_udp_errors)) {
1796 static RRDSET *st = NULL;
1797 static RRDDIM *rd_in_errors = NULL, *rd_no_ports = NULL, *rd_recv_buf_errors = NULL,
1798 *rd_in_csum_errors = NULL, *rd_ignored_multi = NULL;
1800 if (unlikely(!st)) {
1801 st = rrdset_create_localhost("ipv4",
1813 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
1815 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1816 rd_no_ports = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1817 rd_recv_buf_errors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1818 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1819 rd_ignored_multi = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1823 rrddim_set_by_pointer(st, rd_in_errors, udpstat.udps_hdrops + udpstat.udps_badlen);
1824 rrddim_set_by_pointer(st, rd_no_ports, udpstat.udps_noport);
1825 rrddim_set_by_pointer(st, rd_recv_buf_errors, udpstat.udps_fullsock);
1826 rrddim_set_by_pointer(st, rd_in_csum_errors, udpstat.udps_badsum + udpstat.udps_nosum);
1827 rrddim_set_by_pointer(st, rd_ignored_multi, udpstat.udps_filtermcast);
1832 error("DISABLED: net.inet.udp.stats module");
1839 // --------------------------------------------------------------------------------------------------------------------
1840 // net.inet.icmp.stats
1842 int do_net_inet_icmp_stats(int update_every, usec_t dt) {
1843 static int do_icmp_packets = -1, do_icmp_errors = -1, do_icmpmsg = -1;
1845 if (unlikely(do_icmp_packets == -1)) {
1846 do_icmp_packets = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP packets", 1);
1847 do_icmp_errors = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP errors", 1);
1848 do_icmpmsg = config_get_boolean("plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP messages", 1);
1851 if (likely(do_icmp_packets || do_icmp_errors || do_icmpmsg)) {
1852 static int mib[4] = {0, 0, 0, 0};
1853 struct icmpstat icmpstat;
1858 } icmp_total = {0, 0};
1860 if (unlikely(GETSYSCTL_SIMPLE("net.inet.icmp.stats", mib, icmpstat))) {
1861 do_icmp_packets = 0;
1862 error("DISABLED: ipv4.icmp chart");
1864 error("DISABLED: ipv4.icmp_errors chart");
1866 error("DISABLED: ipv4.icmpmsg chart");
1867 error("DISABLED: net.inet.icmp.stats module");
1870 for (i = 0; i <= ICMP_MAXTYPE; i++) {
1871 icmp_total.msgs_in += icmpstat.icps_inhist[i];
1872 icmp_total.msgs_out += icmpstat.icps_outhist[i];
1874 icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort;
1876 // --------------------------------------------------------------------
1878 if (likely(do_icmp_packets)) {
1879 static RRDSET *st = NULL;
1880 static RRDDIM *rd_in = NULL, *rd_out = NULL;
1882 if (unlikely(!st)) {
1883 st = rrdset_create_localhost("ipv4",
1888 "IPv4 ICMP Packets",
1895 rd_in = rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
1896 rd_out = rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
1900 rrddim_set_by_pointer(st, rd_in, icmp_total.msgs_in);
1901 rrddim_set_by_pointer(st, rd_out, icmp_total.msgs_out);
1906 // --------------------------------------------------------------------
1908 if (likely(do_icmp_errors)) {
1909 static RRDSET *st = NULL;
1910 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_csum = NULL;
1912 if (unlikely(!st)) {
1913 st = rrdset_create_localhost("ipv4", "icmp_errors", NULL, "icmp", NULL, "IPv4 ICMP Errors",
1915 2603, update_every, RRDSET_TYPE_LINE);
1917 rd_in = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1918 rd_out = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1919 rd_in_csum = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1923 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_badcode + icmpstat.icps_badlen +
1924 icmpstat.icps_checksum + icmpstat.icps_tooshort);
1925 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_error);
1926 rrddim_set_by_pointer(st, rd_in_csum, icmpstat.icps_checksum);
1931 // --------------------------------------------------------------------
1933 if (likely(do_icmpmsg)) {
1934 static RRDSET *st = NULL;
1935 static RRDDIM *rd_in_reps = NULL, *rd_out_reps = NULL, *rd_in = NULL, *rd_out = NULL;
1937 if (unlikely(!st)) {
1938 st = rrdset_create_localhost("ipv4", "icmpmsg", NULL, "icmp", NULL, "IPv4 ICMP Messsages",
1939 "packets/s", 2604, update_every, RRDSET_TYPE_LINE);
1941 rd_in_reps = rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1942 rd_out_reps = rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1943 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
1944 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
1948 rrddim_set_by_pointer(st, rd_in_reps, icmpstat.icps_inhist[ICMP_ECHOREPLY]);
1949 rrddim_set_by_pointer(st, rd_out_reps, icmpstat.icps_outhist[ICMP_ECHOREPLY]);
1950 rrddim_set_by_pointer(st, rd_in, icmpstat.icps_inhist[ICMP_ECHO]);
1951 rrddim_set_by_pointer(st, rd_out, icmpstat.icps_outhist[ICMP_ECHO]);
1957 error("DISABLED: net.inet.icmp.stats module");
1964 // --------------------------------------------------------------------------------------------------------------------
1965 // net.inet.ip.stats
1967 int do_net_inet_ip_stats(int update_every, usec_t dt) {
1968 static int do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1;
1970 if (unlikely(do_ip_packets == -1)) {
1971 do_ip_packets = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 packets", 1);
1972 do_ip_fragsout = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments sent", 1);
1973 do_ip_fragsin = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 fragments assembly", 1);
1974 do_ip_errors = config_get_boolean("plugin:freebsd:net.inet.ip.stats", "ipv4 errors", 1);
1977 // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html
1978 if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) {
1979 static int mib[4] = {0, 0, 0, 0};
1980 struct ipstat ipstat;
1982 if (unlikely(GETSYSCTL_SIMPLE("net.inet.ip.stats", mib, ipstat))) {
1984 error("DISABLED: ipv4.packets chart");
1986 error("DISABLED: ipv4.fragsout chart");
1988 error("DISABLED: ipv4.fragsin chart");
1990 error("DISABLED: ipv4.errors chart");
1991 error("DISABLED: net.inet.ip.stats module");
1995 // --------------------------------------------------------------------
1997 if (likely(do_ip_packets)) {
1998 static RRDSET *st = NULL;
1999 static RRDDIM *rd_in_receives = NULL, *rd_out_requests = NULL, *rd_forward_datagrams = NULL,
2000 *rd_in_delivers = NULL;
2002 if (unlikely(!st)) {
2003 st = rrdset_create_localhost("ipv4",
2015 rd_in_receives = rrddim_add(st, "InReceives", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2016 rd_out_requests = rrddim_add(st, "OutRequests", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2017 rd_forward_datagrams = rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2018 rd_in_delivers = rrddim_add(st, "InDelivers", "delivered", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2022 rrddim_set_by_pointer(st, rd_in_receives, ipstat.ips_total);
2023 rrddim_set_by_pointer(st, rd_out_requests, ipstat.ips_localout);
2024 rrddim_set_by_pointer(st, rd_forward_datagrams, ipstat.ips_forward);
2025 rrddim_set_by_pointer(st, rd_in_delivers, ipstat.ips_delivered);
2029 // --------------------------------------------------------------------
2031 if (likely(do_ip_fragsout)) {
2032 static RRDSET *st = NULL;
2033 static RRDDIM *rd_ok = NULL, *rd_fails = NULL, *rd_created = NULL;
2035 if (unlikely(!st)) {
2036 st = rrdset_create_localhost("ipv4",
2041 "IPv4 Fragments Sent",
2048 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2050 rd_ok = rrddim_add(st, "FragOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2051 rd_fails = rrddim_add(st, "FragFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2052 rd_created = rrddim_add(st, "FragCreates", "created", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2056 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragmented);
2057 rrddim_set_by_pointer(st, rd_fails, ipstat.ips_cantfrag);
2058 rrddim_set_by_pointer(st, rd_created, ipstat.ips_ofragments);
2062 // --------------------------------------------------------------------
2064 if (likely(do_ip_fragsin)) {
2065 static RRDSET *st = NULL;
2066 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2068 if (unlikely(!st)) {
2069 st = rrdset_create_localhost("ipv4",
2074 "IPv4 Fragments Reassembly",
2081 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2083 rd_ok = rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2084 rd_failed = rrddim_add(st, "ReasmFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
2085 rd_all = rrddim_add(st, "ReasmReqds", "all", 1, 1, RRD_ALGORITHM_INCREMENTAL);
2089 rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragments);
2090 rrddim_set_by_pointer(st, rd_failed, ipstat.ips_fragdropped);
2091 rrddim_set_by_pointer(st, rd_all, ipstat.ips_reassembled);
2095 // --------------------------------------------------------------------
2097 if (likely(do_ip_errors)) {
2098 static RRDSET *st = NULL;
2099 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2100 *rd_in_hdr_errors = NULL, *rd_out_no_routes = NULL,
2101 *rd_in_addr_errors = NULL, *rd_in_unknown_protos = NULL;
2103 if (unlikely(!st)) {
2104 st = rrdset_create_localhost("ipv4",
2116 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2118 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2119 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2120 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2121 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2122 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2123 rd_in_unknown_protos = rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2127 rrddim_set_by_pointer(st, rd_in_discards, ipstat.ips_badsum + ipstat.ips_tooshort +
2128 ipstat.ips_toosmall + ipstat.ips_toolong);
2129 rrddim_set_by_pointer(st, rd_out_discards, ipstat.ips_odropped);
2130 rrddim_set_by_pointer(st, rd_in_hdr_errors, ipstat.ips_badhlen + ipstat.ips_badlen +
2131 ipstat.ips_badoptions + ipstat.ips_badvers);
2132 rrddim_set_by_pointer(st, rd_out_no_routes, ipstat.ips_noroute);
2133 rrddim_set_by_pointer(st, rd_in_addr_errors, ipstat.ips_badaddr);
2134 rrddim_set_by_pointer(st, rd_in_unknown_protos, ipstat.ips_noproto);
2139 error("DISABLED: net.inet.ip.stats module");
2146 // --------------------------------------------------------------------------------------------------------------------
2147 // net.inet6.ip6.stats
2149 int do_net_inet6_ip6_stats(int update_every, usec_t dt) {
2150 static int do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1;
2152 if (unlikely(do_ip6_packets == -1)) {
2153 do_ip6_packets = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 packets",
2154 CONFIG_BOOLEAN_AUTO);
2155 do_ip6_fragsout = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments sent",
2156 CONFIG_BOOLEAN_AUTO);
2157 do_ip6_fragsin = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments assembly",
2158 CONFIG_BOOLEAN_AUTO);
2159 do_ip6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.ip6.stats", "ipv6 errors",
2160 CONFIG_BOOLEAN_AUTO);
2163 if (likely(do_ip6_packets || do_ip6_fragsout || do_ip6_fragsin || do_ip6_errors)) {
2164 static int mib[4] = {0, 0, 0, 0};
2165 struct ip6stat ip6stat;
2167 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.ip6.stats", mib, ip6stat))) {
2169 error("DISABLED: ipv6.packets chart");
2170 do_ip6_fragsout = 0;
2171 error("DISABLED: ipv6.fragsout chart");
2173 error("DISABLED: ipv6.fragsin chart");
2175 error("DISABLED: ipv6.errors chart");
2176 error("DISABLED: net.inet6.ip6.stats module");
2180 // --------------------------------------------------------------------
2182 if (do_ip6_packets == CONFIG_BOOLEAN_YES || (do_ip6_packets == CONFIG_BOOLEAN_AUTO &&
2183 (ip6stat.ip6s_localout || ip6stat.ip6s_total ||
2184 ip6stat.ip6s_forward || ip6stat.ip6s_delivered))) {
2185 do_ip6_packets = CONFIG_BOOLEAN_YES;
2187 static RRDSET *st = NULL;
2188 static RRDDIM *rd_received = NULL, *rd_sent = NULL, *rd_forwarded = NULL, *rd_delivers = NULL;
2190 if (unlikely(!st)) {
2191 st = rrdset_create_localhost("ipv6",
2203 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2204 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2205 rd_forwarded = rrddim_add(st, "forwarded", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2206 rd_delivers = rrddim_add(st, "delivers", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2210 rrddim_set_by_pointer(st, rd_sent, ip6stat.ip6s_localout);
2211 rrddim_set_by_pointer(st, rd_received, ip6stat.ip6s_total);
2212 rrddim_set_by_pointer(st, rd_forwarded, ip6stat.ip6s_forward);
2213 rrddim_set_by_pointer(st, rd_delivers, ip6stat.ip6s_delivered);
2217 // --------------------------------------------------------------------
2219 if (do_ip6_fragsout == CONFIG_BOOLEAN_YES || (do_ip6_fragsout == CONFIG_BOOLEAN_AUTO &&
2220 (ip6stat.ip6s_fragmented || ip6stat.ip6s_cantfrag ||
2221 ip6stat.ip6s_ofragments))) {
2222 do_ip6_fragsout = CONFIG_BOOLEAN_YES;
2224 static RRDSET *st = NULL;
2225 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL;
2227 if (unlikely(!st)) {
2228 st = rrdset_create_localhost("ipv6",
2233 "IPv6 Fragments Sent",
2240 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2242 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2243 rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2244 rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2248 rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_fragmented);
2249 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_cantfrag);
2250 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_ofragments);
2254 // --------------------------------------------------------------------
2256 if (do_ip6_fragsin == CONFIG_BOOLEAN_YES || (do_ip6_fragsin == CONFIG_BOOLEAN_AUTO &&
2257 (ip6stat.ip6s_reassembled || ip6stat.ip6s_fragdropped ||
2258 ip6stat.ip6s_fragtimeout || ip6stat.ip6s_fragments))) {
2259 do_ip6_fragsin = CONFIG_BOOLEAN_YES;
2261 static RRDSET *st = NULL;
2262 static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_timeout = NULL, *rd_all = NULL;
2264 if (unlikely(!st)) {
2265 st = rrdset_create_localhost("ipv6",
2270 "IPv6 Fragments Reassembly",
2277 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2279 rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2280 rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2281 rd_timeout = rrddim_add(st, "timeout", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2282 rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2286 rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_reassembled);
2287 rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_fragdropped);
2288 rrddim_set_by_pointer(st, rd_timeout, ip6stat.ip6s_fragtimeout);
2289 rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_fragments);
2293 // --------------------------------------------------------------------
2295 if (do_ip6_errors == CONFIG_BOOLEAN_YES || (do_ip6_errors == CONFIG_BOOLEAN_AUTO && (
2296 ip6stat.ip6s_toosmall ||
2297 ip6stat.ip6s_odropped ||
2298 ip6stat.ip6s_badoptions ||
2299 ip6stat.ip6s_badvers ||
2300 ip6stat.ip6s_exthdrtoolong ||
2301 ip6stat.ip6s_sources_none ||
2302 ip6stat.ip6s_tooshort ||
2303 ip6stat.ip6s_cantforward ||
2304 ip6stat.ip6s_noroute))) {
2305 do_ip6_errors = CONFIG_BOOLEAN_YES;
2307 static RRDSET *st = NULL;
2308 static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL,
2309 *rd_in_hdr_errors = NULL, *rd_in_addr_errors = NULL, *rd_in_truncated_pkts = NULL,
2310 *rd_in_no_routes = NULL, *rd_out_no_routes = NULL;
2312 if (unlikely(!st)) {
2313 st = rrdset_create_localhost("ipv6",
2325 rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
2327 rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2328 rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2329 rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2330 rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2331 rd_in_truncated_pkts = rrddim_add(st, "InTruncatedPkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2332 rd_in_no_routes = rrddim_add(st, "InNoRoutes", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2333 rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2337 rrddim_set_by_pointer(st, rd_in_discards, ip6stat.ip6s_toosmall);
2338 rrddim_set_by_pointer(st, rd_out_discards, ip6stat.ip6s_odropped);
2339 rrddim_set_by_pointer(st, rd_in_hdr_errors, ip6stat.ip6s_badoptions + ip6stat.ip6s_badvers +
2340 ip6stat.ip6s_exthdrtoolong);
2341 rrddim_set_by_pointer(st, rd_in_addr_errors, ip6stat.ip6s_sources_none);
2342 rrddim_set_by_pointer(st, rd_in_truncated_pkts, ip6stat.ip6s_tooshort);
2343 rrddim_set_by_pointer(st, rd_in_no_routes, ip6stat.ip6s_cantforward);
2344 rrddim_set_by_pointer(st, rd_out_no_routes, ip6stat.ip6s_noroute);
2349 error("DISABLED: net.inet6.ip6.stats module");
2356 // --------------------------------------------------------------------------------------------------------------------
2357 // net.inet6.icmp6.stats
2359 int do_net_inet6_icmp6_stats(int update_every, usec_t dt) {
2360 static int do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1,
2361 do_icmp6_neighbor = -1, do_icmp6_types = -1;
2363 if (unlikely(do_icmp6 == -1)) {
2364 do_icmp6 = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp",
2365 CONFIG_BOOLEAN_AUTO);
2366 do_icmp6_redir = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp redirects",
2367 CONFIG_BOOLEAN_AUTO);
2368 do_icmp6_errors = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp errors",
2369 CONFIG_BOOLEAN_AUTO);
2370 do_icmp6_echos = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp echos",
2371 CONFIG_BOOLEAN_AUTO);
2372 do_icmp6_router = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp router",
2373 CONFIG_BOOLEAN_AUTO);
2374 do_icmp6_neighbor = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp neighbor",
2375 CONFIG_BOOLEAN_AUTO);
2376 do_icmp6_types = config_get_boolean_ondemand("plugin:freebsd:net.inet6.icmp6.stats", "icmp types",
2377 CONFIG_BOOLEAN_AUTO);
2380 if (likely(do_icmp6 || do_icmp6_redir || do_icmp6_errors || do_icmp6_echos || do_icmp6_router || do_icmp6_neighbor || do_icmp6_types)) {
2381 static int mib[4] = {0, 0, 0, 0};
2382 struct icmp6stat icmp6stat;
2384 if (unlikely(GETSYSCTL_SIMPLE("net.inet6.icmp6.stats", mib, icmp6stat))) {
2386 error("DISABLED: ipv6.icmp chart");
2388 error("DISABLED: ipv6.icmpredir chart");
2389 do_icmp6_errors = 0;
2390 error("DISABLED: ipv6.icmperrors chart");
2392 error("DISABLED: ipv6.icmpechos chart");
2393 do_icmp6_router = 0;
2394 error("DISABLED: ipv6.icmprouter chart");
2395 do_icmp6_neighbor = 0;
2396 error("DISABLED: ipv6.icmpneighbor chart");
2398 error("DISABLED: ipv6.icmptypes chart");
2399 error("DISABLED: net.inet6.icmp6.stats module");
2403 struct icmp6_total {
2406 } icmp6_total = {0, 0};
2408 for (i = 0; i <= ICMP6_MAXTYPE; i++) {
2409 icmp6_total.msgs_in += icmp6stat.icp6s_inhist[i];
2410 icmp6_total.msgs_out += icmp6stat.icp6s_outhist[i];
2412 icmp6_total.msgs_in += icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort;
2414 // --------------------------------------------------------------------
2416 if (do_icmp6 == CONFIG_BOOLEAN_YES || (do_icmp6 == CONFIG_BOOLEAN_AUTO && (icmp6_total.msgs_in || icmp6_total.msgs_out))) {
2417 do_icmp6 = CONFIG_BOOLEAN_YES;
2419 static RRDSET *st = NULL;
2420 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2422 if (unlikely(!st)) {
2423 st = rrdset_create_localhost("ipv6",
2428 "IPv6 ICMP Messages",
2435 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2436 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2440 rrddim_set_by_pointer(st, rd_received, icmp6_total.msgs_out);
2441 rrddim_set_by_pointer(st, rd_sent, icmp6_total.msgs_in);
2446 // --------------------------------------------------------------------
2448 if (do_icmp6_redir == CONFIG_BOOLEAN_YES || (do_icmp6_redir == CONFIG_BOOLEAN_AUTO && (icmp6stat.icp6s_inhist[ND_REDIRECT] || icmp6stat.icp6s_outhist[ND_REDIRECT]))) {
2449 do_icmp6_redir = CONFIG_BOOLEAN_YES;
2451 static RRDSET *st = NULL;
2452 static RRDDIM *rd_received = NULL, *rd_sent = NULL;
2454 if (unlikely(!st)) {
2455 st = rrdset_create_localhost("ipv6",
2460 "IPv6 ICMP Redirects",
2467 rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2468 rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2472 rrddim_set_by_pointer(st, rd_received, icmp6stat.icp6s_outhist[ND_REDIRECT]);
2473 rrddim_set_by_pointer(st, rd_sent, icmp6stat.icp6s_inhist[ND_REDIRECT]);
2477 // --------------------------------------------------------------------
2479 if (do_icmp6_errors == CONFIG_BOOLEAN_YES || (do_icmp6_errors == CONFIG_BOOLEAN_AUTO && (
2480 icmp6stat.icp6s_badcode ||
2481 icmp6stat.icp6s_badlen ||
2482 icmp6stat.icp6s_checksum ||
2483 icmp6stat.icp6s_tooshort ||
2484 icmp6stat.icp6s_error ||
2485 icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH] ||
2486 icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED] ||
2487 icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB] ||
2488 icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH] ||
2489 icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED] ||
2490 icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]))) {
2491 do_icmp6_errors = CONFIG_BOOLEAN_YES;
2493 static RRDSET *st = NULL;
2494 static RRDDIM *rd_in_errors = NULL, *rd_out_errors = NULL, *rd_in_csum_errors = NULL,
2495 *rd_in_dest_unreachs = NULL, *rd_in_pkt_too_bigs = NULL, *rd_in_time_excds = NULL,
2496 *rd_in_parm_problems = NULL, *rd_out_dest_unreachs = NULL, *rd_out_time_excds = NULL,
2497 *rd_out_parm_problems = NULL;
2499 if (unlikely(!st)) {
2500 st = rrdset_create_localhost("ipv6",
2511 rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2512 rd_out_errors = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2513 rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2514 rd_in_dest_unreachs = rrddim_add(st, "InDestUnreachs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2515 rd_in_pkt_too_bigs = rrddim_add(st, "InPktTooBigs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2516 rd_in_time_excds = rrddim_add(st, "InTimeExcds", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2517 rd_in_parm_problems = rrddim_add(st, "InParmProblems", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2518 rd_out_dest_unreachs = rrddim_add(st, "OutDestUnreachs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2519 rd_out_time_excds = rrddim_add(st, "OutTimeExcds", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2520 rd_out_parm_problems = rrddim_add(st, "OutParmProblems", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2524 rrddim_set_by_pointer(st, rd_in_errors, icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen +
2525 icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort);
2526 rrddim_set_by_pointer(st, rd_out_errors, icmp6stat.icp6s_error);
2527 rrddim_set_by_pointer(st, rd_in_csum_errors, icmp6stat.icp6s_checksum);
2528 rrddim_set_by_pointer(st, rd_in_dest_unreachs, icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH]);
2529 rrddim_set_by_pointer(st, rd_in_pkt_too_bigs, icmp6stat.icp6s_badlen);
2530 rrddim_set_by_pointer(st, rd_in_time_excds, icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED]);
2531 rrddim_set_by_pointer(st, rd_in_parm_problems, icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB]);
2532 rrddim_set_by_pointer(st, rd_out_dest_unreachs, icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH]);
2533 rrddim_set_by_pointer(st, rd_out_time_excds, icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED]);
2534 rrddim_set_by_pointer(st, rd_out_parm_problems, icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]);
2538 // --------------------------------------------------------------------
2540 if (do_icmp6_echos == CONFIG_BOOLEAN_YES || (do_icmp6_echos == CONFIG_BOOLEAN_AUTO && (
2541 icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST] ||
2542 icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST] ||
2543 icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY] ||
2544 icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]))) {
2545 do_icmp6_echos = CONFIG_BOOLEAN_YES;
2547 static RRDSET *st = NULL;
2548 static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_replies = NULL, *rd_out_replies = NULL;
2550 if (unlikely(!st)) {
2551 st = rrdset_create_localhost("ipv6",
2563 rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2564 rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2565 rd_in_replies = rrddim_add(st, "InEchoReplies", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2566 rd_out_replies = rrddim_add(st, "OutEchoReplies", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2570 rrddim_set_by_pointer(st, rd_in, icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST]);
2571 rrddim_set_by_pointer(st, rd_out, icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST]);
2572 rrddim_set_by_pointer(st, rd_in_replies, icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY]);
2573 rrddim_set_by_pointer(st, rd_out_replies, icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]);
2577 // --------------------------------------------------------------------
2579 if (do_icmp6_router == CONFIG_BOOLEAN_YES || (do_icmp6_router == CONFIG_BOOLEAN_AUTO && (
2580 icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT] ||
2581 icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT] ||
2582 icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT] ||
2583 icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]))) {
2584 do_icmp6_router = CONFIG_BOOLEAN_YES;
2586 static RRDSET *st = NULL;
2587 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2588 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2590 if (unlikely(!st)) {
2591 st = rrdset_create_localhost("ipv6",
2596 "IPv6 Router Messages",
2603 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2604 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2605 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2606 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2610 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT]);
2611 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT]);
2612 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT]);
2613 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]);
2617 // --------------------------------------------------------------------
2619 if (do_icmp6_neighbor == CONFIG_BOOLEAN_YES || (do_icmp6_neighbor == CONFIG_BOOLEAN_AUTO && (
2620 icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT] ||
2621 icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT] ||
2622 icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT] ||
2623 icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]))) {
2624 do_icmp6_neighbor = CONFIG_BOOLEAN_YES;
2626 static RRDSET *st = NULL;
2627 static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL,
2628 *rd_in_advertisements = NULL, *rd_out_advertisements = NULL;
2630 if (unlikely(!st)) {
2631 st = rrdset_create_localhost("ipv6",
2636 "IPv6 Neighbor Messages",
2643 rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2644 rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2645 rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2646 rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2650 rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]);
2651 rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]);
2652 rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT]);
2653 rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]);
2657 // --------------------------------------------------------------------
2659 if (do_icmp6_types == CONFIG_BOOLEAN_YES || (do_icmp6_types == CONFIG_BOOLEAN_AUTO && (
2660 icmp6stat.icp6s_inhist[1] ||
2661 icmp6stat.icp6s_inhist[128] ||
2662 icmp6stat.icp6s_inhist[129] ||
2663 icmp6stat.icp6s_inhist[136] ||
2664 icmp6stat.icp6s_outhist[1] ||
2665 icmp6stat.icp6s_outhist[128] ||
2666 icmp6stat.icp6s_outhist[129] ||
2667 icmp6stat.icp6s_outhist[133] ||
2668 icmp6stat.icp6s_outhist[135] ||
2669 icmp6stat.icp6s_outhist[136]))) {
2670 do_icmp6_types = CONFIG_BOOLEAN_YES;
2672 static RRDSET *st = NULL;
2673 static RRDDIM *rd_in_1 = NULL, *rd_in_128 = NULL, *rd_in_129 = NULL, *rd_in_136 = NULL,
2674 *rd_out_1 = NULL, *rd_out_128 = NULL, *rd_out_129 = NULL, *rd_out_133 = NULL,
2675 *rd_out_135 = NULL, *rd_out_143 = NULL;
2677 if (unlikely(!st)) {
2678 st = rrdset_create_localhost("ipv6",
2690 rd_in_1 = rrddim_add(st, "InType1", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2691 rd_in_128 = rrddim_add(st, "InType128", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2692 rd_in_129 = rrddim_add(st, "InType129", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2693 rd_in_136 = rrddim_add(st, "InType136", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
2694 rd_out_1 = rrddim_add(st, "OutType1", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2695 rd_out_128 = rrddim_add(st, "OutType128", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2696 rd_out_129 = rrddim_add(st, "OutType129", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2697 rd_out_133 = rrddim_add(st, "OutType133", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2698 rd_out_135 = rrddim_add(st, "OutType135", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2699 rd_out_143 = rrddim_add(st, "OutType143", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
2703 rrddim_set_by_pointer(st, rd_in_1, icmp6stat.icp6s_inhist[1]);
2704 rrddim_set_by_pointer(st, rd_in_128, icmp6stat.icp6s_inhist[128]);
2705 rrddim_set_by_pointer(st, rd_in_129, icmp6stat.icp6s_inhist[129]);
2706 rrddim_set_by_pointer(st, rd_in_136, icmp6stat.icp6s_inhist[136]);
2707 rrddim_set_by_pointer(st, rd_out_1, icmp6stat.icp6s_outhist[1]);
2708 rrddim_set_by_pointer(st, rd_out_128, icmp6stat.icp6s_outhist[128]);
2709 rrddim_set_by_pointer(st, rd_out_129, icmp6stat.icp6s_outhist[129]);
2710 rrddim_set_by_pointer(st, rd_out_133, icmp6stat.icp6s_outhist[133]);
2711 rrddim_set_by_pointer(st, rd_out_135, icmp6stat.icp6s_outhist[135]);
2712 rrddim_set_by_pointer(st, rd_out_143, icmp6stat.icp6s_outhist[143]);
2717 error("DISABLED: net.inet6.icmp6.stats module");
2724 // --------------------------------------------------------------------------------------------------------------------
2727 int do_getmntinfo(int update_every, usec_t dt) {
2729 #define DELAULT_EXLUDED_PATHS "/proc/*"
2730 // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes
2731 #define DEFAULT_EXCLUDED_FILESYSTEMS "autofs procfs subfs devfs none"
2732 #define CONFIG_SECTION_GETMNTINFO "plugin:freebsd:getmntinfo"
2734 static int do_space = -1, do_inodes = -1;
2736 if (unlikely(do_space == -1)) {
2737 do_space = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
2738 do_inodes = config_get_boolean_ondemand(CONFIG_SECTION_GETMNTINFO, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
2741 if (likely(do_space || do_inodes)) {
2742 struct statfs *mntbuf;
2745 // there is no mount info in sysctl MIBs
2746 if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) {
2747 error("FREEBSD: getmntinfo() failed");
2749 error("DISABLED: disk_space.* charts");
2751 error("DISABLED: disk_inodes.* charts");
2752 error("DISABLED: getmntinfo module");
2755 // Data to be stored in DICTIONARY mount_points.
2756 // This DICTIONARY is used to lookup the settings of the mount point on each iteration.
2757 struct mount_point_metadata {
2761 size_t collected; // the number of times this has been collected
2763 // charts and dimensions
2766 RRDDIM *rd_space_used;
2767 RRDDIM *rd_space_avail;
2768 RRDDIM *rd_space_reserved;
2771 RRDDIM *rd_inodes_used;
2772 RRDDIM *rd_inodes_avail;
2774 static DICTIONARY *mount_points = NULL;
2775 static SIMPLE_PATTERN *excluded_mountpoints = NULL;
2776 static SIMPLE_PATTERN *excluded_filesystems = NULL;
2779 if(unlikely(!mount_points)) {
2781 excluded_mountpoints = simple_pattern_create(
2782 config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on paths",
2783 DELAULT_EXLUDED_PATHS),
2784 SIMPLE_PATTERN_EXACT
2787 excluded_filesystems = simple_pattern_create(
2788 config_get(CONFIG_SECTION_GETMNTINFO, "exclude space metrics on filesystems",
2789 DEFAULT_EXCLUDED_FILESYSTEMS),
2790 SIMPLE_PATTERN_EXACT
2793 mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
2796 for (i = 0; i < mntsize; i++) {
2798 char title[4096 + 1];
2799 int def_space, def_inodes, iter_space, iter_inodes;
2801 struct mount_point_metadata *m = dictionary_get(mount_points, mntbuf[i].f_mntonname);
2803 char var_name[4096 + 1];
2804 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETMNTINFO, mntbuf[i].f_mntonname);
2806 def_space = do_space;
2807 def_inodes = do_space;
2809 if(unlikely(simple_pattern_matches(excluded_mountpoints, mntbuf[i].f_mntonname))) {
2810 def_space = CONFIG_BOOLEAN_NO;
2811 def_inodes = CONFIG_BOOLEAN_NO;
2814 if(unlikely(simple_pattern_matches(excluded_filesystems, mntbuf[i].f_fstypename))) {
2815 def_space = CONFIG_BOOLEAN_NO;
2816 def_inodes = CONFIG_BOOLEAN_NO;
2819 iter_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
2820 iter_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
2822 struct mount_point_metadata mp = {
2823 .do_space = iter_space,
2824 .do_inodes = iter_inodes,
2829 .rd_space_avail = NULL,
2830 .rd_space_used = NULL,
2831 .rd_space_reserved = NULL,
2834 .rd_inodes_avail = NULL,
2835 .rd_inodes_used = NULL,
2838 m = dictionary_set(mount_points, mntbuf[i].f_mntonname, &mp, sizeof(struct mount_point_metadata));
2841 if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
2844 if(unlikely(mntbuf[i].f_flags & MNT_RDONLY && !m->collected))
2847 // --------------------------------------------------------------------------
2851 if (m->do_space == CONFIG_BOOLEAN_YES || (m->do_space == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_blocks > 2))) {
2852 if (unlikely(!m->st_space)) {
2853 snprintfz(title, 4096, "Disk Space Usage for %s [%s]",
2854 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2855 m->st_space = rrdset_create_localhost("disk_space",
2856 mntbuf[i].f_mntonname,
2858 mntbuf[i].f_mntonname,
2867 m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL,
2868 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2869 m->rd_space_used = rrddim_add(m->st_space, "used", NULL,
2870 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2871 m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root",
2872 mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE);
2874 rrdset_next(m->st_space);
2876 rrddim_set_by_pointer(m->st_space, m->rd_space_avail, (collected_number) mntbuf[i].f_bavail);
2877 rrddim_set_by_pointer(m->st_space, m->rd_space_used, (collected_number) (mntbuf[i].f_blocks -
2878 mntbuf[i].f_bfree));
2879 rrddim_set_by_pointer(m->st_space, m->rd_space_reserved, (collected_number) (mntbuf[i].f_bfree -
2880 mntbuf[i].f_bavail));
2881 rrdset_done(m->st_space);
2886 // --------------------------------------------------------------------------
2888 if (m->do_inodes == CONFIG_BOOLEAN_YES || (m->do_inodes == CONFIG_BOOLEAN_AUTO && (mntbuf[i].f_files > 1))) {
2889 if (unlikely(!m->st_inodes)) {
2890 snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]",
2891 mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
2892 m->st_inodes = rrdset_create_localhost("disk_inodes",
2893 mntbuf[i].f_mntonname,
2895 mntbuf[i].f_mntonname,
2904 m->rd_inodes_avail = rrddim_add(m->st_inodes, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2905 m->rd_inodes_used = rrddim_add(m->st_inodes, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
2907 rrdset_next(m->st_inodes);
2909 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_avail, (collected_number) mntbuf[i].f_ffree);
2910 rrddim_set_by_pointer(m->st_inodes, m->rd_inodes_used, (collected_number) (mntbuf[i].f_files -
2911 mntbuf[i].f_ffree));
2912 rrdset_done(m->st_inodes);
2917 if(likely(rendered))
2922 error("DISABLED: getmntinfo module");
2929 // --------------------------------------------------------------------------------------------------------------------
2932 int do_getifaddrs(int update_every, usec_t dt) {
2934 #define DELAULT_EXLUDED_INTERFACES "lo*"
2935 #define CONFIG_SECTION_GETIFADDRS "plugin:freebsd:getifaddrs"
2937 static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1,
2938 do_errors = -1, do_drops = -1, do_events = -1;
2940 if (unlikely(do_bandwidth_ipv4 == -1)) {
2941 do_bandwidth_ipv4 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv4 interfaces",
2942 CONFIG_BOOLEAN_AUTO);
2943 do_bandwidth_ipv6 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv6 interfaces",
2944 CONFIG_BOOLEAN_AUTO);
2945 do_bandwidth = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "bandwidth for all interfaces",
2946 CONFIG_BOOLEAN_AUTO);
2947 do_packets = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "packets for all interfaces",
2948 CONFIG_BOOLEAN_AUTO);
2949 do_errors = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "errors for all interfaces",
2950 CONFIG_BOOLEAN_AUTO);
2951 do_drops = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "drops for all interfaces",
2952 CONFIG_BOOLEAN_AUTO);
2953 do_events = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "collisions for all interfaces",
2954 CONFIG_BOOLEAN_AUTO);
2957 if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors ||
2958 do_drops || do_events)) {
2959 struct ifaddrs *ifap;
2961 if (unlikely(getifaddrs(&ifap))) {
2962 error("FREEBSD: getifaddrs() failed");
2963 do_bandwidth_ipv4 = 0;
2964 error("DISABLED: system.ipv4 chart");
2965 do_bandwidth_ipv6 = 0;
2966 error("DISABLED: system.ipv6 chart");
2968 error("DISABLED: net.* charts");
2970 error("DISABLED: net_packets.* charts");
2972 error("DISABLED: net_errors.* charts");
2974 error("DISABLED: net_drops.* charts");
2976 error("DISABLED: net_events.* charts");
2977 error("DISABLED: getifaddrs module");
2980 #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
2981 struct ifaddrs *ifa;
2987 // --------------------------------------------------------------------
2989 if (likely(do_bandwidth_ipv4)) {
2990 iftot.ift_ibytes = iftot.ift_obytes = 0;
2991 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
2992 if (ifa->ifa_addr->sa_family != AF_INET)
2994 iftot.ift_ibytes += IFA_DATA(ibytes);
2995 iftot.ift_obytes += IFA_DATA(obytes);
2998 static RRDSET *st = NULL;
2999 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3001 if (unlikely(!st)) {
3002 st = rrdset_create_localhost("system",
3014 rd_in = rrddim_add(st, "InOctets", "received", 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3015 rd_out = rrddim_add(st, "OutOctets", "sent", -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3019 rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3020 rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3024 // --------------------------------------------------------------------
3026 if (likely(do_bandwidth_ipv6)) {
3027 iftot.ift_ibytes = iftot.ift_obytes = 0;
3028 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3029 if (ifa->ifa_addr->sa_family != AF_INET6)
3031 iftot.ift_ibytes += IFA_DATA(ibytes);
3032 iftot.ift_obytes += IFA_DATA(obytes);
3035 static RRDSET *st = NULL;
3036 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3038 if (unlikely(!st)) {
3039 st = rrdset_create_localhost("system",
3051 rd_in = rrddim_add(st, "received", NULL, 8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3052 rd_out = rrddim_add(st, "sent", NULL, -8, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL);
3056 rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
3057 rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
3061 // --------------------------------------------------------------------
3063 // Data to be stored in DICTIONARY interfaces.
3064 // This DICTIONARY is used to lookup the settings of the interfaces on each iteration.
3065 struct interfaces_metadata {
3072 // charts and dimensions
3074 RRDSET *st_bandwidth;
3075 RRDDIM *rd_bandwidth_in;
3076 RRDDIM *rd_bandwidth_out;
3079 RRDDIM *rd_packets_in;
3080 RRDDIM *rd_packets_out;
3081 RRDDIM *rd_packets_m_in;
3082 RRDDIM *rd_packets_m_out;
3085 RRDDIM *rd_errors_in;
3086 RRDDIM *rd_errors_out;
3089 RRDDIM *rd_drops_in;
3090 RRDDIM *rd_drops_out;
3093 RRDDIM *rd_events_coll;
3095 static DICTIONARY *interfaces = NULL;
3096 static SIMPLE_PATTERN *excluded_interfaces = NULL;
3098 if(unlikely(!interfaces)) {
3100 excluded_interfaces = simple_pattern_create(
3101 config_get(CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching",
3102 DELAULT_EXLUDED_INTERFACES)
3103 , SIMPLE_PATTERN_EXACT
3106 interfaces = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
3109 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
3110 if (ifa->ifa_addr->sa_family != AF_LINK)
3113 int def_bandwidth, def_packets, def_errors, def_drops, def_events,
3114 iter_bandwidth, iter_packets, iter_errors, iter_drops, iter_events;
3116 struct interfaces_metadata *ifm = dictionary_get(interfaces, ifa->ifa_name);
3117 if(unlikely(!ifm)) {
3118 char var_name[4096 + 1];
3119 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETIFADDRS, ifa->ifa_name);
3121 def_bandwidth = do_bandwidth;
3122 def_packets = do_packets;
3123 def_errors = do_errors;
3124 def_drops = do_drops;
3125 def_events = do_events;
3127 if(unlikely(simple_pattern_matches(excluded_interfaces, ifa->ifa_name))) {
3128 def_bandwidth = CONFIG_BOOLEAN_NO;
3129 def_packets = CONFIG_BOOLEAN_NO;
3130 def_errors = CONFIG_BOOLEAN_NO;
3131 def_drops = CONFIG_BOOLEAN_NO;
3132 def_events = CONFIG_BOOLEAN_NO;
3135 iter_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", def_bandwidth);
3136 iter_packets = config_get_boolean_ondemand(var_name, "packets", def_packets);
3137 iter_errors = config_get_boolean_ondemand(var_name, "errors", def_errors);
3138 iter_drops = config_get_boolean_ondemand(var_name, "drops", def_drops);
3139 iter_events = config_get_boolean_ondemand(var_name, "events", def_events);
3141 struct interfaces_metadata ifmp = {
3142 .do_bandwidth = iter_bandwidth,
3143 .do_packets = iter_packets,
3144 .do_errors = iter_errors,
3145 .do_drops = iter_drops,
3146 .do_events = iter_events,
3148 .st_bandwidth = NULL,
3149 .rd_bandwidth_in = NULL,
3150 .rd_bandwidth_out = NULL,
3153 .rd_packets_in = NULL,
3154 .rd_packets_out = NULL,
3155 .rd_packets_m_in = NULL,
3156 .rd_packets_m_out = NULL,
3159 .rd_errors_in = NULL,
3160 .rd_errors_out = NULL,
3163 .rd_drops_in = NULL,
3164 .rd_drops_out = NULL,
3167 .rd_events_coll = NULL,
3170 ifm = dictionary_set(interfaces, ifa->ifa_name, &ifmp, sizeof(struct interfaces_metadata));
3173 // --------------------------------------------------------------------
3175 if (ifm->do_bandwidth == CONFIG_BOOLEAN_YES || (ifm->do_bandwidth == CONFIG_BOOLEAN_AUTO &&
3176 (IFA_DATA(ibytes) || IFA_DATA(obytes)))) {
3177 if (unlikely(!ifm->st_bandwidth)) {
3178 ifm->st_bandwidth = rrdset_create_localhost("net",
3190 ifm->rd_bandwidth_in = rrddim_add(ifm->st_bandwidth, "received", NULL, 8, KILO_FACTOR,
3191 RRD_ALGORITHM_INCREMENTAL);
3192 ifm->rd_bandwidth_out = rrddim_add(ifm->st_bandwidth, "sent", NULL, -8, KILO_FACTOR,
3193 RRD_ALGORITHM_INCREMENTAL);
3195 rrdset_next(ifm->st_bandwidth);
3197 rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_in, IFA_DATA(ibytes));
3198 rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_out, IFA_DATA(obytes));
3199 rrdset_done(ifm->st_bandwidth);
3202 // --------------------------------------------------------------------
3204 if (ifm->do_packets == CONFIG_BOOLEAN_YES || (ifm->do_packets == CONFIG_BOOLEAN_AUTO &&
3205 (IFA_DATA(ipackets) || IFA_DATA(opackets) || IFA_DATA(imcasts) || IFA_DATA(omcasts)))) {
3206 if (unlikely(!ifm->st_packets)) {
3207 ifm->st_packets = rrdset_create_localhost("net_packets",
3219 rrdset_flag_set(ifm->st_packets, RRDSET_FLAG_DETAIL);
3221 ifm->rd_packets_in = rrddim_add(ifm->st_packets, "received", NULL, 1, 1,
3222 RRD_ALGORITHM_INCREMENTAL);
3223 ifm->rd_packets_out = rrddim_add(ifm->st_packets, "sent", NULL, -1, 1,
3224 RRD_ALGORITHM_INCREMENTAL);
3225 ifm->rd_packets_m_in = rrddim_add(ifm->st_packets, "multicast_received", NULL, 1, 1,
3226 RRD_ALGORITHM_INCREMENTAL);
3227 ifm->rd_packets_m_out = rrddim_add(ifm->st_packets, "multicast_sent", NULL, -1, 1,
3228 RRD_ALGORITHM_INCREMENTAL);
3230 rrdset_next(ifm->st_packets);
3232 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_in, IFA_DATA(ipackets));
3233 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_out, IFA_DATA(opackets));
3234 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_in, IFA_DATA(imcasts));
3235 rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_out, IFA_DATA(omcasts));
3236 rrdset_done(ifm->st_packets);
3239 // --------------------------------------------------------------------
3241 if (ifm->do_errors == CONFIG_BOOLEAN_YES || (ifm->do_errors == CONFIG_BOOLEAN_AUTO &&
3242 (IFA_DATA(ierrors) || IFA_DATA(oerrors)))) {
3243 if (unlikely(!ifm->st_errors)) {
3244 ifm->st_errors = rrdset_create_localhost("net_errors",
3256 rrdset_flag_set(ifm->st_errors, RRDSET_FLAG_DETAIL);
3258 ifm->rd_errors_in = rrddim_add(ifm->st_errors, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3259 ifm->rd_errors_out = rrddim_add(ifm->st_errors, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3261 rrdset_next(ifm->st_errors);
3263 rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_in, IFA_DATA(ierrors));
3264 rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_out, IFA_DATA(oerrors));
3265 rrdset_done(ifm->st_errors);
3267 // --------------------------------------------------------------------
3269 if (ifm->do_drops == CONFIG_BOOLEAN_YES || (ifm->do_drops == CONFIG_BOOLEAN_AUTO &&
3270 (IFA_DATA(iqdrops) || IFA_DATA(oqdrops)))) {
3271 if (unlikely(!ifm->st_drops)) {
3272 ifm->st_drops = rrdset_create_localhost("net_drops",
3284 rrdset_flag_set(ifm->st_drops, RRDSET_FLAG_DETAIL);
3286 ifm->rd_drops_in = rrddim_add(ifm->st_drops, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3287 #if __FreeBSD__ >= 11
3288 ifm->rd_drops_out = rrddim_add(ifm->st_drops, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3291 rrdset_next(ifm->st_drops);
3293 rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_in, IFA_DATA(iqdrops));
3294 #if __FreeBSD__ >= 11
3295 rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_out, IFA_DATA(oqdrops));
3297 rrdset_done(ifm->st_drops);
3300 // --------------------------------------------------------------------
3302 if (ifm->do_events == CONFIG_BOOLEAN_YES || (ifm->do_events == CONFIG_BOOLEAN_AUTO &&
3303 IFA_DATA(collisions))) {
3304 if (unlikely(!ifm->st_events)) {
3305 ifm->st_events = rrdset_create_localhost("net_events",
3310 "Network Interface Events",
3317 rrdset_flag_set(ifm->st_events, RRDSET_FLAG_DETAIL);
3319 ifm->rd_events_coll = rrddim_add(ifm->st_events, "collisions", NULL, -1, 1,
3320 RRD_ALGORITHM_INCREMENTAL);
3322 rrdset_next(ifm->st_events);
3324 rrddim_set_by_pointer(ifm->st_events, ifm->rd_events_coll, IFA_DATA(collisions));
3325 rrdset_done(ifm->st_events);
3332 error("DISABLED: getifaddrs module");
3339 // --------------------------------------------------------------------------------------------------------------------
3342 int do_kern_devstat(int update_every, usec_t dt) {
3344 #define DELAULT_EXLUDED_DISKS ""
3345 #define CONFIG_SECTION_KERN_DEVSTAT "plugin:freebsd:kern.devstat"
3346 #define BINTIME_SCALE 5.42101086242752217003726400434970855712890625e-17 // this is 1000/2^64
3348 static int enable_pass_devices = -1, do_system_io = -1, do_io = -1, do_ops = -1, do_qops = -1, do_util = -1,
3349 do_iotime = -1, do_await = -1, do_avagsz = -1, do_svctm = -1;
3351 if (unlikely(enable_pass_devices == -1)) {
3352 enable_pass_devices = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT,
3353 "performance metrics for pass devices", CONFIG_BOOLEAN_AUTO);
3355 do_system_io = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "total bandwidth for all disks",
3356 CONFIG_BOOLEAN_YES);
3358 do_io = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "bandwidth for all disks",
3359 CONFIG_BOOLEAN_AUTO);
3360 do_ops = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "operations for all disks",
3361 CONFIG_BOOLEAN_AUTO);
3362 do_qops = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "queued operations for all disks",
3363 CONFIG_BOOLEAN_AUTO);
3364 do_util = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "utilization percentage for all disks",
3365 CONFIG_BOOLEAN_AUTO);
3366 do_iotime = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "i/o time for all disks",
3367 CONFIG_BOOLEAN_AUTO);
3368 do_await = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average completed i/o time for all disks",
3369 CONFIG_BOOLEAN_AUTO);
3370 do_avagsz = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average completed i/o bandwidth for all disks",
3371 CONFIG_BOOLEAN_AUTO);
3372 do_svctm = config_get_boolean_ondemand(CONFIG_SECTION_KERN_DEVSTAT, "average service time for all disks",
3373 CONFIG_BOOLEAN_AUTO);
3376 if (likely(do_system_io || do_io || do_ops || do_qops || do_util || do_iotime || do_await || do_avagsz || do_svctm)) {
3377 static int mib_numdevs[3] = {0, 0, 0};
3379 int common_error = 0;
3381 if (unlikely(GETSYSCTL_SIMPLE("kern.devstat.numdevs", mib_numdevs, numdevs))) {
3384 static int mib_devstat[3] = {0, 0, 0};
3385 static void *devstat_data = NULL;
3387 devstat_data = reallocz(devstat_data, sizeof(long) + sizeof(struct devstat) * numdevs); // there is generation number before devstat structures
3388 if (unlikely(GETSYSCTL_WSIZE("kern.devstat.all", mib_devstat, devstat_data,
3389 sizeof(long) + sizeof(struct devstat) * numdevs))) {
3392 struct devstat *dstat;
3394 collected_number total_disk_kbytes_read = 0;
3395 collected_number total_disk_kbytes_write = 0;
3397 // Data to be stored in DICTIONARY disks.
3398 // This DICTIONARY is used to lookup the settings of the disks on each iteration.
3399 struct disks_metadata {
3410 // data for differential charts
3413 collected_number bytes_read;
3414 collected_number bytes_write;
3415 collected_number operations_read;
3416 collected_number operations_write;
3417 collected_number duration_read_ms;
3418 collected_number duration_write_ms;
3419 collected_number busy_time_ms;
3422 // charts and dimensions
3439 RRDDIM *rd_iotime_in;
3440 RRDDIM *rd_iotime_out;
3443 RRDDIM *rd_await_in;
3444 RRDDIM *rd_await_out;
3447 RRDDIM *rd_avagsz_in;
3448 RRDDIM *rd_avagsz_out;
3454 static DICTIONARY *disks = NULL;
3455 static SIMPLE_PATTERN *excluded_disks = NULL;
3457 if(unlikely(!disks)) {
3459 excluded_disks = simple_pattern_create(
3460 config_get(CONFIG_SECTION_KERN_DEVSTAT, "disable by default disks matching",
3461 DELAULT_EXLUDED_DISKS)
3462 , SIMPLE_PATTERN_EXACT
3465 disks = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
3468 dstat = devstat_data + sizeof(long); // skip generation number
3470 for (i = 0; i < numdevs; i++) {
3471 if (likely(do_system_io)) {
3472 if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
3473 total_disk_kbytes_read += dstat[i].bytes[DEVSTAT_READ] / KILO_FACTOR;
3474 total_disk_kbytes_write += dstat[i].bytes[DEVSTAT_WRITE] / KILO_FACTOR;
3478 if (unlikely(!enable_pass_devices))
3479 if (dstat[i].device_type & DEVSTAT_TYPE_PASS == DEVSTAT_TYPE_PASS)
3482 if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
3483 char disk[DEVSTAT_NAME_LEN + MAX_INT_DIGITS + 1];
3484 int def_io, def_ops, def_qops, def_util, def_iotime, def_await, def_avagsz, def_svctm,
3485 iter_io, iter_ops, iter_qops, iter_util, iter_iotime, iter_await, iter_avagsz, iter_svctm;
3487 collected_number duration_read_ms;
3488 collected_number duration_write_ms;
3489 collected_number busy_time_ms;
3492 sprintf(disk, "%s%d", dstat[i].device_name, dstat[i].unit_number);
3494 struct disks_metadata *dm = dictionary_get(disks, disk);
3496 char var_name[4096 + 1];
3497 snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_KERN_DEVSTAT, disk);
3503 def_iotime = do_iotime;
3504 def_await = do_await;
3505 def_avagsz = do_avagsz;
3506 def_svctm = do_svctm;
3508 if(unlikely(simple_pattern_matches(excluded_disks, disk))) {
3509 def_io = CONFIG_BOOLEAN_NO;
3510 def_ops = CONFIG_BOOLEAN_NO;
3511 def_qops = CONFIG_BOOLEAN_NO;
3512 def_util = CONFIG_BOOLEAN_NO;
3513 def_iotime = CONFIG_BOOLEAN_NO;
3514 def_await = CONFIG_BOOLEAN_NO;
3515 def_avagsz = CONFIG_BOOLEAN_NO;
3516 def_svctm = CONFIG_BOOLEAN_NO;
3519 iter_io = config_get_boolean_ondemand(var_name, "bandwidth", def_io);
3520 iter_ops = config_get_boolean_ondemand(var_name, "operations", def_ops);
3521 iter_qops = config_get_boolean_ondemand(var_name, "queued operations", def_qops);
3522 iter_util = config_get_boolean_ondemand(var_name, "utilization percentage", def_util);
3523 iter_iotime = config_get_boolean_ondemand(var_name, "i/o time", def_iotime);
3524 iter_await = config_get_boolean_ondemand(var_name, "average completed i/o time", def_await);
3525 iter_avagsz = config_get_boolean_ondemand(var_name, "average completed i/o bandwidth",
3527 iter_svctm = config_get_boolean_ondemand(var_name, "average service time", def_svctm);
3529 struct disks_metadata dmp = {
3532 .do_qops = iter_qops,
3533 .do_util = iter_util,
3534 .do_iotime = iter_iotime,
3535 .do_await = iter_await,
3536 .do_avagsz = iter_avagsz,
3537 .do_svctm = iter_svctm,
3539 // initialise data for differential charts
3541 .prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ],
3542 .prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE],
3543 .prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ],
3544 .prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE],
3545 .prev_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
3546 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE,
3547 .prev_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
3548 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE,
3549 .prev_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000
3550 + dstat[i].busy_time.frac * BINTIME_SCALE,
3567 .rd_iotime_in = NULL,
3568 .rd_iotime_out = NULL,
3571 .rd_await_in = NULL,
3572 .rd_await_out = NULL,
3575 .rd_avagsz_in = NULL,
3576 .rd_avagsz_out = NULL,
3582 dm = dictionary_set(disks, disk, &dmp, sizeof(struct disks_metadata));
3585 cur_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
3586 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3587 cur_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
3588 + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
3589 cur_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000 + dstat[i].busy_time.frac * BINTIME_SCALE;
3591 // --------------------------------------------------------------------
3593 if(dm->do_io == CONFIG_BOOLEAN_YES || (dm->do_io == CONFIG_BOOLEAN_AUTO &&
3594 (dstat[i].bytes[DEVSTAT_READ] || dstat[i].bytes[DEVSTAT_WRITE]))) {
3595 if (unlikely(!dm->st_io)) {
3596 dm->st_io = rrdset_create_localhost("disk",
3601 "Disk I/O Bandwidth",
3608 dm->rd_io_in = rrddim_add(dm->st_io, "reads", NULL, 1, KILO_FACTOR,
3609 RRD_ALGORITHM_INCREMENTAL);
3610 dm->rd_io_out = rrddim_add(dm->st_io, "writes", NULL, -1, KILO_FACTOR,
3611 RRD_ALGORITHM_INCREMENTAL);
3613 rrdset_next(dm->st_io);
3615 rrddim_set_by_pointer(dm->st_io, dm->rd_io_in, dstat[i].bytes[DEVSTAT_READ]);
3616 rrddim_set_by_pointer(dm->st_io, dm->rd_io_out, dstat[i].bytes[DEVSTAT_WRITE]);
3617 rrdset_done(dm->st_io);
3620 // --------------------------------------------------------------------
3622 if(dm->do_ops == CONFIG_BOOLEAN_YES || (dm->do_ops == CONFIG_BOOLEAN_AUTO &&
3623 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3624 if (unlikely(!dm->st_ops)) {
3625 dm->st_ops = rrdset_create_localhost("disk_ops",
3630 "Disk Completed I/O Operations",
3637 rrdset_flag_set(dm->st_ops, RRDSET_FLAG_DETAIL);
3639 dm->rd_ops_in = rrddim_add(dm->st_ops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3640 dm->rd_ops_out = rrddim_add(dm->st_ops, "writes", NULL, -1, 1,
3641 RRD_ALGORITHM_INCREMENTAL);
3643 rrdset_next(dm->st_ops);
3645 rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_in, dstat[i].operations[DEVSTAT_READ]);
3646 rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_out, dstat[i].operations[DEVSTAT_WRITE]);
3647 rrdset_done(dm->st_ops);
3650 // --------------------------------------------------------------------
3652 if(dm->do_qops == CONFIG_BOOLEAN_YES || (dm->do_qops == CONFIG_BOOLEAN_AUTO &&
3653 (dstat[i].start_count || dstat[i].end_count))) {
3654 if (unlikely(!dm->st_qops)) {
3655 dm->st_qops = rrdset_create_localhost("disk_qops",
3660 "Disk Current I/O Operations",
3667 rrdset_flag_set(dm->st_qops, RRDSET_FLAG_DETAIL);
3669 dm->rd_qops = rrddim_add(dm->st_qops, "operations", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
3671 rrdset_next(dm->st_qops);
3673 rrddim_set_by_pointer(dm->st_qops, dm->rd_qops, dstat[i].start_count - dstat[i].end_count);
3674 rrdset_done(dm->st_qops);
3677 // --------------------------------------------------------------------
3679 if(dm->do_util == CONFIG_BOOLEAN_YES || (dm->do_util == CONFIG_BOOLEAN_AUTO &&
3680 cur_dstat.busy_time_ms)) {
3681 if (unlikely(!dm->st_util)) {
3682 dm->st_util = rrdset_create_localhost("disk_util",
3687 "Disk Utilization Time",
3688 "% of time working",
3694 rrdset_flag_set(dm->st_util, RRDSET_FLAG_DETAIL);
3696 dm->rd_util = rrddim_add(dm->st_util, "utilization", NULL, 1, 10,
3697 RRD_ALGORITHM_INCREMENTAL);
3699 rrdset_next(dm->st_util);
3701 rrddim_set_by_pointer(dm->st_util, dm->rd_util, cur_dstat.busy_time_ms);
3702 rrdset_done(dm->st_util);
3705 // --------------------------------------------------------------------
3707 if(dm->do_iotime == CONFIG_BOOLEAN_YES || (dm->do_iotime == CONFIG_BOOLEAN_AUTO &&
3708 (cur_dstat.duration_read_ms || cur_dstat.duration_write_ms))) {
3709 if (unlikely(!dm->st_iotime)) {
3710 dm->st_iotime = rrdset_create_localhost("disk_iotime",
3715 "Disk Total I/O Time",
3722 rrdset_flag_set(dm->st_iotime, RRDSET_FLAG_DETAIL);
3724 dm->rd_iotime_in = rrddim_add(dm->st_iotime, "reads", NULL, 1, 1,
3725 RRD_ALGORITHM_INCREMENTAL);
3726 dm->rd_iotime_out = rrddim_add(dm->st_iotime, "writes", NULL, -1, 1,
3727 RRD_ALGORITHM_INCREMENTAL);
3729 rrdset_next(dm->st_iotime);
3731 rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_in, cur_dstat.duration_read_ms);
3732 rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_out, cur_dstat.duration_write_ms);
3733 rrdset_done(dm->st_iotime);
3736 // --------------------------------------------------------------------
3737 // calculate differential charts
3738 // only if this is not the first time we run
3742 // --------------------------------------------------------------------
3744 if(dm->do_await == CONFIG_BOOLEAN_YES || (dm->do_await == CONFIG_BOOLEAN_AUTO &&
3745 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3746 if (unlikely(!dm->st_await)) {
3747 dm->st_await = rrdset_create_localhost("disk_await",
3752 "Average Completed I/O Operation Time",
3759 rrdset_flag_set(dm->st_await, RRDSET_FLAG_DETAIL);
3761 dm->rd_await_in = rrddim_add(dm->st_await, "reads", NULL, 1, 1,
3762 RRD_ALGORITHM_ABSOLUTE);
3763 dm->rd_await_out = rrddim_add(dm->st_await, "writes", NULL, -1, 1,
3764 RRD_ALGORITHM_ABSOLUTE);
3766 rrdset_next(dm->st_await);
3768 rrddim_set_by_pointer(dm->st_await, dm->rd_await_in,
3769 (dstat[i].operations[DEVSTAT_READ] -
3770 dm->prev_dstat.operations_read) ?
3771 (cur_dstat.duration_read_ms - dm->prev_dstat.duration_read_ms) /
3772 (dstat[i].operations[DEVSTAT_READ] -
3773 dm->prev_dstat.operations_read) :
3775 rrddim_set_by_pointer(dm->st_await, dm->rd_await_out,
3776 (dstat[i].operations[DEVSTAT_WRITE] -
3777 dm->prev_dstat.operations_write) ?
3778 (cur_dstat.duration_write_ms - dm->prev_dstat.duration_write_ms) /
3779 (dstat[i].operations[DEVSTAT_WRITE] -
3780 dm->prev_dstat.operations_write) :
3782 rrdset_done(dm->st_await);
3785 // --------------------------------------------------------------------
3787 if(dm->do_avagsz == CONFIG_BOOLEAN_YES || (dm->do_avagsz == CONFIG_BOOLEAN_AUTO &&
3788 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3789 if (unlikely(!dm->st_avagsz)) {
3790 dm->st_avagsz = rrdset_create_localhost("disk_avgsz",
3795 "Average Completed I/O Operation Bandwidth",
3796 "kilobytes per operation",
3802 rrdset_flag_set(dm->st_avagsz, RRDSET_FLAG_DETAIL);
3804 dm->rd_avagsz_in = rrddim_add(dm->st_avagsz, "reads", NULL, 1, KILO_FACTOR,
3805 RRD_ALGORITHM_ABSOLUTE);
3806 dm->rd_avagsz_out = rrddim_add(dm->st_avagsz, "writes", NULL, -1, KILO_FACTOR,
3807 RRD_ALGORITHM_ABSOLUTE);
3809 rrdset_next(dm->st_avagsz);
3811 rrddim_set_by_pointer(dm->st_avagsz, dm->rd_avagsz_in,
3812 (dstat[i].operations[DEVSTAT_READ] -
3813 dm->prev_dstat.operations_read) ?
3814 (dstat[i].bytes[DEVSTAT_READ] - dm->prev_dstat.bytes_read) /
3815 (dstat[i].operations[DEVSTAT_READ] -
3816 dm->prev_dstat.operations_read) :
3818 rrddim_set_by_pointer(dm->st_avagsz, dm->rd_avagsz_out,
3819 (dstat[i].operations[DEVSTAT_WRITE] -
3820 dm->prev_dstat.operations_write) ?
3821 (dstat[i].bytes[DEVSTAT_WRITE] - dm->prev_dstat.bytes_write) /
3822 (dstat[i].operations[DEVSTAT_WRITE] -
3823 dm->prev_dstat.operations_write) :
3825 rrdset_done(dm->st_avagsz);
3828 // --------------------------------------------------------------------
3830 if(dm->do_svctm == CONFIG_BOOLEAN_YES || (dm->do_svctm == CONFIG_BOOLEAN_AUTO &&
3831 (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
3832 if (unlikely(!dm->st_svctm)) {
3833 dm->st_svctm = rrdset_create_localhost("disk_svctm",
3838 "Average Service Time",
3845 rrdset_flag_set(dm->st_svctm, RRDSET_FLAG_DETAIL);
3847 dm->rd_svctm = rrddim_add(dm->st_svctm, "svctm", NULL, 1, 1,
3848 RRD_ALGORITHM_ABSOLUTE);
3850 rrdset_next(dm->st_svctm);
3852 rrddim_set_by_pointer(dm->st_svctm, dm->rd_svctm,
3853 ((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
3854 (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) ?
3855 (cur_dstat.busy_time_ms - dm->prev_dstat.busy_time_ms) /
3856 ((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
3857 (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) :
3859 rrdset_done(dm->st_svctm);
3862 // --------------------------------------------------------------------
3864 dm->prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ];
3865 dm->prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE];
3866 dm->prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ];
3867 dm->prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE];
3868 dm->prev_dstat.duration_read_ms = cur_dstat.duration_read_ms;
3869 dm->prev_dstat.duration_write_ms = cur_dstat.duration_write_ms;
3870 dm->prev_dstat.busy_time_ms = cur_dstat.busy_time_ms;
3875 // --------------------------------------------------------------------
3877 if (likely(do_system_io)) {
3878 static RRDSET *st = NULL;
3879 static RRDDIM *rd_in = NULL, *rd_out = NULL;
3881 if (unlikely(!st)) {
3882 st = rrdset_create_localhost("system",
3894 rd_in = rrddim_add(st, "in", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
3895 rd_out = rrddim_add(st, "out", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
3899 rrddim_set_by_pointer(st, rd_in, total_disk_kbytes_read);
3900 rrddim_set_by_pointer(st, rd_out, total_disk_kbytes_write);
3905 if (unlikely(common_error)) {
3907 error("DISABLED: system.io chart");
3909 error("DISABLED: disk.* charts");
3911 error("DISABLED: disk_ops.* charts");
3913 error("DISABLED: disk_qops.* charts");
3915 error("DISABLED: disk_util.* charts");
3917 error("DISABLED: disk_iotime.* charts");
3919 error("DISABLED: disk_await.* charts");
3921 error("DISABLED: disk_avgsz.* charts");
3923 error("DISABLED: disk_svctm.* charts");
3924 error("DISABLED: kern.devstat module");
3928 error("DISABLED: kern.devstat module");