plugin_freebsd.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "plugin_freebsd.h"
  3. static struct freebsd_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. } freebsd_modules[] = {
  10. // system metrics
  11. {.name = "kern.cp_time", .dim = "cp_time", .enabled = 1, .func = do_kern_cp_time},
  12. {.name = "vm.loadavg", .dim = "loadavg", .enabled = 1, .func = do_vm_loadavg},
  13. {.name = "system.ram", .dim = "system_ram", .enabled = 1, .func = do_system_ram},
  14. {.name = "vm.swap_info", .dim = "swap", .enabled = 1, .func = do_vm_swap_info},
  15. {.name = "vm.stats.vm.v_swappgs", .dim = "swap_io", .enabled = 1, .func = do_vm_stats_sys_v_swappgs},
  16. {.name = "vm.vmtotal", .dim = "vmtotal", .enabled = 1, .func = do_vm_vmtotal},
  17. {.name = "vm.stats.vm.v_forks", .dim = "forks", .enabled = 1, .func = do_vm_stats_sys_v_forks},
  18. {.name = "vm.stats.sys.v_swtch", .dim = "context_swtch", .enabled = 1, .func = do_vm_stats_sys_v_swtch},
  19. {.name = "hw.intrcnt", .dim = "hw_intr", .enabled = 1, .func = do_hw_intcnt},
  20. {.name = "vm.stats.sys.v_intr", .dim = "dev_intr", .enabled = 1, .func = do_vm_stats_sys_v_intr},
  21. {.name = "vm.stats.sys.v_soft", .dim = "soft_intr", .enabled = 1, .func = do_vm_stats_sys_v_soft},
  22. {.name = "net.isr", .dim = "net_isr", .enabled = 1, .func = do_net_isr},
  23. {.name = "kern.ipc.sem", .dim = "semaphores", .enabled = 1, .func = do_kern_ipc_sem},
  24. {.name = "kern.ipc.shm", .dim = "shared_memory", .enabled = 1, .func = do_kern_ipc_shm},
  25. {.name = "kern.ipc.msq", .dim = "message_queues", .enabled = 1, .func = do_kern_ipc_msq},
  26. {.name = "uptime", .dim = "uptime", .enabled = 1, .func = do_uptime},
  27. // memory metrics
  28. {.name = "vm.stats.vm.v_pgfaults", .dim = "pgfaults", .enabled = 1, .func = do_vm_stats_sys_v_pgfaults},
  29. // CPU metrics
  30. {.name = "kern.cp_times", .dim = "cp_times", .enabled = 1, .func = do_kern_cp_times},
  31. {.name = "dev.cpu.temperature", .dim = "cpu_temperature", .enabled = 1, .func = do_dev_cpu_temperature},
  32. {.name = "dev.cpu.0.freq", .dim = "cpu_frequency", .enabled = 1, .func = do_dev_cpu_0_freq},
  33. // disk metrics
  34. {.name = "kern.devstat", .dim = "kern_devstat", .enabled = 1, .func = do_kern_devstat},
  35. {.name = "getmntinfo", .dim = "getmntinfo", .enabled = 1, .func = do_getmntinfo},
  36. // network metrics
  37. {.name = "net.inet.tcp.states", .dim = "tcp_states", .enabled = 1, .func = do_net_inet_tcp_states},
  38. {.name = "net.inet.tcp.stats", .dim = "tcp_stats", .enabled = 1, .func = do_net_inet_tcp_stats},
  39. {.name = "net.inet.udp.stats", .dim = "udp_stats", .enabled = 1, .func = do_net_inet_udp_stats},
  40. {.name = "net.inet.icmp.stats", .dim = "icmp_stats", .enabled = 1, .func = do_net_inet_icmp_stats},
  41. {.name = "net.inet.ip.stats", .dim = "ip_stats", .enabled = 1, .func = do_net_inet_ip_stats},
  42. {.name = "net.inet6.ip6.stats", .dim = "ip6_stats", .enabled = 1, .func = do_net_inet6_ip6_stats},
  43. {.name = "net.inet6.icmp6.stats", .dim = "icmp6_stats", .enabled = 1, .func = do_net_inet6_icmp6_stats},
  44. // network interfaces metrics
  45. {.name = "getifaddrs", .dim = "getifaddrs", .enabled = 1, .func = do_getifaddrs},
  46. // ZFS metrics
  47. {.name = "kstat.zfs.misc.arcstats", .dim = "arcstats", .enabled = 1, .func = do_kstat_zfs_misc_arcstats},
  48. {.name = "kstat.zfs.misc.zio_trim", .dim = "trim", .enabled = 1, .func = do_kstat_zfs_misc_zio_trim},
  49. // ipfw metrics
  50. {.name = "ipfw", .dim = "ipfw", .enabled = 1, .func = do_ipfw},
  51. // the terminator of this array
  52. {.name = NULL, .dim = NULL, .enabled = 0, .func = NULL}
  53. };
  54. #if WORKER_UTILIZATION_MAX_JOB_TYPES < 33
  55. #error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 33
  56. #endif
  57. static void freebsd_main_cleanup(void *ptr)
  58. {
  59. worker_unregister();
  60. struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
  61. static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
  62. info("cleaning up...");
  63. static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
  64. }
  65. void *freebsd_main(void *ptr)
  66. {
  67. worker_register("FREEBSD");
  68. netdata_thread_cleanup_push(freebsd_main_cleanup, ptr);
  69. // initialize FreeBSD plugin
  70. if (freebsd_plugin_init())
  71. netdata_cleanup_and_exit(1);
  72. // check the enabled status for each module
  73. int i;
  74. for (i = 0; freebsd_modules[i].name; i++) {
  75. struct freebsd_module *pm = &freebsd_modules[i];
  76. pm->enabled = config_get_boolean("plugin:freebsd", pm->name, pm->enabled);
  77. pm->rd = NULL;
  78. worker_register_job_name(i, freebsd_modules[i].dim);
  79. }
  80. usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
  81. heartbeat_t hb;
  82. heartbeat_init(&hb);
  83. while (!netdata_exit) {
  84. worker_is_idle();
  85. usec_t hb_dt = heartbeat_next(&hb, step);
  86. if (unlikely(netdata_exit))
  87. break;
  88. for (i = 0; freebsd_modules[i].name; i++) {
  89. struct freebsd_module *pm = &freebsd_modules[i];
  90. if (unlikely(!pm->enabled))
  91. continue;
  92. debug(D_PROCNETDEV_LOOP, "FREEBSD calling %s.", pm->name);
  93. worker_is_busy(i);
  94. pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
  95. if (unlikely(netdata_exit))
  96. break;
  97. }
  98. }
  99. netdata_thread_cleanup_pop(1);
  100. return NULL;
  101. }