5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Evan Felix <evan.felix@pnnl.gov
25 #include "utils_ignorelist.h"
27 #include <MicAccessTypes.h>
28 #include <MicAccessErrorTypes.h>
29 #include <MicAccessApi.h>
30 #include <MicThermalAPI.h>
35 static MicDeviceOnSystem mics[MAX_MICS];
36 static U32 numMics = MAX_MICS;
37 static HANDLE micHandle=NULL;
39 static const int therms[NUM_THERMS] = {eMicThermalDie,eMicThermalDevMem,eMicThermalFin,eMicThermalFout,eMicThermalVccp,eMicThermalVddg,eMicThermalVddq};
40 static const char *thermNames[NUM_THERMS] = {"die","devmem","fin","fout","vccp","vddg","vddq"};
42 static const char *config_keys[] =
51 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
53 static _Bool show_total_cpu = 1;
54 static _Bool show_per_cpu = 1;
55 static _Bool show_temps = 1;
56 static _Bool show_memory = 1;
57 static ignorelist_t *temp_ignore = NULL;
60 static int mic_init (void)
64 ret = MicInitAPI(&micHandle, eTARGET_SCIF_DRIVER, mics, &numMics);
65 if (ret != MIC_ACCESS_API_SUCCESS) {
66 ERROR("Problem initializing MicAccessAPI: %s",MicGetErrorString(ret));
68 DEBUG("MICs found: %d",numMics);
70 if (numMics<0 || numMics>=MAX_MICS)
76 static int mic_config (const char *key, const char *value) {
77 if (temp_ignore == NULL)
78 temp_ignore = ignorelist_create(1);
79 if (temp_ignore == NULL)
82 if (strcasecmp("ShowTotalCPU",key) == 0)
84 show_total_cpu = IS_TRUE(value);
86 else if (strcasecmp("ShowPerCPU",key) == 0)
88 show_per_cpu = IS_TRUE(value);
90 else if (strcasecmp("ShowTemps",key) == 0)
92 show_temps = IS_TRUE(value);
94 else if (strcasecmp("ShowMemory",key) == 0)
96 show_memory = IS_TRUE(value);
98 else if (strcasecmp("TempSensor",key) == 0)
100 ignorelist_add(temp_ignore,value);
102 else if (strcasecmp("IgnoreTempSelected",key) == 0)
107 ignorelist_set_invert(temp_ignore,invert);
116 static void mic_submit_memory_use(int micnumber, const char *type, gauge_t val)
119 value_list_t vl = VALUE_LIST_INIT;
121 values[0].gauge = val;
126 strncpy (vl.host, hostname_g, sizeof (vl.host));
127 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
128 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
129 strncpy (vl.type, "memory", sizeof (vl.type));
130 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
132 plugin_dispatch_values (&vl);
135 /* Gather memory Utilization */
136 static int mic_read_memory(int mic)
139 U32 mem_total,mem_used,mem_bufs;
141 ret = MicGetMemoryUtilization(micHandle,&mem_total,&mem_used,&mem_bufs);
142 if (ret != MIC_ACCESS_API_SUCCESS) {
143 ERROR("Problem getting Memory Utilization: %s",MicGetErrorString(ret));
146 /* API reprots KB's of memory, adjust for this */
147 mic_submit_memory_use(mic,"total",mem_total*1024);
148 mic_submit_memory_use(mic,"used",mem_used*1024);
149 mic_submit_memory_use(mic,"bufs",mem_bufs*1024);
150 /*INFO("Memory Read: %u %u %u",mem_total,mem_used,mem_bufs);*/
154 static void mic_submit_temp(int micnumber, const char *type, gauge_t val)
157 value_list_t vl = VALUE_LIST_INIT;
159 values[0].gauge = val;
164 strncpy (vl.host, hostname_g, sizeof (vl.host));
165 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
166 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
167 strncpy (vl.type, "temperature", sizeof (vl.type));
168 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
170 plugin_dispatch_values (&vl);
173 /* Gather Temperature Information */
174 static int mic_read_temps(int mic)
181 bufferSize = sizeof(U32);
182 tempBuffer = malloc(bufferSize);
183 for (j=0;j<NUM_THERMS;j++) {
184 if (ignorelist_match(temp_ignore,thermNames[j])!=0)
186 ret = MicGetTemperature(micHandle,therms[j],tempBuffer,&bufferSize);
187 if (ret != MIC_ACCESS_API_SUCCESS) {
188 ERROR("Problem getting Temperature(%d) %s",j,MicGetErrorString(ret));
191 /*INFO("Temp Read: %u: %u %s",j,tempBuffer[0],thermNames[j]);*/
192 mic_submit_temp(mic,thermNames[j],tempBuffer[0]);
197 static void mic_submit_cpu(int micnumber, const char *type, int core, derive_t val)
200 value_list_t vl = VALUE_LIST_INIT;
202 values[0].derive = val;
207 strncpy (vl.host, hostname_g, sizeof (vl.host));
208 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
209 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
210 strncpy (vl.type, "cpu", sizeof (vl.type));
212 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
214 ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i-%s", core, type);
216 plugin_dispatch_values (&vl);
219 /*Gather CPU Utilization Information */
220 static int mic_read_cpu(int mic)
225 MicCoreUtil coreUtil;
226 MicCoreJiff coreJiffs[MAX_CORES];
228 bufferSize=MAX_CORES*sizeof(MicCoreJiff);
229 ret = MicGetCoreUtilization(micHandle,&coreUtil,coreJiffs,&bufferSize);
230 if (ret != MIC_ACCESS_API_SUCCESS) {
231 ERROR("Problem getting CPU utilization: %s",MicGetErrorString(ret));
234 if (show_total_cpu) {
235 mic_submit_cpu(mic,"user",-1,coreUtil.sum.user);
236 mic_submit_cpu(mic,"sys",-1,coreUtil.sum.sys);
237 mic_submit_cpu(mic,"nice",-1,coreUtil.sum.nice);
238 mic_submit_cpu(mic,"idle",-1,coreUtil.sum.idle);
241 for (j=0;j<coreUtil.core;j++) {
242 mic_submit_cpu(mic,"user",j,coreJiffs[j].user);
243 mic_submit_cpu(mic,"sys",j,coreJiffs[j].sys);
244 mic_submit_cpu(mic,"nice",j,coreJiffs[j].nice);
245 mic_submit_cpu(mic,"idle",j,coreJiffs[j].idle);
251 static int mic_read (void)
258 for (i=0;i<numMics;i++) {
259 ret = MicInitAdapter(&micHandle,&mics[i]);
260 if (ret != MIC_ACCESS_API_SUCCESS) {
261 ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
265 if (error == 0 && show_memory)
266 error = mic_read_memory(i);
268 if (error == 0 && show_temps)
269 error = mic_read_temps(i);
271 if (error == 0 && (show_total_cpu || show_per_cpu))
272 error = mic_read_cpu(i);
274 ret = MicCloseAdapter(micHandle);
275 if (ret != MIC_ACCESS_API_SUCCESS) {
276 ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
285 static int mic_shutdown (void)
288 MicCloseAPI(&micHandle);
292 void module_register (void)
294 plugin_register_init ("mic", mic_init);
295 plugin_register_shutdown ("mic", mic_shutdown);
296 plugin_register_read ("mic", mic_read);
297 plugin_register_config ("mic",mic_config, config_keys, config_keys_num);
298 } /* void module_register */
301 * vim: shiftwidth=2:softtabstop=2:textwidth=78