3 static struct freebsd_module {
9 int (*func)(int update_every, usec_t dt);
14 } freebsd_modules[] = {
16 { .name = "freebsd_old", .dim = "freebsd_old", .enabled = 1, .func = do_freebsd_sysctl_old },
19 { .name = "vm.loadavg", .dim = "loadavg", .enabled = 1, .func = do_vm_loadavg },
20 { .name = "vm.vmtotal", .dim = "vmtotal", .enabled = 1, .func = do_vm_vmtotal },
21 { .name = "kern.cp_time", .dim = "cp_time", .enabled = 1, .func = do_kern_cp_time },
22 { .name = "hw.intrcnt", .dim = "hw_intr", .enabled = 1, .func = do_hw_intcnt },
23 { .name = "vm.stats.sys.v_intr", .dim = "dev_intr", .enabled = 1, .func = do_vm_stats_sys_v_intr },
24 { .name = "vm.stats.sys.v_soft", .dim = "soft_intr", .enabled = 1, .func = do_vm_stats_sys_v_soft },
25 { .name = "vm.stats.sys.v_swtch", .dim = "context_swtch", .enabled = 1, .func = do_vm_stats_sys_v_swtch },
26 { .name = "vm.stats.vm.v_forks", .dim = "forks", .enabled = 1, .func = do_vm_stats_sys_v_forks },
27 { .name = "vm.swap_info", .dim = "swap", .enabled = 1, .func = do_vm_swap_info },
28 { .name = "system.ram", .dim = "system_ram", .enabled = 1, .func = do_system_ram },
29 { .name = "vm.stats.vm.v_swappgs", .dim = "swap_io", .enabled = 1, .func = do_vm_stats_sys_v_swappgs },
30 { .name = "kern.ipc.sem", .dim = "semaphores", .enabled = 1, .func = do_kern_ipc_sem },
31 { .name = "kern.ipc.shm", .dim = "shared_memory", .enabled = 1, .func = do_kern_ipc_shm },
32 { .name = "kern.ipc.msq", .dim = "message_queues", .enabled = 1, .func = do_kern_ipc_msq },
35 { .name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times },
38 { .name = "vm.stats.vm.v_pgfaults", .dim = "pgfaults", .enabled = 1, .func = do_vm_stats_sys_v_pgfaults },
40 // the terminator of this array
41 { .name = NULL, .dim = NULL, .enabled = 0, .func = NULL }
44 void *freebsd_main(void *ptr) {
45 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
47 info("FREEBSD Plugin thread created with task id %d", gettid());
49 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
50 error("Cannot set pthread cancel type to DEFERRED.");
52 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
53 error("Cannot set pthread cancel state to ENABLE.");
55 int vdo_cpu_netdata = config_get_boolean("plugin:freebsd", "netdata server resources", 1);
57 // initialize FreeBSD plugin
58 if (freebsd_plugin_init())
61 // check the enabled status for each module
63 for(i = 0 ; freebsd_modules[i].name ;i++) {
64 struct freebsd_module *pm = &freebsd_modules[i];
66 pm->enabled = config_get_boolean("plugin:freebsd", pm->name, pm->enabled);
71 usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
76 usec_t hb_dt = heartbeat_next(&hb, step);
77 usec_t duration = 0ULL;
79 if(unlikely(netdata_exit)) break;
81 // BEGIN -- the job to be done
83 for(i = 0 ; freebsd_modules[i].name ;i++) {
84 struct freebsd_module *pm = &freebsd_modules[i];
85 if(unlikely(!pm->enabled)) continue;
87 debug(D_PROCNETDEV_LOOP, "FREEBSD calling %s.", pm->name);
89 pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
90 pm->duration = heartbeat_dt_usec(&hb) - duration;
91 duration += pm->duration;
93 if(unlikely(netdata_exit)) break;
96 // END -- the job is done
98 // --------------------------------------------------------------------
100 if(vdo_cpu_netdata) {
101 static RRDSET *st = NULL;
104 st = rrdset_find_bytype_localhost("netdata", "plugin_freebsd_modules");
107 st = rrdset_create_localhost("netdata", "plugin_freebsd_modules", NULL, "freebsd", NULL
108 , "NetData FreeBSD Plugin Modules Durations", "milliseconds/run", 132001
109 , localhost->rrd_update_every, RRDSET_TYPE_STACKED);
111 for(i = 0 ; freebsd_modules[i].name ;i++) {
112 struct freebsd_module *pm = &freebsd_modules[i];
113 if(unlikely(!pm->enabled)) continue;
115 pm->rd = rrddim_add(st, pm->dim, NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
119 else rrdset_next(st);
121 for(i = 0 ; freebsd_modules[i].name ;i++) {
122 struct freebsd_module *pm = &freebsd_modules[i];
123 if(unlikely(!pm->enabled)) continue;
125 rrddim_set_by_pointer(st, pm->rd, pm->duration);
129 global_statistics_charts();
130 registry_statistics();
134 info("FREEBSD thread exiting");
136 static_thread->enabled = 0;