f299e942d3dc28231c2e940c1f5b57981e767d6a
1 /**
2 * collectd - src/xmms.c
3 * Copyright (C) 2013
4 *
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.
8 *
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.
13 *
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
17 *
18 * Authors:
19 * Evan Felix <evan.felix@pnnl.gov
20 **/
22 #include "collectd.h"
23 #include "plugin.h"
24 #include "common.h"
26 #include <MicAccessTypes.h>
27 #include <MicAccessErrorTypes.h>
28 #include <MicAccessApi.h>
29 #include <MicThermalAPI.h>
31 #define MAX_MICS 32
33 static MicDeviceOnSystem mics[MAX_MICS];
34 static U32 numMics = MAX_MICS;
35 static HANDLE micHandle=NULL;
36 #define NUM_THERMS 7
37 static const int therms[NUM_THERMS] = {eMicThermalDie,eMicThermalDevMem,eMicThermalFin,eMicThermalFout,eMicThermalVccp,eMicThermalVddg,eMicThermalVddq};
38 static const char *thermNames[NUM_THERMS] = {"die","devmem","fin","fout","vccp","vddg","vddq"};
41 static int mic_init (void)
42 {
43 U32 ret;
45 ret = MicInitAPI(&micHandle, eTARGET_SCIF_DRIVER, mics, &numMics);
46 if (ret != MIC_ACCESS_API_SUCCESS) {
47 ERROR("Problem initializing MicAccessAPI: %s",MicGetErrorString(ret));
48 }
49 INFO("MICs found: %d",numMics);
50 if (numMics<0 || numMics>=MAX_MICS)
51 return (1);
52 else
53 return (0);
54 }
56 static void mic_submit_memory_use(int micnumber, const char *type, gauge_t val)
57 {
58 value_t values[1];
59 value_list_t vl = VALUE_LIST_INIT;
61 values[0].gauge = val;
63 vl.values=values;
64 vl.values_len=1;
66 strncpy (vl.host, hostname_g, sizeof (vl.host));
67 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
68 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
69 strncpy (vl.type, "memory", sizeof (vl.type));
70 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
72 plugin_dispatch_values (&vl);
73 }
75 static void mic_submit_temp(int micnumber, const char *type, gauge_t val)
76 {
77 value_t values[1];
78 value_list_t vl = VALUE_LIST_INIT;
80 values[0].gauge = val;
82 vl.values=values;
83 vl.values_len=1;
85 strncpy (vl.host, hostname_g, sizeof (vl.host));
86 strncpy (vl.plugin, "mic", sizeof (vl.plugin));
87 ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%i", micnumber);
88 strncpy (vl.type, "temperature", sizeof (vl.type));
89 strncpy (vl.type_instance, type, sizeof (vl.type_instance));
91 plugin_dispatch_values (&vl);
92 }
95 static int mic_read (void)
96 {
97 int i,j;
98 U32 ret,bufferSize;
99 U32 *tempBuffer;
100 int error;
101 U32 mem_total,mem_used,mem_bufs;
103 error=0;
104 for (i=0;i<numMics;i++) {
105 ret = MicInitAdapter(&micHandle,&mics[i]);
106 if (ret != MIC_ACCESS_API_SUCCESS) {
107 ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
108 error=1;
109 break;
110 }
112 /* Gather memory Utilization */
113 ret = MicGetMemoryUtilization(micHandle,&mem_total,&mem_used,&mem_bufs);
114 if (ret != MIC_ACCESS_API_SUCCESS) {
115 ERROR("Problem getting Memory Utilization: %s",MicGetErrorString(ret));
116 error=3;
117 break;
118 }
119 /* API reprots KB's of memory, adjust for this */
120 mic_submit_memory_use(i,"total",mem_total*1024);
121 mic_submit_memory_use(i,"used",mem_used*1024);
122 mic_submit_memory_use(i,"bufs",mem_bufs*1024);
123 /*INFO("Memory Read: %u %u %u",mem_total,mem_used,mem_bufs);*/
125 /* Gather Temperature Information */
126 bufferSize = sizeof(U32);
127 tempBuffer = malloc(bufferSize);
128 for (j=0;j<NUM_THERMS;j++) {
129 ret = MicGetTemperature(micHandle,therms[j],tempBuffer,&bufferSize);
130 if (ret != MIC_ACCESS_API_SUCCESS) {
131 ERROR("Problem getting Temperature(%d) %s",j,MicGetErrorString(ret));
132 error=4;
133 break;
134 }
135 /*INFO("Temp Read: %u: %u %s",j,tempBuffer[0],thermNames[j]);*/
136 mic_submit_temp(i,thermNames[j],tempBuffer[0]);
137 }
138 if (error)
139 break;
141 ret = MicCloseAdapter(micHandle);
142 if (ret != MIC_ACCESS_API_SUCCESS) {
143 ERROR("Problem initializing MicAdapter: %s",MicGetErrorString(ret));
144 error=2;
145 break;
146 }
147 }
148 return error;
149 }
152 static int mic_shutdown (void)
153 {
154 if (micHandle)
155 MicCloseAPI(micHandle);
156 return (0);
157 }
159 void module_register (void)
160 {
161 plugin_register_init ("mic", mic_init);
162 plugin_register_shutdown ("mic", mic_shutdown);
163 plugin_register_read ("mic", mic_read);
164 } /* void module_register */
166 /*
167 * vim: shiftwidth=2:softtabstop=2:textwidth=78
168 */