| 1 |
#include <gm_metric.h> |
| 2 |
#include <libmetrics.h> |
| 3 |
|
| 4 |
mmodule cpu_module; |
| 5 |
|
| 6 |
/* |
| 7 |
** A helper function to determine the number of cpustates in /proc/stat (MKN) |
| 8 |
*/ |
| 9 |
|
| 10 |
static int cpu_metric_init ( apr_pool_t *p ) |
| 11 |
{ |
| 12 |
int i; |
| 13 |
|
| 14 |
libmetrics_init(); |
| 15 |
|
| 16 |
for (i = 0; cpu_module.metrics_info[i].name != NULL; i++) { |
| 17 |
/* Initialize the metadata storage for each of the metrics and then |
| 18 |
* store one or more key/value pairs. The define MGROUPS defines |
| 19 |
* the key for the grouping attribute. */ |
| 20 |
MMETRIC_INIT_METADATA(&(cpu_module.metrics_info[i]),p); |
| 21 |
MMETRIC_ADD_METADATA(&(cpu_module.metrics_info[i]),MGROUP,"cpu"); |
| 22 |
} |
| 23 |
|
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
static void cpu_metric_cleanup ( void ) |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
static g_val_t cpu_metric_handler ( int metric_index ) |
| 32 |
{ |
| 33 |
g_val_t val; |
| 34 |
|
| 35 |
/* The metric_index corresponds to the order in which |
| 36 |
the metrics appear in the metric_info array |
| 37 |
*/ |
| 38 |
switch (metric_index) { |
| 39 |
case 0: |
| 40 |
return cpu_num_func(); |
| 41 |
case 1: |
| 42 |
return cpu_speed_func(); |
| 43 |
case 2: |
| 44 |
return cpu_user_func(); |
| 45 |
case 3: |
| 46 |
return cpu_nice_func(); |
| 47 |
case 4: |
| 48 |
return cpu_system_func(); |
| 49 |
case 5: |
| 50 |
return cpu_idle_func(); |
| 51 |
case 6: |
| 52 |
return cpu_aidle_func(); |
| 53 |
case 7: |
| 54 |
return cpu_wio_func(); |
| 55 |
case 8: |
| 56 |
return cpu_intr_func(); |
| 57 |
case 9: |
| 58 |
return cpu_sintr_func(); |
| 59 |
case 10: |
| 60 |
return cpu_steal_func(); |
| 61 |
} |
| 62 |
|
| 63 |
/* default case */ |
| 64 |
val.int32 = 0; |
| 65 |
return val; |
| 66 |
} |
| 67 |
|
| 68 |
static Ganglia_25metric cpu_metric_info[] = |
| 69 |
{ |
| 70 |
{0, "cpu_num", 1200, GANGLIA_VALUE_UNSIGNED_SHORT, "CPUs", "zero", "%hu", UDP_HEADER_SIZE+8, "Total number of CPUs"}, |
| 71 |
{0, "cpu_speed", 1200, GANGLIA_VALUE_UNSIGNED_INT, "MHz", "zero", "%u", UDP_HEADER_SIZE+8, "CPU Speed in terms of MHz"}, |
| 72 |
{0, "cpu_user", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percentage of CPU utilization that occurred while executing at the user level"}, |
| 73 |
{0, "cpu_nice", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percentage of CPU utilization that occurred while executing at the user level with nice priority"}, |
| 74 |
{0, "cpu_system", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percentage of CPU utilization that occurred while executing at the system level"}, |
| 75 |
{0, "cpu_idle", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request"}, |
| 76 |
{0, "cpu_aidle", 3800, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percent of time since boot idle CPU"}, |
| 77 |
{0, "cpu_wio", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request"}, |
| 78 |
{0, "cpu_intr", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "cpu_intr"}, |
| 79 |
{0, "cpu_sintr", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "cpu_sintr"}, |
| 80 |
{0, "cpu_steal", 90, GANGLIA_VALUE_FLOAT, "%", "both", "%.1f", UDP_HEADER_SIZE+8, "cpu_steal"}, |
| 81 |
{0, NULL} |
| 82 |
|
| 83 |
}; |
| 84 |
|
| 85 |
mmodule cpu_module = |
| 86 |
{ |
| 87 |
STD_MMODULE_STUFF, |
| 88 |
cpu_metric_init, |
| 89 |
cpu_metric_cleanup, |
| 90 |
cpu_metric_info, |
| 91 |
cpu_metric_handler, |
| 92 |
}; |
| 93 |
|