plugin_macos.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "plugin_macos.h"
  3. static struct macos_module {
  4. const char *name;
  5. const char *dim;
  6. int enabled;
  7. int (*func)(int update_every, usec_t dt);
  8. RRDDIM *rd;
  9. } macos_modules[] = {
  10. {.name = "sysctl", .dim = "sysctl", .enabled = 1, .func = do_macos_sysctl},
  11. {.name = "mach system management interface", .dim = "mach_smi", .enabled = 1, .func = do_macos_mach_smi},
  12. {.name = "iokit", .dim = "iokit", .enabled = 1, .func = do_macos_iokit},
  13. // the terminator of this array
  14. {.name = NULL, .dim = NULL, .enabled = 0, .func = NULL}
  15. };
  16. #if WORKER_UTILIZATION_MAX_JOB_TYPES < 3
  17. #error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 3
  18. #endif
  19. static void macos_main_cleanup(void *ptr)
  20. {
  21. worker_unregister();
  22. struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
  23. static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
  24. collector_info("cleaning up...");
  25. static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
  26. }
  27. void *macos_main(void *ptr)
  28. {
  29. worker_register("MACOS");
  30. netdata_thread_cleanup_push(macos_main_cleanup, ptr);
  31. // check the enabled status for each module
  32. for (int i = 0; macos_modules[i].name; i++) {
  33. struct macos_module *pm = &macos_modules[i];
  34. pm->enabled = config_get_boolean("plugin:macos", pm->name, pm->enabled);
  35. pm->rd = NULL;
  36. worker_register_job_name(i, macos_modules[i].dim);
  37. }
  38. usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
  39. heartbeat_t hb;
  40. heartbeat_init(&hb);
  41. while (!netdata_exit) {
  42. worker_is_idle();
  43. usec_t hb_dt = heartbeat_next(&hb, step);
  44. for (int i = 0; macos_modules[i].name; i++) {
  45. struct macos_module *pm = &macos_modules[i];
  46. if (unlikely(!pm->enabled))
  47. continue;
  48. debug(D_PROCNETDEV_LOOP, "macos calling %s.", pm->name);
  49. worker_is_busy(i);
  50. pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
  51. if (unlikely(netdata_exit))
  52. break;
  53. }
  54. }
  55. netdata_thread_cleanup_pop(1);
  56. return NULL;
  57. }