2 #include <mach/mach_host.h>
4 int do_macos_mach_smi(int update_every, usec_t dt) {
7 static int do_cpu = -1;
9 if (unlikely(do_cpu == -1)) {
10 do_cpu = config_get_boolean("plugin:macos:mach_smi", "cpu utilization", 1);
15 // NEEDED BY: do_cpu, do_cpu_cores
16 natural_t cp_time[CPU_STATE_MAX];
18 mach_msg_type_number_t count;
20 // --------------------------------------------------------------------
23 if (unlikely(HOST_CPU_LOAD_INFO_COUNT != 4)) {
24 error("FREEBSD: There are %d CPU states (4 was expected)", HOST_CPU_LOAD_INFO_COUNT);
26 error("DISABLED: system.cpu");
28 count = HOST_CPU_LOAD_INFO_COUNT;
29 if (unlikely(kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)cp_time, &count))) {
30 if (kr != KERN_SUCCESS) {
31 error("MACOS: host_statistics() failed: %s", mach_error_string(kr));
33 error("DISABLED: system.cpu");
37 st = rrdset_find_bytype("system", "cpu");
39 st = rrdset_create("system", "cpu", NULL, "cpu", "system.cpu", "Total CPU utilization", "percentage", 100, update_every, RRDSET_TYPE_STACKED);
41 rrddim_add(st, "user", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
42 rrddim_add(st, "nice", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
43 rrddim_add(st, "system", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
44 rrddim_add(st, "idle", NULL, 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
45 rrddim_hide(st, "idle");
49 rrddim_set(st, "user", cp_time[CPU_STATE_USER]);
50 rrddim_set(st, "nice", cp_time[CPU_STATE_NICE]);
51 rrddim_set(st, "system", cp_time[CPU_STATE_SYSTEM]);
52 rrddim_set(st, "idle", cp_time[CPU_STATE_IDLE]);