[collectd] VMware Guest SDK plugin for Collectd 5

Keith Chambers chambers_keith at yahoo.com
Wed Aug 3 22:23:14 CEST 2011


Team,

In case others find this of value -- I reworked the VMware plugin submitted by Edward Muller:
http://mailman.verplant.org/pipermail/collectd/2010-November/004268.html

Thank you Edward for your original submission.

Changes:
* As Florian suggested I changed 'counter_t' to 'derive_t', and added 'type' / 'type instance' grouping of similar counters together.
* I removed the VMware Guest SDK counters that don't work on ESX 4.X.  (I'm not sure if they worked on Workstation, ESX 3.X, or other.)

I understand that this will not get merged in to the mainline due to the associated VMware licensing. 

Lastly -- I'm a hack when it comes to c. It's been working find for me but use at your own risk.  :-)
 
Regards,
Keith


diff -Nur a/configure b/configure
--- a/configure	1970-01-01 00:00:00.000000000 +0000
+++ b/configure	1970-01-01 00:00:00.000000000 +0000
@@ -1980,6 +1980,7 @@
--enable-users          User statistics
--enable-uuid           UUID as hostname plugin
--enable-vmem           Virtual memory statistics
+  --enable-vmware         VMware client statistics
--enable-vserver        Linux VServer statistics
--enable-wireless       Wireless statistics
--enable-write_http     HTTP output plugin
@@ -45332,6 +45333,7 @@
plugin_users="no"
plugin_uptime="no"
plugin_vmem="no"
+plugin_vmware="no"
plugin_vserver="no"
plugin_wireless="no"
plugin_zfs_arc="no"
@@ -45360,6 +45362,7 @@
plugin_thermal="yes"
plugin_uptime="yes"
plugin_vmem="yes"
+	plugin_vmware="yes"
plugin_vserver="yes"
plugin_wireless="yes"

@@ -51612,6 +51615,69 @@

enable_plugin="no"
force="no"
+    # Check whether --enable-vmware was given.
+if test "${enable_vmware+set}" = set; then
+  enableval=$enable_vmware;
+     if test "x$enableval" = "xyes"
+     then
+             enable_plugin="yes"
+     else if test "x$enableval" = "xforce"
+     then
+             enable_plugin="yes"
+             force="yes"
+     else
+             enable_plugin="no (disabled on command line)"
+     fi; fi
+
+else
+
+         if test "x$enable_all_plugins" = "xauto"
+         then
+             if test "x$plugin_vmware" = "xyes"
+             then
+                     enable_plugin="yes"
+             else
+                     enable_plugin="no"
+             fi
+         else
+             enable_plugin="$enable_all_plugins"
+         fi
+
+fi
+
+    if test "x$enable_plugin" = "xyes"
+    then
+            if test "x$plugin_vmware" = "xyes" || test "x$force" = "xyes"
+            then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_PLUGIN_VMWARE 1
+_ACEOF
+
+                    if test "x$plugin_vmware" != "xyes"
+                    then
+                            dependency_warning="yes"
+                    fi
+            else # User passed "yes" but dependency checking yielded "no" => Dependency problem.
+                    dependency_error="yes"
+                    enable_plugin="no (dependency error)"
+            fi
+    fi
+
+if test "x$enable_plugin" = "xyes"; then
+  BUILD_PLUGIN_VMWARE_TRUE=
+  BUILD_PLUGIN_VMWARE_FALSE='#'
+else
+  BUILD_PLUGIN_VMWARE_TRUE='#'
+  BUILD_PLUGIN_VMWARE_FALSE=
+fi
+
+    enable_vmware="$enable_plugin"
+
+
+
+    enable_plugin="no"
+    force="no"
# Check whether --enable-wireless was given.
if test "${enable_wireless+set}" = set; then
enableval=$enable_wireless;
@@ -55321,6 +55387,7 @@
users . . . . . . . . $enable_users
uuid  . . . . . . . . $enable_uuid
vmem  . . . . . . . . $enable_vmem
+    vmware  . . . . . . . $enable_vmware
vserver . . . . . . . $enable_vserver
wireless  . . . . . . $enable_wireless
write_http  . . . . . $enable_write_http
diff -Nur a/configure.in b/configure.in
--- a/configure.in	1970-01-01 00:00:00.000000000 +0000
+++ b/configure.in	1970-01-01 00:00:00.000000000 +0000
@@ -3997,6 +3997,7 @@
plugin_users="no"
plugin_uptime="no"
plugin_vmem="no"
+plugin_vmware="no"
plugin_vserver="no"
plugin_wireless="no"
plugin_zfs_arc="no"
@@ -4025,6 +4026,7 @@
plugin_thermal="yes"
plugin_uptime="yes"
plugin_vmem="yes"
+	plugin_vmware="yes"
plugin_vserver="yes"
plugin_wireless="yes"

@@ -4350,6 +4352,7 @@
AC_PLUGIN([users],       [$plugin_users],      [User statistics])
AC_PLUGIN([uuid],        [yes],                [UUID as hostname plugin])
AC_PLUGIN([vmem],        [$plugin_vmem],       [Virtual memory statistics])
+AC_PLUGIN([vmware],      [$plugin_vmware],     [VMware client statistics])
AC_PLUGIN([vserver],     [$plugin_vserver],    [Linux VServer statistics])
AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
AC_PLUGIN([write_http],  [$with_libcurl],      [HTTP output plugin])
@@ -4666,6 +4669,7 @@
users . . . . . . . . $enable_users
uuid  . . . . . . . . $enable_uuid
vmem  . . . . . . . . $enable_vmem
+    vmware  . . . . . . . $enable_vmware
vserver . . . . . . . $enable_vserver
wireless  . . . . . . $enable_wireless
write_http  . . . . . $enable_write_http
diff -Nur a/src/config.h.in b/src/config.h.in
--- a/src/config.h.in	1970-01-01 00:00:00.000000000 +0000
+++ b/src/config.h.in	1970-01-01 00:00:00.000000000 +0000
@@ -774,6 +774,9 @@
/* Define to 1 if the vmem plugin is enabled. */
#undef HAVE_PLUGIN_VMEM

+/* Define to 1 if the vmware plugin is enabled. */
+#undef HAVE_PLUGIN_VMWARE
+
/* Define to 1 if the vserver plugin is enabled. */
#undef HAVE_PLUGIN_VSERVER

diff -Nur a/src/collectd.conf.in b/src/collectd.conf.in
--- a/src/collectd.conf.in	1970-01-01 00:00:00.000000000 +0000
+++ b/src/collectd.conf.in	1970-01-01 00:00:00.000000000 +0000
@@ -134,6 +134,7 @@
#@BUILD_PLUGIN_USERS_TRUE at LoadPlugin users
#@BUILD_PLUGIN_UUID_TRUE at LoadPlugin uuid
#@BUILD_PLUGIN_VMEM_TRUE at LoadPlugin vmem
+#@BUILD_PLUGIN_VMWARE_TRUE at LoadPlugin vmware
#@BUILD_PLUGIN_VSERVER_TRUE at LoadPlugin vserver
#@BUILD_PLUGIN_WIRELESS_TRUE at LoadPlugin wireless
#@BUILD_PLUGIN_WRITE_HTTP_TRUE at LoadPlugin write_http
diff -Nur a/src/Makefile.am b/src/Makefile.am
--- a/src/Makefile.am	1970-01-01 00:00:00.000000000 +0000
+++ b/src/Makefile.am	1970-01-01 00:00:00.000000000 +0000
@@ -156,6 +156,17 @@
collectd_DEPENDENCIES += ascent.la
endif

+if BUILD_PLUGIN_VMWARE
+pkglib_LTLIBRARIES += vmware.la
+vmware_la_SOURCES = vmware.c
+vmware_la_LDFLAGS = -module -avoid-version
+vmware_la_CFLAGS = $(AM_CFLAGS) \
+		$(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+vmware_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
+collectd_LDADD += "-dlopen" vmware.la
+collectd_DEPENDENCIES += vmware.la
+endif
+
if BUILD_PLUGIN_BATTERY
pkglib_LTLIBRARIES += battery.la
battery_la_SOURCES = battery.c
diff -Nur a/src/types.db b/src/types.db
--- a/src/types.db	1970-01-01 00:00:00.000000000 +0000
+++ b/src/types.db	1970-01-01 00:00:00.000000000 +0000
@@ -150,6 +151,7 @@
threads			value:GAUGE:0:U
time_dispersion		value:GAUGE:-1000000:1000000
timeleft		value:GAUGE:0:3600
+time			value:DERIVE:0:U
time_offset		value:GAUGE:-1000000:1000000
total_bytes		value:DERIVE:0:U
total_connections	value:DERIVE:0:U
@@ -168,6 +170,8 @@
vmpage_faults		minflt:DERIVE:0:U, majflt:DERIVE:0:U
vmpage_io		in:DERIVE:0:U, out:DERIVE:0:U
vmpage_number		value:GAUGE:0:4294967295
+vmware_qos		value:GAUGE:0:U
+vmware_host_cpu	value:GAUGE:0:U
volatile_changes	value:GAUGE:0:U
voltage_threshold	value:GAUGE:U:U, threshold:GAUGE:U:U
voltage			value:GAUGE:U:U
diff -Nur a/src/vmware.c b/src/vmware.c
--- a/src/vmware.c	2011-05-22 02:15:32.179086658 +0000
+++ b/src/vmware.c	2011-05-22 02:12:35.340762567 +0000
@@ -0,0 +1,395 @@
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include "vmGuestLib.h"
+
+/* functions to dynamically load from the GuestLib library */
+char const * (*GuestLib_GetErrorText)(VMGuestLibError);
+VMGuestLibError (*GuestLib_OpenHandle)(VMGuestLibHandle*);
+VMGuestLibError (*GuestLib_CloseHandle)(VMGuestLibHandle);
+VMGuestLibError (*GuestLib_UpdateInfo)(VMGuestLibHandle handle);
+VMGuestLibError (*GuestLib_GetSessionId)(VMGuestLibHandle handle, VMSessionId *id);
+
+/* time */
+VMGuestLibError (*GuestLib_GetElapsedMs)(VMGuestLibHandle handle, uint64 *elapsedMs);
+
+/* cpu */
+VMGuestLibError (*GuestLib_GetCpuUsedMs)(VMGuestLibHandle handle, uint64 *cpuUsedMs);
+VMGuestLibError (*GuestLib_GetCpuStolenMs)(VMGuestLibHandle handle, uint64 *cpuStolenMs);
+
+/* cpu_qos */
+VMGuestLibError (*GuestLib_GetCpuReservationMHz)(VMGuestLibHandle handle, uint32 *cpuReservationMHz);
+VMGuestLibError (*GuestLib_GetCpuLimitMHz)(VMGuestLibHandle handle, uint32 *cpuLimitMHz);
+VMGuestLibError (*GuestLib_GetCpuShares)(VMGuestLibHandle handle, uint32 *cpuShares);
+
+/* cpu_host */
+VMGuestLibError (*GuestLib_GetHostProcessorSpeed)(VMGuestLibHandle handle, uint32 *mhz);
+
+/* memory */
+VMGuestLibError (*GuestLib_GetMemUsedMB)(VMGuestLibHandle handle, uint32 *memUsedMB);
+VMGuestLibError (*GuestLib_GetMemMappedMB)(VMGuestLibHandle handle, uint32 *memMappedMB);
+VMGuestLibError (*GuestLib_GetMemActiveMB)(VMGuestLibHandle handle, uint32 *memActiveMB);
+VMGuestLibError (*GuestLib_GetMemTargetSizeMB)(VMGuestLibHandle handle, uint64 *memTargetSizeMB);
+VMGuestLibError (*GuestLib_GetMemOverheadMB)(VMGuestLibHandle handle, uint32 *memOverheadMB);
+VMGuestLibError (*GuestLib_GetMemSharedMB)(VMGuestLibHandle handle, uint32 *memSharedMB);
+VMGuestLibError (*GuestLib_GetMemSharedSavedMB)(VMGuestLibHandle handle, uint32 *memSharedSavedMB);
+VMGuestLibError (*GuestLib_GetMemBalloonedMB)(VMGuestLibHandle handle, uint32 *memBalloonedMB);
+VMGuestLibError (*GuestLib_GetMemSwappedMB)(VMGuestLibHandle handle, uint32 *memSwappedMB);
+
+/* memory_qos */
+VMGuestLibError (*GuestLib_GetMemReservationMB)(VMGuestLibHandle handle, uint32 *memReservationMB);
+VMGuestLibError (*GuestLib_GetMemLimitMB)(VMGuestLibHandle handle, uint32 *memLimitMB);
+VMGuestLibError (*GuestLib_GetMemShares)(VMGuestLibHandle handle, uint32 *memShares);
+
+/* handle for use with shared library */
+void *dlHandle = NULL;
+VMGuestLibHandle glHandle;
+VMGuestLibError glError;
+
+/* macro to load a single GuestLib function from the shared library */
+#define LOAD_ONE_FUNC(funcname)                           \
+   do {                                                   \
+      funcname = dlsym(dlHandle, "VM" #funcname);         \
+      if ((dlErrStr = dlerror()) != NULL) {               \
+         printf("Failed to load \'%s\': \'%s\'\n",        \
+                #funcname, dlErrStr);                     \
+         return FALSE;                                    \
+      }                                                   \
+   } while (0)
+
+Bool
+LoadFunctions(void)
+{
+    /* first try to load the shared library */
+    char const *dlErrStr;
+
+    dlHandle = dlopen("libvmGuestLib.so", RTLD_NOW);
+    if (!dlHandle) {
+        dlErrStr = dlerror();
+        printf("dlopen failed: \'%s\'\n", dlErrStr);
+        return FALSE;
+    }
+
+    /* Load all the individual library functions */
+    LOAD_ONE_FUNC(GuestLib_GetErrorText);
+    LOAD_ONE_FUNC(GuestLib_OpenHandle);
+    LOAD_ONE_FUNC(GuestLib_CloseHandle);
+    LOAD_ONE_FUNC(GuestLib_UpdateInfo);
+    LOAD_ONE_FUNC(GuestLib_GetSessionId);
+    LOAD_ONE_FUNC(GuestLib_GetElapsedMs);
+    LOAD_ONE_FUNC(GuestLib_GetCpuStolenMs);
+    LOAD_ONE_FUNC(GuestLib_GetCpuUsedMs);
+    LOAD_ONE_FUNC(GuestLib_GetCpuReservationMHz);
+    LOAD_ONE_FUNC(GuestLib_GetCpuLimitMHz);
+    LOAD_ONE_FUNC(GuestLib_GetCpuShares);
+    LOAD_ONE_FUNC(GuestLib_GetHostProcessorSpeed);
+    LOAD_ONE_FUNC(GuestLib_GetMemReservationMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemLimitMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemShares);
+    LOAD_ONE_FUNC(GuestLib_GetMemMappedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemActiveMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemOverheadMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemBalloonedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemSwappedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemSharedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemSharedSavedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemUsedMB);
+    LOAD_ONE_FUNC(GuestLib_GetMemTargetSizeMB);
+
+    return TRUE;
+}
+
+static int vmware_init (void)
+{
+    if (!LoadFunctions()) {
+        ERROR ("vmware guest plugin: Unable to load GuistLib functions");
+        return (-1);
+    }
+
+    /* try to load the library */
+    glError = GuestLib_OpenHandle(&glHandle);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        ERROR ("OpenHandle failed: %s", GuestLib_GetErrorText(glError));
+        return (-1);
+    }
+
+    return (0);
+}
+
+static void submit_vmw_counter (const char *type, const char *type_inst,
+				derive_t value)
+{
+    value_t values[1];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    values[0].derive = value;
+
+    vl.values = values;
+    vl.values_len = 1;
+
+    sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+    sstrncpy (vl.plugin, "vmware", sizeof (vl.plugin));
+    sstrncpy (vl.type, type, sizeof (vl.type));
+    sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+}
+
+static void submit_vmw_gauge (const char *type, const char *type_inst,
+                                gauge_t value)
+{
+    value_t values[1];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    values[0].gauge = value;
+
+    vl.values = values;
+    vl.values_len = 1;
+
+    sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+    sstrncpy (vl.plugin, "vmware", sizeof (vl.plugin));
+    sstrncpy (vl.type, type, sizeof (vl.type));
+    sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+}
+
+static int vmware_read (void)
+{
+
+    derive_t value;
+
+    /* time */
+    uint64 elapsedMs = 0;
+
+    /* cpu */
+    uint64 cpuUsedMs = 0;
+    uint64 cpuStolenMs = 0;
+
+    /* cpu_qos */
+    uint32 cpuReservationMHz = 0;
+    uint32 cpuLimitMHz = 0;
+    uint32 cpuShares = 0;
+
+    /* cpu_host */
+    uint32 hostMHz = 0;
+ 
+    /* memory */
+    uint64 memTargetSizeMB = 0;
+    uint32 memUsedMB = 0;
+    uint32 memMappedMB = 0;
+    uint32 memActiveMB = 0;
+    uint32 memOverheadMB = 0;
+    uint32 memSharedMB = 0;
+    uint32 memSharedSavedMB = 0;
+    uint32 memBalloonedMB = 0;
+    uint32 memSwappedMB = 0;
+
+    /* memory_qos */
+    uint32 memReservationMB = 0;
+    uint32 memLimitMB = 0;
+    uint32 memShares = 0;
+
+    VMSessionId sessionId = 0;
+ 
+    /* attempt to retrieve info from the host */
+    VMSessionId tmpSession;
+
+    glError = GuestLib_UpdateInfo(glHandle);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        ERROR ("UpdateInfo failed: %s", GuestLib_GetErrorText(glError));
+        return (-1);
+    }
+
+    /* retrieve and check the session ID */
+    glError = GuestLib_GetSessionId(glHandle, &tmpSession);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        ERROR ("Failed to get session ID: %s", GuestLib_GetErrorText(glError));
+        return (-1);
+    }
+
+    if (tmpSession == 0) {
+        ERROR ("Error: Got zero sessionId from GuestLib");
+        return (-1);
+    }
+
+    if (sessionId == 0) {
+        sessionId = tmpSession;
+        DEBUG ("Initial session ID is 0x%"FMT64"x", sessionId);
+        } else if (tmpSession != sessionId) {
+        sessionId = tmpSession;
+        DEBUG ("SESSION CHANGED: New session ID is 0x%"FMT64"x\n", sessionId);
+    }
+
+    /* GetElapsedMs */
+    glError = GuestLib_GetElapsedMs(glHandle, &elapsedMs);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get elapsed ms: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (derive_t) elapsedMs;
+    submit_vmw_counter ("time", "elapsed_ms", value);
+
+    /* GetCpuUsedMs */
+    glError = GuestLib_GetCpuUsedMs(glHandle, &cpuUsedMs);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get used ms: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (derive_t) cpuUsedMs;
+    submit_vmw_counter ("cpu", "used_ms", value);
+
+    /* GetCpuStolenMs */
+    glError = GuestLib_GetCpuStolenMs(glHandle, &cpuStolenMs);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get CPU stolen: %s\n", GuestLib_GetErrorText(glError));
+        if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
+            cpuStolenMs = 0;
+        }
+    }
+    value = (derive_t) cpuStolenMs;
+    submit_vmw_counter ("cpu", "stolen_ms", value);
+
+    /* GetCpuReservationMHz */ 
+    glError = GuestLib_GetCpuReservationMHz(glHandle, &cpuReservationMHz);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get CPU reservation: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) cpuReservationMHz;
+    submit_vmw_gauge ("vmware_qos", "reservation_mhz", value);
+
+    /* GetCpuLimitMHz */
+    glError = GuestLib_GetCpuLimitMHz(glHandle, &cpuLimitMHz);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get CPU limit: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) cpuLimitMHz;
+    submit_vmw_gauge ("vmware_qos", "limit_mhz", value);
+
+    /* GetCpuShares */
+    glError = GuestLib_GetCpuShares(glHandle, &cpuShares);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get cpu shares: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) cpuShares;
+    submit_vmw_gauge ("vmware_qos", "shares", value);
+
+    /* GetHostProcessorSpeed */
+    glError = GuestLib_GetHostProcessorSpeed(glHandle, &hostMHz);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get host proc speed: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) hostMHz;
+    submit_vmw_gauge ("vmware_host_cpu", "clock_speed_mhz", value);
+
+    /* GetMemTargetSizeMB */
+    glError = GuestLib_GetMemTargetSizeMB(glHandle, &memTargetSizeMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get target mem size: %s\n", GuestLib_GetErrorText(glError));
+        if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
+            memTargetSizeMB = 0;
+        }
+    }
+    value = (gauge_t) memTargetSizeMB;
+    submit_vmw_gauge ("memory", "target_mb", value);
+
+    /* GetMemUsedMB */
+    glError = GuestLib_GetMemUsedMB(glHandle, &memUsedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get used mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memUsedMB;
+    submit_vmw_gauge ("memory", "used_mb", value);
+
+    /* GetMemMappedMB */
+    glError = GuestLib_GetMemMappedMB(glHandle, &memMappedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get mapped mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memMappedMB;
+    submit_vmw_gauge ("memory", "mapped_mb", value);
+
+    /* GetMemActiveMB */
+    glError = GuestLib_GetMemActiveMB(glHandle, &memActiveMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get active mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memActiveMB;
+    submit_vmw_gauge ("memory", "active_mb", value);
+
+    /* GetMemOverheadMB */
+    glError = GuestLib_GetMemOverheadMB(glHandle, &memOverheadMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get overhead mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memOverheadMB;
+    submit_vmw_gauge ("memory", "overhead_mb", value);
+
+    /* GetMemSharedMB */
+    glError = GuestLib_GetMemSharedMB(glHandle, &memSharedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get shared mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memSharedMB;
+    submit_vmw_gauge ("memory", "shared_mb", value);
+
+    /* GetMemSharedSavedMB */
+    glError = GuestLib_GetMemSharedSavedMB(glHandle, &memSharedSavedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get shared saved mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memSharedSavedMB;
+    submit_vmw_gauge ("memory", "shared_saved_mb", value);
+
+    /* GetMemBalloonedMB */
+    glError = GuestLib_GetMemBalloonedMB(glHandle, &memBalloonedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get ballooned mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memBalloonedMB;
+    submit_vmw_gauge ("memory", "ballooned_mb", value);
+
+    /* GetMemSwappedMB */
+    glError = GuestLib_GetMemSwappedMB(glHandle, &memSwappedMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memSwappedMB;
+    submit_vmw_gauge ("memory", "swapped_mb", value);
+
+    /* GetMemReservationMB */
+    glError = GuestLib_GetMemReservationMB(glHandle, &memReservationMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get mem reservation: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memReservationMB;
+    submit_vmw_gauge ("vmware_qos", "reservation_mb", value);
+
+    /* GetMemLimitMB */
+    glError = GuestLib_GetMemLimitMB(glHandle, &memLimitMB);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get mem limit: %s\n", GuestLib_GetErrorText(glError));
+    }
+    value = (gauge_t) memLimitMB;
+    submit_vmw_gauge ("vmware_qos", "limit_mb", value);
+
+    /* GetMemShares */
+    glError = GuestLib_GetMemShares(glHandle, &memShares);
+    if (glError != VMGUESTLIB_ERROR_SUCCESS) {
+        DEBUG ("Failed to get mem shares: %s\n", GuestLib_GetErrorText(glError));
+        memShares = 0;
+    }
+    value = (gauge_t) memShares;
+    submit_vmw_gauge ("vmware_qos", "shares", value);
+
+    return (0);
+}
+
+void module_register (void)
+{
+    plugin_register_init ("vmware", vmware_init);
+    plugin_register_read ("vmware", vmware_read);
+}




More information about the collectd mailing list