Vmware Client SDK plugin
[collectd.git] / src / vmware.c
1 #include <stdlib.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <dlfcn.h>
5 #include "collectd.h"
6 #include "common.h"
7 #include "plugin.h"
8
9 #include "vmGuestLib.h"
10
11 /* Functions to dynamically load from the GuestLib library. */
12 char const * (*GuestLib_GetErrorText)(VMGuestLibError);
13 VMGuestLibError (*GuestLib_OpenHandle)(VMGuestLibHandle*);
14 VMGuestLibError (*GuestLib_CloseHandle)(VMGuestLibHandle);
15 VMGuestLibError (*GuestLib_UpdateInfo)(VMGuestLibHandle handle);
16 VMGuestLibError (*GuestLib_GetSessionId)(VMGuestLibHandle handle,
17                                          VMSessionId *id);
18 VMGuestLibError (*GuestLib_GetCpuReservationMHz)(VMGuestLibHandle handle,
19                                                  uint32 *cpuReservationMHz);
20 VMGuestLibError (*GuestLib_GetCpuLimitMHz)(VMGuestLibHandle handle, uint32 *cpuLimitMHz);
21 VMGuestLibError (*GuestLib_GetCpuShares)(VMGuestLibHandle handle, uint32 *cpuShares);
22 VMGuestLibError (*GuestLib_GetCpuUsedMs)(VMGuestLibHandle handle, uint64 *cpuUsedMs);
23 VMGuestLibError (*GuestLib_GetHostProcessorSpeed)(VMGuestLibHandle handle, uint32 *mhz);
24 VMGuestLibError (*GuestLib_GetMemReservationMB)(VMGuestLibHandle handle,
25                                                 uint32 *memReservationMB);
26 VMGuestLibError (*GuestLib_GetMemLimitMB)(VMGuestLibHandle handle, uint32 *memLimitMB);
27 VMGuestLibError (*GuestLib_GetMemShares)(VMGuestLibHandle handle, uint32 *memShares);
28 VMGuestLibError (*GuestLib_GetMemMappedMB)(VMGuestLibHandle handle,
29                                            uint32 *memMappedMB);
30 VMGuestLibError (*GuestLib_GetMemActiveMB)(VMGuestLibHandle handle, uint32 *memActiveMB);
31 VMGuestLibError (*GuestLib_GetMemOverheadMB)(VMGuestLibHandle handle,
32                                              uint32 *memOverheadMB);
33 VMGuestLibError (*GuestLib_GetMemBalloonedMB)(VMGuestLibHandle handle,
34                                               uint32 *memBalloonedMB);
35 VMGuestLibError (*GuestLib_GetMemSwappedMB)(VMGuestLibHandle handle,
36                                             uint32 *memSwappedMB);
37 VMGuestLibError (*GuestLib_GetMemSharedMB)(VMGuestLibHandle handle,
38                                            uint32 *memSharedMB);
39 VMGuestLibError (*GuestLib_GetMemSharedSavedMB)(VMGuestLibHandle handle,
40                                                 uint32 *memSharedSavedMB);
41 VMGuestLibError (*GuestLib_GetMemUsedMB)(VMGuestLibHandle handle,
42                                          uint32 *memUsedMB);
43 VMGuestLibError (*GuestLib_GetElapsedMs)(VMGuestLibHandle handle, uint64 *elapsedMs);
44 VMGuestLibError (*GuestLib_GetResourcePoolPath)(VMGuestLibHandle handle,
45                                                 size_t *bufferSize,
46                                                 char *pathBuffer);
47 VMGuestLibError (*GuestLib_GetCpuStolenMs)(VMGuestLibHandle handle,
48                                            uint64 *cpuStolenMs);
49 VMGuestLibError (*GuestLib_GetMemTargetSizeMB)(VMGuestLibHandle handle,
50                                                uint64 *memTargetSizeMB);
51 VMGuestLibError (*GuestLib_GetHostNumCpuCores)(VMGuestLibHandle handle,
52                                                uint32 *hostNumCpuCores);
53 VMGuestLibError (*GuestLib_GetHostCpuUsedMs)(VMGuestLibHandle handle,
54                                              uint64 *hostCpuUsedMs);
55 VMGuestLibError (*GuestLib_GetHostMemSwappedMB)(VMGuestLibHandle handle,
56                                                 uint64 *hostMemSwappedMB);
57 VMGuestLibError (*GuestLib_GetHostMemSharedMB)(VMGuestLibHandle handle,
58                                                uint64 *hostMemSharedMB);
59 VMGuestLibError (*GuestLib_GetHostMemUsedMB)(VMGuestLibHandle handle,
60                                              uint64 *hostMemUsedMB);
61 VMGuestLibError (*GuestLib_GetHostMemPhysMB)(VMGuestLibHandle handle,
62                                              uint64 *hostMemPhysMB);
63 VMGuestLibError (*GuestLib_GetHostMemPhysFreeMB)(VMGuestLibHandle handle,
64                                                  uint64 *hostMemPhysFreeMB);
65 VMGuestLibError (*GuestLib_GetHostMemKernOvhdMB)(VMGuestLibHandle handle,
66                                                  uint64 *hostMemKernOvhdMB);
67 VMGuestLibError (*GuestLib_GetHostMemMappedMB)(VMGuestLibHandle handle,
68                                                uint64 *hostMemMappedMB);
69 VMGuestLibError (*GuestLib_GetHostMemUnmappedMB)(VMGuestLibHandle handle,
70                                                  uint64 *hostMemUnmappedMB);
71 /*
72  * Handle for use with shared library.
73  */
74 void *dlHandle = NULL;
75
76 /*
77  * GuestLib handle.
78  */
79 VMGuestLibHandle glHandle;
80
81 VMGuestLibError glError;
82
83 /*
84  * Macro to load a single GuestLib function from the shared library.
85  */
86 #define LOAD_ONE_FUNC(funcname)                           \
87    do {                                                   \
88       funcname = dlsym(dlHandle, "VM" #funcname);         \
89       if ((dlErrStr = dlerror()) != NULL) {               \
90          printf("Failed to load \'%s\': \'%s\'\n",        \
91                 #funcname, dlErrStr);                     \
92          return FALSE;                                    \
93       }                                                   \
94    } while (0)
95
96 Bool
97 LoadFunctions(void)
98 {
99    /*
100     * First, try to load the shared library.
101     */
102    char const *dlErrStr;
103
104    dlHandle = dlopen("libvmGuestLib.so", RTLD_NOW);
105    if (!dlHandle) {
106       dlErrStr = dlerror();
107       printf("dlopen failed: \'%s\'\n", dlErrStr);
108       return FALSE;
109    }
110
111    /* Load all the individual library functions. */
112    LOAD_ONE_FUNC(GuestLib_GetErrorText);
113    LOAD_ONE_FUNC(GuestLib_OpenHandle);
114    LOAD_ONE_FUNC(GuestLib_CloseHandle);
115    LOAD_ONE_FUNC(GuestLib_UpdateInfo);
116    LOAD_ONE_FUNC(GuestLib_GetSessionId);
117    LOAD_ONE_FUNC(GuestLib_GetCpuReservationMHz);
118    LOAD_ONE_FUNC(GuestLib_GetCpuLimitMHz);
119    LOAD_ONE_FUNC(GuestLib_GetCpuShares);
120    LOAD_ONE_FUNC(GuestLib_GetCpuUsedMs);
121    LOAD_ONE_FUNC(GuestLib_GetHostProcessorSpeed);
122    LOAD_ONE_FUNC(GuestLib_GetMemReservationMB);
123    LOAD_ONE_FUNC(GuestLib_GetMemLimitMB);
124    LOAD_ONE_FUNC(GuestLib_GetMemShares);
125    LOAD_ONE_FUNC(GuestLib_GetMemMappedMB);
126    LOAD_ONE_FUNC(GuestLib_GetMemActiveMB);
127    LOAD_ONE_FUNC(GuestLib_GetMemOverheadMB);
128    LOAD_ONE_FUNC(GuestLib_GetMemBalloonedMB);
129    LOAD_ONE_FUNC(GuestLib_GetMemSwappedMB);
130    LOAD_ONE_FUNC(GuestLib_GetMemSharedMB);
131    LOAD_ONE_FUNC(GuestLib_GetMemSharedSavedMB);
132    LOAD_ONE_FUNC(GuestLib_GetMemUsedMB);
133    LOAD_ONE_FUNC(GuestLib_GetElapsedMs);
134    LOAD_ONE_FUNC(GuestLib_GetResourcePoolPath);
135    LOAD_ONE_FUNC(GuestLib_GetCpuStolenMs);
136    LOAD_ONE_FUNC(GuestLib_GetMemTargetSizeMB);
137    LOAD_ONE_FUNC(GuestLib_GetHostNumCpuCores);
138    LOAD_ONE_FUNC(GuestLib_GetHostCpuUsedMs);
139    LOAD_ONE_FUNC(GuestLib_GetHostMemSwappedMB);
140    LOAD_ONE_FUNC(GuestLib_GetHostMemSharedMB);
141    LOAD_ONE_FUNC(GuestLib_GetHostMemUsedMB);
142    LOAD_ONE_FUNC(GuestLib_GetHostMemPhysMB);
143    LOAD_ONE_FUNC(GuestLib_GetHostMemPhysFreeMB);
144    LOAD_ONE_FUNC(GuestLib_GetHostMemKernOvhdMB);
145    LOAD_ONE_FUNC(GuestLib_GetHostMemMappedMB);
146    LOAD_ONE_FUNC(GuestLib_GetHostMemUnmappedMB);
147
148    return TRUE;
149 }
150
151 static int vmware_init (void)
152 {
153   if (!LoadFunctions()) {
154     ERROR ("vmware guest plugin: Unable to load GuistLib functions");
155     return (-1);
156   }
157
158   /* Try to load the library. */
159   glError = GuestLib_OpenHandle(&glHandle);
160   if (glError != VMGUESTLIB_ERROR_SUCCESS) {
161      ERROR ("OpenHandle failed: %s", GuestLib_GetErrorText(glError));
162      return (-1);
163   }
164
165   return (0);
166 }
167
168 static void vmware_submit_counter (const char *reading, counter_t value)
169 {
170     value_t values[1];
171     value_list_t vl = VALUE_LIST_INIT;
172
173     values[0].counter = value;
174
175     vl.values = values;
176     vl.values_len = 1;
177
178     sstrncpy (vl.host, hostname_g, sizeof (vl.host));
179     sstrncpy (vl.plugin, "vmware", sizeof (vl.plugin));
180     sstrncpy (vl.type, reading, sizeof (vl.type));
181
182     plugin_dispatch_values (&vl);
183 }
184
185 static void vmware_submit_gauge (const char *reading, gauge_t value)
186 {
187     value_t values[1];
188     value_list_t vl = VALUE_LIST_INIT;
189
190     values[0].gauge = value;
191
192     vl.values = values;
193     vl.values_len = 1;
194
195     sstrncpy (vl.host, hostname_g, sizeof (vl.host));
196     sstrncpy (vl.plugin, "vmware", sizeof (vl.plugin));
197     sstrncpy (vl.type, reading, sizeof (vl.type));
198
199     plugin_dispatch_values (&vl);
200 }
201
202 static int vmware_read (void)
203 {
204    counter_t value;
205    uint32 cpuReservationMHz = 0;
206    uint32 cpuLimitMHz = 0;
207    uint32 cpuShares = 0;
208    uint64 cpuUsedMs = 0;
209    uint32 hostMHz = 0;
210    uint32 memReservationMB = 0;
211    uint32 memLimitMB = 0;
212    uint32 memShares = 0;
213    uint32 memMappedMB = 0;
214    uint32 memActiveMB = 0;
215    uint32 memOverheadMB = 0;
216    uint32 memBalloonedMB = 0;
217    uint32 memSwappedMB = 0;
218    uint32 memSharedMB = 0;
219    uint32 memSharedSavedMB = 0;
220    uint32 memUsedMB = 0;
221    uint64 elapsedMs = 0;
222    uint64 cpuStolenMs = 0;
223    uint64 memTargetSizeMB = 0;
224    uint32 hostNumCpuCores = 0;
225    uint64 hostCpuUsedMs = 0;
226    uint64 hostMemSwappedMB = 0;
227    uint64 hostMemSharedMB = 0;
228    uint64 hostMemUsedMB = 0;
229    uint64 hostMemPhysMB = 0;
230    uint64 hostMemPhysFreeMB = 0;
231    uint64 hostMemKernOvhdMB = 0;
232    uint64 hostMemMappedMB = 0;
233    uint64 hostMemUnmappedMB = 0;
234    VMSessionId sessionId = 0;
235
236    /* Attempt to retrieve info from the host. */
237    VMSessionId tmpSession;
238
239    glError = GuestLib_UpdateInfo(glHandle);
240    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
241      ERROR ("UpdateInfo failed: %s", GuestLib_GetErrorText(glError));
242      return (-1);
243    }
244
245    /* Retrieve and check the session ID */
246    glError = GuestLib_GetSessionId(glHandle, &tmpSession);
247    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
248     ERROR ("Failed to get session ID: %s", GuestLib_GetErrorText(glError));
249     return (-1);
250    }
251
252    if (tmpSession == 0) {
253      ERROR ("Error: Got zero sessionId from GuestLib");
254      return (-1);
255    }
256
257    if (sessionId == 0) {
258     sessionId = tmpSession;
259     DEBUG ("Initial session ID is 0x%"FMT64"x", sessionId);
260    } else if (tmpSession != sessionId) {
261     sessionId = tmpSession;
262     DEBUG ("SESSION CHANGED: New session ID is 0x%"FMT64"x\n", sessionId);
263    }
264
265    /* Retrieve all the stats. */
266    /* FIXME: GENERALIZE */
267     glError = GuestLib_GetCpuReservationMHz(glHandle, &cpuReservationMHz);
268     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
269       DEBUG ("Failed to get CPU reservation: %s\n", GuestLib_GetErrorText(glError));
270     }
271     value = (gauge_t) cpuReservationMHz;
272     vmware_submit_gauge ("cpu_reservation_mhz", value);
273
274     glError = GuestLib_GetCpuLimitMHz(glHandle, &cpuLimitMHz);
275     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
276       DEBUG ("Failed to get CPU limit: %s\n", GuestLib_GetErrorText(glError));
277     }
278     value = (gauge_t) cpuLimitMHz;
279     vmware_submit_gauge ("cpu_limit_mhz", value);
280
281     glError = GuestLib_GetCpuShares(glHandle, &cpuShares);
282     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
283       DEBUG ("Failed to get cpu shares: %s\n", GuestLib_GetErrorText(glError));
284     }
285     value = (gauge_t) cpuShares;
286     vmware_submit_gauge ("cpu_shares", value);
287
288     glError = GuestLib_GetCpuUsedMs(glHandle, &cpuUsedMs);
289     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
290       DEBUG ("Failed to get used ms: %s\n", GuestLib_GetErrorText(glError));
291     }
292     value = (counter_t) cpuUsedMs;
293     vmware_submit_counter ("cpu_used_ms", value);
294
295     glError = GuestLib_GetHostProcessorSpeed(glHandle, &hostMHz);
296     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
297       DEBUG ("Failed to get host proc speed: %s\n", GuestLib_GetErrorText(glError));
298     }
299     value = (gauge_t) hostMHz;
300     vmware_submit_gauge ("host_processor_speed", value);
301
302     glError = GuestLib_GetMemReservationMB(glHandle, &memReservationMB);
303     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
304       DEBUG ("Failed to get mem reservation: %s\n", GuestLib_GetErrorText(glError));
305     }
306     value = (gauge_t) memReservationMB;
307     vmware_submit_gauge ("memory_reservation_mb", value);
308
309     glError = GuestLib_GetMemLimitMB(glHandle, &memLimitMB);
310     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
311       DEBUG ("Failed to get mem limit: %s\n", GuestLib_GetErrorText(glError));
312     }
313     value = (gauge_t) memLimitMB;
314     vmware_submit_gauge ("memory_limit_mb", value);
315
316     glError = GuestLib_GetMemShares(glHandle, &memShares);
317     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
318       DEBUG ("Failed to get mem shares: %s\n", GuestLib_GetErrorText(glError));
319       memShares = 0;
320     }
321     value = (gauge_t) memShares;
322     vmware_submit_gauge ("memory_shares", value);
323
324     glError = GuestLib_GetMemMappedMB(glHandle, &memMappedMB);
325     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
326       DEBUG ("Failed to get mapped mem: %s\n", GuestLib_GetErrorText(glError));
327     }
328     value = (gauge_t) memMappedMB;
329     vmware_submit_gauge ("memory_mapped_mb", value);
330
331     glError = GuestLib_GetMemActiveMB(glHandle, &memActiveMB);
332     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
333      DEBUG ("Failed to get active mem: %s\n", GuestLib_GetErrorText(glError));
334     }
335     value = (gauge_t) memActiveMB;
336     vmware_submit_gauge ("memory_active_mb", value);
337
338     glError = GuestLib_GetMemOverheadMB(glHandle, &memOverheadMB);
339     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
340       DEBUG ("Failed to get overhead mem: %s\n", GuestLib_GetErrorText(glError));
341     }
342     value = (gauge_t) memOverheadMB;
343     vmware_submit_gauge ("memory_overhead_mb", value);
344
345     glError = GuestLib_GetMemBalloonedMB(glHandle, &memBalloonedMB);
346     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
347       DEBUG ("Failed to get ballooned mem: %s\n", GuestLib_GetErrorText(glError));
348     }
349     value = (gauge_t) memBalloonedMB;
350     vmware_submit_gauge ("memory_ballooned_mb", value);
351
352     glError = GuestLib_GetMemSwappedMB(glHandle, &memSwappedMB);
353     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
354       DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError));
355     }
356     value = (gauge_t) memSwappedMB;
357     vmware_submit_gauge ("memory_swapped_mb", value);
358
359     glError = GuestLib_GetMemSharedMB(glHandle, &memSharedMB);
360     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
361       DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError));
362     }
363     value = (gauge_t) memSharedMB;
364     vmware_submit_gauge ("memory_shared_mb", value);
365
366     glError = GuestLib_GetMemSharedSavedMB(glHandle, &memSharedSavedMB);
367     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
368      DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError));
369     }
370     value = (gauge_t) memSharedSavedMB;
371     vmware_submit_gauge ("memory_shared_saved_mb", value);
372
373     glError = GuestLib_GetMemUsedMB(glHandle, &memUsedMB);
374     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
375       DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError));
376     }
377     value = (gauge_t) memUsedMB;
378     vmware_submit_gauge ("memory_used_mb", value);
379
380     glError = GuestLib_GetElapsedMs(glHandle, &elapsedMs);
381     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
382       DEBUG ("Failed to get elapsed ms: %s\n", GuestLib_GetErrorText(glError));
383     }
384     value = (counter_t) elapsedMs;
385     vmware_submit_counter ("elapsed_ms", value);
386
387     glError = GuestLib_GetCpuStolenMs(glHandle, &cpuStolenMs);
388     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
389       DEBUG ("Failed to get CPU stolen: %s\n", GuestLib_GetErrorText(glError));
390       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
391         cpuStolenMs = 0;
392       }
393     }
394     value = (counter_t) cpuStolenMs;
395     vmware_submit_counter ("cpu_stolen_ms", value);
396
397     glError = GuestLib_GetMemTargetSizeMB(glHandle, &memTargetSizeMB);
398     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
399       DEBUG ("Failed to get target mem size: %s\n", GuestLib_GetErrorText(glError));
400       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
401         memTargetSizeMB = 0;
402       }
403     }
404     value = (gauge_t) memTargetSizeMB;
405     vmware_submit_gauge ("memory_target_size", value);
406
407     glError = GuestLib_GetHostNumCpuCores(glHandle, &hostNumCpuCores);
408     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
409       DEBUG ("Failed to get host CPU cores: %s\n", GuestLib_GetErrorText(glError));
410       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
411           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
412         hostNumCpuCores = 0;
413       }
414     }
415     value = (gauge_t) hostNumCpuCores;
416     vmware_submit_gauge ("host_cpu_cores", value);
417
418     glError = GuestLib_GetHostCpuUsedMs(glHandle, &hostCpuUsedMs);
419     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
420       DEBUG ("Failed to get host CPU used: %s\n", GuestLib_GetErrorText(glError));
421       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
422           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
423         hostCpuUsedMs = 0;
424       }
425     }
426     value = (counter_t) hostCpuUsedMs;
427     vmware_submit_counter ("host_cpu_used_ms", value);
428
429     glError = GuestLib_GetHostMemSwappedMB(glHandle, &hostMemSwappedMB);
430     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
431       DEBUG ("Failed to get host mem swapped: %s\n", GuestLib_GetErrorText(glError));
432       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
433           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
434         hostMemSwappedMB = 0;
435       }
436     }
437     value = (gauge_t) hostMemSwappedMB;
438     vmware_submit_gauge ("host_mem_swapped_mb", value);
439
440     glError = GuestLib_GetHostMemSharedMB(glHandle, &hostMemSharedMB);
441     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
442       DEBUG ("Failed to get host mem shared: %s\n", GuestLib_GetErrorText(glError));
443       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
444           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
445         hostMemSharedMB = 0;
446       }
447     }
448     value = (gauge_t) hostMemSharedMB;
449     vmware_submit_gauge ("host_mem_shared_mb", value);
450
451     glError = GuestLib_GetHostMemUsedMB(glHandle, &hostMemUsedMB);
452     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
453       DEBUG ("Failed to get host mem used: %s\n", GuestLib_GetErrorText(glError));
454       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
455           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
456         hostMemUsedMB = 0;
457       }
458     }
459     value = (gauge_t) hostMemSharedMB;
460     vmware_submit_gauge ("host_mem_used_mb", value);
461
462     glError = GuestLib_GetHostMemPhysMB(glHandle, &hostMemPhysMB);
463     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
464       DEBUG ("Failed to get host phys mem: %s\n", GuestLib_GetErrorText(glError));
465       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
466           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
467         hostMemPhysMB = 0;
468       }
469     }
470     value = (gauge_t) hostMemPhysMB;
471     vmware_submit_gauge ("host_mem_physical_mb", value);
472
473     glError = GuestLib_GetHostMemPhysFreeMB(glHandle, &hostMemPhysFreeMB);
474     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
475       DEBUG ("Failed to get host phys mem free: %s\n", GuestLib_GetErrorText(glError));
476       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
477           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
478         hostMemPhysFreeMB = 0;
479       }
480     }
481     value = (gauge_t) hostMemPhysFreeMB;
482     vmware_submit_gauge ("host_mem_physical_free_mb", value);
483
484     glError = GuestLib_GetHostMemKernOvhdMB(glHandle, &hostMemKernOvhdMB);
485     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
486       DEBUG ("Failed to get host kernel overhead mem: %s\n", GuestLib_GetErrorText(glError));
487       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
488           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
489         hostMemKernOvhdMB = 0;
490       }
491     }
492     value = (gauge_t) hostMemKernOvhdMB;
493     vmware_submit_gauge ("host_mem_kernel_overhead_mb", value);
494
495     glError = GuestLib_GetHostMemMappedMB(glHandle, &hostMemMappedMB);
496     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
497       DEBUG ("Failed to get host mem mapped: %s\n", GuestLib_GetErrorText(glError));
498       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
499           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
500         hostMemMappedMB = 0;
501       }
502     }
503     value = (gauge_t) hostMemMappedMB;
504     vmware_submit_gauge ("host_mem_mapped_mb", value);
505
506     glError = GuestLib_GetHostMemUnmappedMB(glHandle, &hostMemUnmappedMB);
507     if (glError != VMGUESTLIB_ERROR_SUCCESS) {
508       DEBUG ("Failed to get host mem unmapped: %s\n", GuestLib_GetErrorText(glError));
509       if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION ||
510           glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
511         hostMemUnmappedMB = 0;
512       }
513     }
514     value = (gauge_t) hostMemUnmappedMB;
515     vmware_submit_gauge ("host_mem_unmapped_mb", value);
516
517    return (0);
518 }
519
520 void module_register (void)
521 {
522   plugin_register_init ("vmware", vmware_init);
523   plugin_register_read ("vmware", vmware_read);
524 }