master
c 80 lines 2.25 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "plugin_macos.h"
4
5 static struct macos_module {
6 const char *name;
7 const char *dim;
8
9 int enabled;
10
11 int (*func)(int update_every, usec_t dt);
12
13 RRDDIM *rd;
14
15 } macos_modules[] = {
16 {.name = "sysctl", .dim = "sysctl", .enabled = 1, .func = do_macos_sysctl},
17 {.name = "mach system management interface", .dim = "mach_smi", .enabled = 1, .func = do_macos_mach_smi},
18 {.name = "iokit", .dim = "iokit", .enabled = 1, .func = do_macos_iokit},
19
20 // the terminator of this array
21 {.name = NULL, .dim = NULL, .enabled = 0, .func = NULL}
22 };
23
24 #if WORKER_UTILIZATION_MAX_JOB_TYPES < 3
25 #error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 3
26 #endif
27
28 static void macos_main_cleanup(void *pptr)
29 {
30 struct netdata_static_thread *static_thread = CLEANUP_FUNCTION_GET_PTR(pptr);
31 if(!static_thread) return;
32
33 static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
34
35 worker_unregister();
36
37 static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
38 }
39
40 void macos_main(void *ptr)
41 {
42 CLEANUP_FUNCTION_REGISTER(macos_main_cleanup) cleanup_ptr = ptr;
43
44 worker_register("MACOS");
45
46 // check the enabled status for each module
47 for (int i = 0; macos_modules[i].name; i++) {
48 struct macos_module *pm = &macos_modules[i];
49
50 pm->enabled = inicfg_get_boolean(&netdata_config, "plugin:macos", pm->name, pm->enabled);
51 pm->rd = NULL;
52
53 worker_register_job_name(i, macos_modules[i].dim);
54 }
55
56 heartbeat_t hb;
57 heartbeat_init(&hb, localhost->rrd_update_every * USEC_PER_SEC);
58
59 while(service_running(SERVICE_COLLECTORS)) {
60 worker_is_idle();
61 usec_t hb_dt = heartbeat_next(&hb);
62
63 if (!service_running(SERVICE_COLLECTORS))
64 break;
65
66 for (int i = 0; macos_modules[i].name; i++) {
67 struct macos_module *pm = &macos_modules[i];
68 if (unlikely(!pm->enabled))
69 continue;
70
71 netdata_log_debug(D_PROCNETDEV_LOOP, "macos calling %s.", pm->name);
72
73 worker_is_busy(i);
74 pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
75
76 if (!service_running(SERVICE_COLLECTORS))
77 break;
78 }
79 }
80 }