port_host = mach_host_self ();
- /* FIXME: Free `cpu_list' if it's not NULL */
- if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS)
+ status = host_processors (port_host, &cpu_list, &cpu_list_len);
+ if (status == KERN_INVALID_ARGUMENT)
{
- ERROR ("cpu plugin: host_processors returned %i", (int) status);
+ ERROR ("cpu plugin: Don't have a privileged host control port. "
+ "The most common cause for this problem is "
+ "that collectd is running without root "
+ "privileges, which are required to read CPU "
+ "load information. "
+ "<https://collectd.org/bugs/22>");
+ cpu_list_len = 0;
+ return (-1);
+ }
+ if (status != KERN_SUCCESS)
+ {
+ ERROR ("cpu plugin: host_processors() failed with status %d.", (int) status);
cpu_list_len = 0;
return (-1);
}
- DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors");
INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s");
-
- cpu_temp_retry_max = 86400 / CDTIME_T_TO_TIME_T (plugin_get_interval ());
/* #endif PROCESSOR_CPU_LOAD_INFO */
#elif defined(HAVE_LIBKSTAT)
RATE_ADD (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate, this_cpu_states[state].rate);
}
+ if (!isnan (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate))
+ this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].has_value = 1;
+
RATE_ADD (sum_by_state[COLLECTD_CPU_STATE_ACTIVE], this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate);
}
} /* }}} void aggregate */
};
size_t state;
- for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+ for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
if (this_cpu_states[state].has_value)
local_rates[state] = this_cpu_states[state].rate;
continue;
}
- if (cpu_info_len < COLLECTD_CPU_STATE_MAX)
+ if (cpu_info_len < CPU_STATE_MAX)
{
ERROR ("cpu plugin: processor_info returned only %i elements..", cpu_info_len);
continue;
}
- cpu_stage (cpu, COLLECTD_CPU_STATE_USER, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_USER], now);
- cpu_stage (cpu, COLLECTD_CPU_STATE_NICE, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_NICE], now);
- cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_SYSTEM], now);
- cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_IDLE], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_USER, (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_NICE, (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM], now);
+ cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE, (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE], now);
}
/* }}} #endif PROCESSOR_CPU_LOAD_INFO */