3 static struct freebsd_module {
9 int (*func)(int update_every, usec_t dt);
14 } freebsd_modules[] = {
17 { .name = "kern.cp_time", .dim = "cp_time", .enabled = 1, .func = do_kern_cp_time },
18 { .name = "vm.loadavg", .dim = "loadavg", .enabled = 1, .func = do_vm_loadavg },
19 { .name = "system.ram", .dim = "system_ram", .enabled = 1, .func = do_system_ram },
20 { .name = "vm.swap_info", .dim = "swap", .enabled = 1, .func = do_vm_swap_info },
21 { .name = "vm.stats.vm.v_swappgs", .dim = "swap_io", .enabled = 1, .func = do_vm_stats_sys_v_swappgs },
22 { .name = "vm.vmtotal", .dim = "vmtotal", .enabled = 1, .func = do_vm_vmtotal },
23 { .name = "vm.stats.vm.v_forks", .dim = "forks", .enabled = 1, .func = do_vm_stats_sys_v_forks },
24 { .name = "vm.stats.sys.v_swtch", .dim = "context_swtch", .enabled = 1, .func = do_vm_stats_sys_v_swtch },
25 { .name = "hw.intrcnt", .dim = "hw_intr", .enabled = 1, .func = do_hw_intcnt },
26 { .name = "vm.stats.sys.v_intr", .dim = "dev_intr", .enabled = 1, .func = do_vm_stats_sys_v_intr },
27 { .name = "vm.stats.sys.v_soft", .dim = "soft_intr", .enabled = 1, .func = do_vm_stats_sys_v_soft },
28 { .name = "net.isr", .dim = "net_isr", .enabled = 1, .func = do_net_isr },
29 { .name = "kern.ipc.sem", .dim = "semaphores", .enabled = 1, .func = do_kern_ipc_sem },
30 { .name = "kern.ipc.shm", .dim = "shared_memory", .enabled = 1, .func = do_kern_ipc_shm },
31 { .name = "kern.ipc.msq", .dim = "message_queues", .enabled = 1, .func = do_kern_ipc_msq },
32 { .name = "uptime", .dim = "uptime", .enabled = 1, .func = do_uptime },
35 { .name = "vm.stats.vm.v_pgfaults", .dim = "pgfaults", .enabled = 1, .func = do_vm_stats_sys_v_pgfaults },
38 { .name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times },
41 { .name = "kern.devstat", .dim = "kern_devstat", .enabled = 1, .func = do_kern_devstat },
42 { .name = "getmntinfo", .dim = "getmntinfo", .enabled = 1, .func = do_getmntinfo },
45 { .name = "net.inet.tcp.states", .dim = "tcp_states", .enabled = 1, .func = do_net_inet_tcp_states },
46 { .name = "net.inet.tcp.stats", .dim = "tcp_stats", .enabled = 1, .func = do_net_inet_tcp_stats },
47 { .name = "net.inet.udp.stats", .dim = "udp_stats", .enabled = 1, .func = do_net_inet_udp_stats },
48 { .name = "net.inet.icmp.stats", .dim = "icmp_stats", .enabled = 1, .func = do_net_inet_icmp_stats },
49 { .name = "net.inet.ip.stats", .dim = "ip_stats", .enabled = 1, .func = do_net_inet_ip_stats },
50 { .name = "net.inet6.ip6.stats", .dim = "ip6_stats", .enabled = 1, .func = do_net_inet6_ip6_stats },
51 { .name = "net.inet6.icmp6.stats", .dim = "icmp6_stats", .enabled = 1, .func = do_net_inet6_icmp6_stats },
53 // network interfaces metrics
54 { .name = "getifaddrs", .dim = "getifaddrs", .enabled = 1, .func = do_getifaddrs },
56 // the terminator of this array
57 { .name = NULL, .dim = NULL, .enabled = 0, .func = NULL }
60 void *freebsd_main(void *ptr) {
61 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
63 info("FREEBSD Plugin thread created with task id %d", gettid());
65 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
66 error("Cannot set pthread cancel type to DEFERRED.");
68 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
69 error("Cannot set pthread cancel state to ENABLE.");
71 int vdo_cpu_netdata = config_get_boolean("plugin:freebsd", "netdata server resources", 1);
73 // initialize FreeBSD plugin
74 if (freebsd_plugin_init())
77 // check the enabled status for each module
79 for(i = 0 ; freebsd_modules[i].name ;i++) {
80 struct freebsd_module *pm = &freebsd_modules[i];
82 pm->enabled = config_get_boolean("plugin:freebsd", pm->name, pm->enabled);
87 usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
92 usec_t hb_dt = heartbeat_next(&hb, step);
93 usec_t duration = 0ULL;
95 if(unlikely(netdata_exit)) break;
97 // BEGIN -- the job to be done
99 for(i = 0 ; freebsd_modules[i].name ;i++) {
100 struct freebsd_module *pm = &freebsd_modules[i];
101 if(unlikely(!pm->enabled)) continue;
103 debug(D_PROCNETDEV_LOOP, "FREEBSD calling %s.", pm->name);
105 pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
106 pm->duration = heartbeat_dt_usec(&hb) - duration;
107 duration += pm->duration;
109 if(unlikely(netdata_exit)) break;
112 // END -- the job is done
114 // --------------------------------------------------------------------
116 if(vdo_cpu_netdata) {
117 static RRDSET *st = NULL;
120 st = rrdset_find_bytype_localhost("netdata", "plugin_freebsd_modules");
123 st = rrdset_create_localhost("netdata", "plugin_freebsd_modules", NULL, "freebsd", NULL
124 , "NetData FreeBSD Plugin Modules Durations", "milliseconds/run", 132001
125 , localhost->rrd_update_every, RRDSET_TYPE_STACKED);
127 for(i = 0 ; freebsd_modules[i].name ;i++) {
128 struct freebsd_module *pm = &freebsd_modules[i];
129 if(unlikely(!pm->enabled)) continue;
131 pm->rd = rrddim_add(st, pm->dim, NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
135 else rrdset_next(st);
137 for(i = 0 ; freebsd_modules[i].name ;i++) {
138 struct freebsd_module *pm = &freebsd_modules[i];
139 if(unlikely(!pm->enabled)) continue;
141 rrddim_set_by_pointer(st, pm->rd, pm->duration);
145 global_statistics_charts();
146 registry_statistics();
150 info("FREEBSD thread exiting");
152 static_thread->enabled = 0;