]> arthur.barton.de Git - netdata.git/blob - src/macos_mach_smi.c
Separate macOS plugin
[netdata.git] / src / macos_mach_smi.c
1 #include "common.h"
2
3 int do_macos_mach_smi(int update_every, usec_t dt) {
4     (void)dt;
5
6     static int do_cpu = -1;
7
8     if (unlikely(do_cpu == -1)) {
9         do_cpu                  = config_get_boolean("plugin:macos:mach_smi", "cpu utilization", 1);
10     }
11
12     RRDSET *st;
13
14     // NEEDED BY: do_cpu, do_cpu_cores
15     long cp_time[5];
16
17     // --------------------------------------------------------------------
18
19     if (likely(do_cpu)) {
20         if (unlikely(1)) {
21             do_cpu = 0;
22             error("DISABLED: system.cpu");
23         } else {
24
25             st = rrdset_find_bytype("system", "cpu");
26             if (unlikely(!st)) {
27                 st = rrdset_create("system", "cpu", NULL, "cpu", "system.cpu", "Total CPU utilization", "percentage", 100, update_every, RRDSET_TYPE_STACKED);
28
29                 rrddim_add(st, "user", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
30                 rrddim_add(st, "nice", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
31                 rrddim_add(st, "system", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
32                 rrddim_add(st, "interrupt", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
33                 rrddim_add(st, "idle", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
34                 rrddim_hide(st, "idle");
35             }
36             else rrdset_next(st);
37
38             rrddim_set(st, "user", cp_time[0]);
39             rrddim_set(st, "nice", cp_time[1]);
40             rrddim_set(st, "system", cp_time[2]);
41             rrddim_set(st, "interrupt", cp_time[3]);
42             rrddim_set(st, "idle", cp_time[4]);
43             rrdset_done(st);
44         }
45      }
46
47     return 0;
48 }