X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmic.c;h=3e31889fe83f560d89a09ce20df0d26c55d95dc6;hb=a349e06f0c4e2c853eced8a2621f52ee712b6e0c;hp=566b21660f87754e7c7d322d38db682c07ba54c0;hpb=e1f9a8285e12663764f7b74e21a394eb04613dc6;p=collectd.git diff --git a/src/mic.c b/src/mic.c index 566b2166..3e31889f 100644 --- a/src/mic.c +++ b/src/mic.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include "utils_ignorelist.h" @@ -28,6 +29,7 @@ #include #include #include +#include #define MAX_MICS 32 #define MAX_CORES 256 @@ -45,21 +47,25 @@ static char const * const therm_names[] = { static const char *config_keys[] = { - "ShowTotalCPU", - "ShowPerCPU", - "ShowTemps", + "ShowCPU", + "ShowCPUCores", "ShowMemory", - "TempSensor", - "IgnoreTempSelected", + "ShowTemperatures", + "Temperature", + "IgnoreSelectedTemperature", + "ShowPower", + "Power", + "IgnoreSelectedPower" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); -static _Bool show_total_cpu = 1; -static _Bool show_per_cpu = 1; -static _Bool show_temps = 1; +static _Bool show_cpu = 1; +static _Bool show_cpu_cores = 1; static _Bool show_memory = 1; +static _Bool show_temps = 1; static ignorelist_t *temp_ignore = NULL; - +static _Bool show_power = 1; +static ignorelist_t *power_ignore = NULL; static int mic_init (void) { @@ -72,10 +78,11 @@ static int mic_init (void) mic_count = (U32) STATIC_ARRAY_SIZE(mics); ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &mic_count); if (ret != MIC_ACCESS_API_SUCCESS) { - ERROR("mic plugin: Problem initializing MicAccessAPI: %s",MicGetErrorString(ret)); + ERROR("mic plugin: Problem initializing MicAccessAPI: %s", + MicGetErrorString(ret)); } DEBUG("mic plugin: found: %"PRIu32" MIC(s)",mic_count); - + if (mic_count<0 || mic_count>=MAX_MICS) { ERROR("mic plugin: No Intel MICs in system"); return (1); @@ -89,18 +96,20 @@ static int mic_init (void) static int mic_config (const char *key, const char *value) { if (temp_ignore == NULL) temp_ignore = ignorelist_create(1); - if (temp_ignore == NULL) + if (power_ignore == NULL) + power_ignore = ignorelist_create(1); + if (temp_ignore == NULL || power_ignore == NULL) return (1); - if (strcasecmp("ShowTotalCPU",key) == 0) + if (strcasecmp("ShowCPU",key) == 0) { - show_total_cpu = IS_TRUE(value); + show_cpu = IS_TRUE(value); } - else if (strcasecmp("ShowPerCPU",key) == 0) + else if (strcasecmp("ShowCPUCores",key) == 0) { - show_per_cpu = IS_TRUE(value); + show_cpu_cores = IS_TRUE(value); } - else if (strcasecmp("ShowTemps",key) == 0) + else if (strcasecmp("ShowTemperatures",key) == 0) { show_temps = IS_TRUE(value); } @@ -108,17 +117,32 @@ static int mic_config (const char *key, const char *value) { { show_memory = IS_TRUE(value); } - else if (strcasecmp("TempSensor",key) == 0) + else if (strcasecmp("ShowPower",key) == 0) + { + show_power = IS_TRUE(value); + } + else if (strcasecmp("Temperature",key) == 0) { ignorelist_add(temp_ignore,value); } - else if (strcasecmp("IgnoreTempSelected",key) == 0) + else if (strcasecmp("IgnoreSelectedTemperature",key) == 0) { int invert = 1; if (IS_TRUE(value)) invert = 0; ignorelist_set_invert(temp_ignore,invert); } + else if (strcasecmp("Power",key) == 0) + { + ignorelist_add(power_ignore,value); + } + else if (strcasecmp("IgnoreSelectedPower",key) == 0) + { + int invert = 1; + if (IS_TRUE(value)) + invert = 0; + ignorelist_set_invert(power_ignore,invert); + } else { return (-1); @@ -131,7 +155,7 @@ static void mic_submit_memory_use(int micnumber, const char *type_instance, U32 value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - /* MicAccessAPI reports KB's of memory, adjust for this */ + /* MicAccessAPI reports KB's of memory, adjust for this */ DEBUG("mic plugin: Memory Value Report; %u %lf",val,((gauge_t)val)*1024.0); values[0].gauge = ((gauge_t)val)*1024.0; @@ -145,17 +169,18 @@ static void mic_submit_memory_use(int micnumber, const char *type_instance, U32 strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} +} /* Gather memory Utilization */ static int mic_read_memory(int mic) { U32 ret; U32 mem_total,mem_free,mem_bufs; - + ret = MicGetMemoryUtilization(mic_handle,&mem_total,&mem_free,&mem_bufs); if (ret != MIC_ACCESS_API_SUCCESS) { - ERROR("mic plugin: Problem getting Memory Utilization: %s",MicGetErrorString(ret)); + ERROR("mic plugin: Problem getting Memory Utilization: %s", + MicGetErrorString(ret)); return (1); } mic_submit_memory_use(mic,"free",mem_free); @@ -177,20 +202,20 @@ static void mic_submit_temp(int micnumber, const char *type, gauge_t val) strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); - ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber); + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + "%i", micnumber); strncpy (vl.type, "temperature", sizeof (vl.type)); strncpy (vl.type_instance, type, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} +} /* Gather Temperature Information */ static int mic_read_temps(int mic) { size_t num_therms = STATIC_ARRAY_SIZE(therm_ids); - size_t j; - - for (j = 0; j < num_therms; j++) { + + for (size_t j = 0; j < num_therms; j++) { U32 status; U32 temp_buffer; U32 buffer_size = (U32)sizeof(temp_buffer); @@ -211,7 +236,8 @@ static int mic_read_temps(int mic) return (0); } -static void mic_submit_cpu(int micnumber, const char *type_instance, int core, derive_t val) +static void mic_submit_cpu(int micnumber, const char *type_instance, + int core, derive_t val) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -223,59 +249,121 @@ static void mic_submit_cpu(int micnumber, const char *type_instance, int core, d strncpy (vl.host, hostname_g, sizeof (vl.host)); strncpy (vl.plugin, "mic", sizeof (vl.plugin)); - ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber); + if (core < 0) /* global aggregation */ + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + "%i", micnumber); + else /* per-core statistics */ + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + "%i-cpu-%i", micnumber, core); strncpy (vl.type, "cpu", sizeof (vl.type)); - if (core < 0) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - else - ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i-%s", core, type_instance); + strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} +} /*Gather CPU Utilization Information */ static int mic_read_cpu(int mic) { - U32 ret; - U32 buffer_size; - int j; MicCoreUtil core_util; MicCoreJiff core_jiffs[MAX_CORES]; - - buffer_size=MAX_CORES*sizeof(MicCoreJiff); - ret = MicGetCoreUtilization(mic_handle,&core_util,core_jiffs,&buffer_size); - if (ret != MIC_ACCESS_API_SUCCESS) { - ERROR("mic plugin: Problem getting CPU utilization: %s",MicGetErrorString(ret)); - return(0); + U32 core_jiffs_size; + U32 status; + + core_jiffs_size = MAX_CORES * sizeof(MicCoreJiff); + status = MicGetCoreUtilization(mic_handle, &core_util, + core_jiffs, &core_jiffs_size); + if (status != MIC_ACCESS_API_SUCCESS) { + ERROR("mic plugin: Problem getting CPU utilization: %s", + MicGetErrorString(status)); + return(-1); } - if (show_total_cpu) { - mic_submit_cpu(mic,"user",-1,core_util.sum.user); - mic_submit_cpu(mic,"sys",-1,core_util.sum.sys); - mic_submit_cpu(mic,"nice",-1,core_util.sum.nice); - mic_submit_cpu(mic,"idle",-1,core_util.sum.idle); + + if (show_cpu) { + mic_submit_cpu(mic, "user", -1, core_util.sum.user); + mic_submit_cpu(mic, "sys", -1, core_util.sum.sys); + mic_submit_cpu(mic, "nice", -1, core_util.sum.nice); + mic_submit_cpu(mic, "idle", -1, core_util.sum.idle); } - if (show_per_cpu) { - for (j=0;j