]> arthur.barton.de Git - netdata.git/blob - src/plugin_freebsd.c
Merge pull request #1914 from NMcCloud/patch-1
[netdata.git] / src / plugin_freebsd.c
1 #include "common.h"
2
3 void *freebsd_main(void *ptr) {
4     struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
5
6     info("FREEBSD Plugin thread created with task id %d", gettid());
7
8     if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
9         error("Cannot set pthread cancel type to DEFERRED.");
10
11     if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
12         error("Cannot set pthread cancel state to ENABLE.");
13
14     // when ZERO, attempt to do it
15     int vdo_cpu_netdata             = !config_get_boolean("plugin:freebsd", "netdata server resources", 1);
16     int vdo_freebsd_sysctl          = !config_get_boolean("plugin:freebsd", "sysctl", 1);
17
18     // keep track of the time each module was called
19     unsigned long long sutime_freebsd_sysctl = 0ULL;
20
21     usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
22     heartbeat_t hb;
23     heartbeat_init(&hb);
24     for(;;) {
25         usec_t hb_dt = heartbeat_next(&hb, step);
26
27         if(unlikely(netdata_exit)) break;
28
29         // BEGIN -- the job to be done
30
31         if(!vdo_freebsd_sysctl) {
32             debug(D_PROCNETDEV_LOOP, "FREEBSD: calling do_freebsd_sysctl().");
33             vdo_freebsd_sysctl = do_freebsd_sysctl(localhost->rrd_update_every, hb_dt);
34         }
35         if(unlikely(netdata_exit)) break;
36
37         // END -- the job is done
38
39         // --------------------------------------------------------------------
40
41         if(!vdo_cpu_netdata) {
42             global_statistics_charts();
43             registry_statistics();
44         }
45     }
46
47     info("FREEBSD thread exiting");
48
49     static_thread->enabled = 0;
50     pthread_exit(NULL);
51     return NULL;
52 }