From: Keith Chambers Date: Sun, 18 Sep 2011 16:58:02 +0000 (-0700) Subject: VMware Plugin: Various improvements. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d7ece1d2b10be46a2f0b697bd2c6838d2fe8f4fa;p=collectd.git VMware Plugin: Various improvements. Made all changes requested by Florian Forster - Removed trailing white spaces in configure.in, src/collectd.conf.pod, src/vmware.c - Removed unused plugin_vmware variable from configure.in - Removed unneeded include statements for stdarg.h, stdio.h, dlfcn.h - Changed include for vmGuestLib.h to use angle brackets instead of double quotes - Changed global variable VMGuestLibHandle to static - Changed printf errors to use ERROR() macro - Changed variable names to follow the normal C / collectd naming schema, e.g. "elapsed_ms" and "cpu_used_ms". Rebased on top of Edward Muller's commit. --octo --- diff --git a/AUTHORS b/AUTHORS index 45645d1a..dd34de6d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -73,6 +73,9 @@ Doug MacEachern Edward “Koko” Konetzko - fscache plugin. +Edward Muller + - vmware plugin. + Fabian Linzberger - Percentage aggregation for `collectd-nagios'. @@ -91,6 +94,9 @@ Jason Pepas Jérôme Renard - varnish plugin. +Keith Chambers + - vmware plugin. + Kris Nielander - tail_csv plugin. diff --git a/README b/README index c3c45472..56444fe1 100644 --- a/README +++ b/README @@ -316,6 +316,10 @@ Features - varnish Various statistics from Varnish, an HTTP accelerator. + - vmware + The VMware plugin collects information exposed to a guest virtual + machine running on a VMware hypervisor through the VMware Guest SDK. + - vmem Virtual memory statistics, e. g. the number of page-ins/-outs or the number of pagefaults. diff --git a/configure.in b/configure.in index 2118d78d..a5403990 100644 --- a/configure.in +++ b/configure.in @@ -4243,6 +4243,39 @@ then fi # }}} +# --with-libvmware {{{ +with_libvmware_cflags="" +AC_ARG_WITH(libvmware, [AS_HELP_STRING([--with-libvmware@<:@=PREFIX@:>@], [Path to libvmware.])], +[ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libvmware_cflags="-I$withval" + with_libvmware="yes" + else + with_libvmware="$withval" + fi +], +[ + with_libvmware="yes" +]) +if test "x$with_libvmware" = "xyes" +then + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $with_libvmware_cflags" + + AC_CHECK_HEADERS(vmGuestLib.h, [with_libvmware="yes"], [with_libvmware="no (vmGuestLib.h not found)"]) + + CFLAGS="$SAVE_CFLAGS" +fi +if test "x$with_libvmware" = "xyes" +then + BUILD_WITH_LIBVMWARE_CFLAGS="$with_libvmware_cflags" + AC_SUBST(BUILD_WITH_LIBVMWARE_CFLAGS) + #AC_DEFINE(HAVE_LIBVMWARE, 1, [Define if libvmware is present and usable.]) +fi +AM_CONDITIONAL(BUILD_WITH_LIBVMWARE, test "x$with_libvmware" = "xyes") +# }}} + # pkg-config --exists 'libxml-2.0'; pkg-config --exists libvirt {{{ with_libxml2="no (pkg-config isn't available)" with_libxml2_cflags="" @@ -4640,6 +4673,7 @@ then plugin_tcpconns="yes" plugin_thermal="yes" plugin_uptime="yes" + plugin_vmware="yes" plugin_vmem="yes" plugin_vserver="yes" plugin_wireless="yes" @@ -4722,9 +4756,6 @@ then then plugin_bind="yes" fi - - # FIXME: Check for the required library. - plugin_vmware="yes" fi if test "x$with_libopenipmipthread" = "xyes" @@ -4997,7 +5028,7 @@ AC_PLUGIN([users], [$plugin_users], [User statistics]) AC_PLUGIN([uuid], [yes], [UUID as hostname plugin]) AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics]) AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics]) -AC_PLUGIN([vmware], [$plugin_vmware], [VMware client statistics]) +AC_PLUGIN([vmware], [$with_libvmware], [VMware client statistics]) AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics]) AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics]) AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin]) @@ -5211,6 +5242,7 @@ Configuration: libupsclient . . . . $with_libupsclient libvarnish . . . . . $with_libvarnish libvirt . . . . . . . $with_libvirt + libvmware . . . . . . $with_libvmware libxml2 . . . . . . . $with_libxml2 libxmms . . . . . . . $with_libxmms libyajl . . . . . . . $with_libyajl diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 5af15684..c81b4ea4 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -157,6 +157,7 @@ #@BUILD_PLUGIN_UUID_TRUE@LoadPlugin uuid #@BUILD_PLUGIN_VARNISH_TRUE@LoadPlugin varnish #@BUILD_PLUGIN_VMEM_TRUE@LoadPlugin vmem +#@BUILD_PLUGIN_VMWARE_TRUE@LoadPlugin vmware #@BUILD_PLUGIN_VSERVER_TRUE@LoadPlugin vserver #@BUILD_PLUGIN_WIRELESS_TRUE@LoadPlugin wireless #@BUILD_PLUGIN_WRITE_GRAPHITE_TRUE@LoadPlugin write_graphite diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 8606d3e0..63e1f731 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -5477,6 +5477,11 @@ Take the UUID from the given file (default I). The Varnish plugin collects information about Varnish, an HTTP accelerator. +=head2 Plugin C + +The VMware plugin collects information exposed to a guest virtual machine +running on a VMware hypervisor through the VMware Guest SDK. + =over 4 =item B B|B diff --git a/src/vmware.c b/src/vmware.c index 507375e6..a1b5e914 100644 --- a/src/vmware.c +++ b/src/vmware.c @@ -1,520 +1,426 @@ -#include -#include -#include -#include +/** + * collectd - src/vmware.c + * Copyright (C) 2010 Edward Muller + * Copyright (C) 2011 Keith Chambers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; only version 2.1 of the License is + * applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Edward Muller + * Keith Chambers + **/ + #include "collectd.h" #include "common.h" #include "plugin.h" +#include -#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); -VMGuestLibError (*GuestLib_GetCpuReservationMHz)(VMGuestLibHandle handle, - uint32 *cpuReservationMHz); -VMGuestLibError (*GuestLib_GetCpuLimitMHz)(VMGuestLibHandle handle, uint32 *cpuLimitMHz); -VMGuestLibError (*GuestLib_GetCpuShares)(VMGuestLibHandle handle, uint32 *cpuShares); -VMGuestLibError (*GuestLib_GetCpuUsedMs)(VMGuestLibHandle handle, uint64 *cpuUsedMs); -VMGuestLibError (*GuestLib_GetHostProcessorSpeed)(VMGuestLibHandle handle, uint32 *mhz); -VMGuestLibError (*GuestLib_GetMemReservationMB)(VMGuestLibHandle handle, - uint32 *memReservationMB); -VMGuestLibError (*GuestLib_GetMemLimitMB)(VMGuestLibHandle handle, uint32 *memLimitMB); -VMGuestLibError (*GuestLib_GetMemShares)(VMGuestLibHandle handle, uint32 *memShares); -VMGuestLibError (*GuestLib_GetMemMappedMB)(VMGuestLibHandle handle, - uint32 *memMappedMB); -VMGuestLibError (*GuestLib_GetMemActiveMB)(VMGuestLibHandle handle, uint32 *memActiveMB); -VMGuestLibError (*GuestLib_GetMemOverheadMB)(VMGuestLibHandle handle, - uint32 *memOverheadMB); -VMGuestLibError (*GuestLib_GetMemBalloonedMB)(VMGuestLibHandle handle, - uint32 *memBalloonedMB); -VMGuestLibError (*GuestLib_GetMemSwappedMB)(VMGuestLibHandle handle, - uint32 *memSwappedMB); -VMGuestLibError (*GuestLib_GetMemSharedMB)(VMGuestLibHandle handle, - uint32 *memSharedMB); -VMGuestLibError (*GuestLib_GetMemSharedSavedMB)(VMGuestLibHandle handle, - uint32 *memSharedSavedMB); -VMGuestLibError (*GuestLib_GetMemUsedMB)(VMGuestLibHandle handle, - uint32 *memUsedMB); -VMGuestLibError (*GuestLib_GetElapsedMs)(VMGuestLibHandle handle, uint64 *elapsedMs); -VMGuestLibError (*GuestLib_GetResourcePoolPath)(VMGuestLibHandle handle, - size_t *bufferSize, - char *pathBuffer); -VMGuestLibError (*GuestLib_GetCpuStolenMs)(VMGuestLibHandle handle, - uint64 *cpuStolenMs); -VMGuestLibError (*GuestLib_GetMemTargetSizeMB)(VMGuestLibHandle handle, - uint64 *memTargetSizeMB); -VMGuestLibError (*GuestLib_GetHostNumCpuCores)(VMGuestLibHandle handle, - uint32 *hostNumCpuCores); -VMGuestLibError (*GuestLib_GetHostCpuUsedMs)(VMGuestLibHandle handle, - uint64 *hostCpuUsedMs); -VMGuestLibError (*GuestLib_GetHostMemSwappedMB)(VMGuestLibHandle handle, - uint64 *hostMemSwappedMB); -VMGuestLibError (*GuestLib_GetHostMemSharedMB)(VMGuestLibHandle handle, - uint64 *hostMemSharedMB); -VMGuestLibError (*GuestLib_GetHostMemUsedMB)(VMGuestLibHandle handle, - uint64 *hostMemUsedMB); -VMGuestLibError (*GuestLib_GetHostMemPhysMB)(VMGuestLibHandle handle, - uint64 *hostMemPhysMB); -VMGuestLibError (*GuestLib_GetHostMemPhysFreeMB)(VMGuestLibHandle handle, - uint64 *hostMemPhysFreeMB); -VMGuestLibError (*GuestLib_GetHostMemKernOvhdMB)(VMGuestLibHandle handle, - uint64 *hostMemKernOvhdMB); -VMGuestLibError (*GuestLib_GetHostMemMappedMB)(VMGuestLibHandle handle, - uint64 *hostMemMappedMB); -VMGuestLibError (*GuestLib_GetHostMemUnmappedMB)(VMGuestLibHandle handle, - uint64 *hostMemUnmappedMB); -/* - * Handle for use with shared library. - */ -void *dlHandle = NULL; - -/* - * GuestLib handle. - */ -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) +#include + +/* functions to dynamically load from the GuestLib library */ +static char const * (*GuestLib_GetErrorText)(VMGuestLibError); +static VMGuestLibError (*GuestLib_OpenHandle)(VMGuestLibHandle*); +static VMGuestLibError (*GuestLib_CloseHandle)(VMGuestLibHandle); +static VMGuestLibError (*GuestLib_UpdateInfo)(VMGuestLibHandle handle); +static VMGuestLibError (*GuestLib_GetSessionId)(VMGuestLibHandle handle, VMSessionId *id); +static VMGuestLibError (*GuestLib_GetElapsedMs)(VMGuestLibHandle handle, uint64_t *elapsedMs); +static VMGuestLibError (*GuestLib_GetCpuUsedMs)(VMGuestLibHandle handle, uint64_t *cpuUsedMs); +static VMGuestLibError (*GuestLib_GetCpuStolenMs)(VMGuestLibHandle handle, uint64_t *cpuStolenMs); +static VMGuestLibError (*GuestLib_GetCpuReservationMHz)(VMGuestLibHandle handle, uint32_t *cpuReservationMHz); +static VMGuestLibError (*GuestLib_GetCpuLimitMHz)(VMGuestLibHandle handle, uint32_t *cpuLimitMHz); +static VMGuestLibError (*GuestLib_GetCpuShares)(VMGuestLibHandle handle, uint32_t *cpuShares); +static VMGuestLibError (*GuestLib_GetHostProcessorSpeed)(VMGuestLibHandle handle, uint32_t *mhz); +static VMGuestLibError (*GuestLib_GetMemUsedMB)(VMGuestLibHandle handle, uint32_t *memUsedMB); +static VMGuestLibError (*GuestLib_GetMemMappedMB)(VMGuestLibHandle handle, uint32_t *memMappedMB); +static VMGuestLibError (*GuestLib_GetMemActiveMB)(VMGuestLibHandle handle, uint32_t *memActiveMB); +static VMGuestLibError (*GuestLib_GetMemTargetSizeMB)(VMGuestLibHandle handle, uint64_t *memTargetSizeMB); +static VMGuestLibError (*GuestLib_GetMemOverheadMB)(VMGuestLibHandle handle, uint32_t *memOverheadMB); +static VMGuestLibError (*GuestLib_GetMemSharedMB)(VMGuestLibHandle handle, uint32_t *memSharedMB); +static VMGuestLibError (*GuestLib_GetMemSharedSavedMB)(VMGuestLibHandle handle, uint32_t *memSharedSavedMB); +static VMGuestLibError (*GuestLib_GetMemBalloonedMB)(VMGuestLibHandle handle, uint32_t *memBalloonedMB); +static VMGuestLibError (*GuestLib_GetMemSwappedMB)(VMGuestLibHandle handle, uint32_t *memSwappedMB); +static VMGuestLibError (*GuestLib_GetMemReservationMB)(VMGuestLibHandle handle, uint32_t *memReservationMB); +static VMGuestLibError (*GuestLib_GetMemLimitMB)(VMGuestLibHandle handle, uint32_t *memLimitMB); +static VMGuestLibError (*GuestLib_GetMemShares)(VMGuestLibHandle handle, uint32_t *memShares); + +/* handle for use with shared library */ +static VMGuestLibHandle glHandle; + +/* used when converting megabytes to bytes for memory counters */ +#define BYTES_PER_MB 1024*1024 + +/* 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) { \ + ERROR ("vmware plugin: Failed to load \"%s\": %s", \ +#funcname, dlErrStr); \ + return (-1); \ + } \ + } while (0) + + _Bool +static 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_GetCpuReservationMHz); - LOAD_ONE_FUNC(GuestLib_GetCpuLimitMHz); - LOAD_ONE_FUNC(GuestLib_GetCpuShares); - LOAD_ONE_FUNC(GuestLib_GetCpuUsedMs); - 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_GetElapsedMs); - LOAD_ONE_FUNC(GuestLib_GetResourcePoolPath); - LOAD_ONE_FUNC(GuestLib_GetCpuStolenMs); - LOAD_ONE_FUNC(GuestLib_GetMemTargetSizeMB); - LOAD_ONE_FUNC(GuestLib_GetHostNumCpuCores); - LOAD_ONE_FUNC(GuestLib_GetHostCpuUsedMs); - LOAD_ONE_FUNC(GuestLib_GetHostMemSwappedMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemSharedMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemUsedMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemPhysMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemPhysFreeMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemKernOvhdMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemMappedMB); - LOAD_ONE_FUNC(GuestLib_GetHostMemUnmappedMB); - - return TRUE; + void *dlHandle = NULL; + + /* first try to load the shared library */ + char const *dlErrStr; + + dlHandle = dlopen("libvmGuestLib.so", RTLD_NOW); + if (!dlHandle) { + dlErrStr = dlerror(); + ERROR("vmware plugin: dlopen (\"libvmGuestLib.so\") failed: %s", + dlErrStr); + return (-1); + } + + /* 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 (0); } static int vmware_init (void) { + VMGuestLibError glError; + if (!LoadFunctions()) { - ERROR ("vmware guest plugin: Unable to load GuistLib functions"); + ERROR ("vmware plugin: Unable to load GuestLib functions"); return (-1); } - /* Try to load the library. */ + /* try to load the library */ glError = GuestLib_OpenHandle(&glHandle); if (glError != VMGUESTLIB_ERROR_SUCCESS) { - ERROR ("OpenHandle failed: %s", GuestLib_GetErrorText(glError)); - return (-1); + ERROR ("vmware plugin: OpenHandle failed: %s", GuestLib_GetErrorText(glError)); + return (-1); } return (0); } -static void vmware_submit_counter (const char *reading, counter_t value) +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; + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; - vl.values = values; - vl.values_len = 1; + 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, reading, sizeof (vl.type)); + 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); + plugin_dispatch_values (&vl); } -static void vmware_submit_gauge (const char *reading, gauge_t value) +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; + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; + values[0].gauge = value; - vl.values = values; - vl.values_len = 1; + 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, reading, sizeof (vl.type)); + 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); + plugin_dispatch_values (&vl); } +static int vmw_query_memory (VMGuestLibHandle handle, const char *function_name, + VMGuestLibError (*function) (VMGuestLibHandle handle, uint32_t *ret_data), + const char *type_instance) +{ + uint32_t value; + VMGuestLibError status; + + status = (*function) (handle, &value); + if (status != VMGUESTLIB_ERROR_SUCCESS) { + WARNING ("vmware plugin: %s failed: %s", + function_name, + GuestLib_GetErrorText(glError)); + return (-1); + } + + /* The returned value is in megabytes, so multiply it by 2^20. It's not + * 10^6, because we're talking about memory. */ + submit_vmw_gauge ("memory", type_instance, + (gauge_t) (1024 * 1024 * value)); + return (0); +} /* }}} int vmw_query_megabyte */ + static int vmware_read (void) { - counter_t value; - uint32 cpuReservationMHz = 0; - uint32 cpuLimitMHz = 0; - uint32 cpuShares = 0; - uint64 cpuUsedMs = 0; - uint32 hostMHz = 0; - uint32 memReservationMB = 0; - uint32 memLimitMB = 0; - uint32 memShares = 0; - uint32 memMappedMB = 0; - uint32 memActiveMB = 0; - uint32 memOverheadMB = 0; - uint32 memBalloonedMB = 0; - uint32 memSwappedMB = 0; - uint32 memSharedMB = 0; - uint32 memSharedSavedMB = 0; - uint32 memUsedMB = 0; - uint64 elapsedMs = 0; - uint64 cpuStolenMs = 0; - uint64 memTargetSizeMB = 0; - uint32 hostNumCpuCores = 0; - uint64 hostCpuUsedMs = 0; - uint64 hostMemSwappedMB = 0; - uint64 hostMemSharedMB = 0; - uint64 hostMemUsedMB = 0; - uint64 hostMemPhysMB = 0; - uint64 hostMemPhysFreeMB = 0; - uint64 hostMemKernOvhdMB = 0; - uint64 hostMemMappedMB = 0; - uint64 hostMemUnmappedMB = 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)); + VMGuestLibError glError; + + /* total_time_in_ms */ + uint64_t elapsedMs = 0; + + /* virt_vcpu */ + uint64_t cpuUsedMs = 0; + uint64_t cpuStolenMs = 0; + + /* vcpu (quality of service) */ + uint32_t cpuReservationMHz = 0; + uint32_t cpuLimitMHz = 0; + uint32_t cpuShares = 0; + + /* cpufreq */ + uint32_t hostMHz = 0; + + /* memory */ + uint64_t memTargetSizeMB = 0; + uint32_t memUsedMB = 0; + uint32_t memMappedMB = 0; + uint32_t memActiveMB = 0; + uint32_t memOverheadMB = 0; + uint32_t memSharedMB = 0; + uint32_t memSharedSavedMB = 0; + uint32_t memBalloonedMB = 0; + uint32_t memSwappedMB = 0; + + /* memory (quality of service) */ + uint32_t memReservationMB = 0; + uint32_t memLimitMB = 0; + uint32_t memShares = 0; + + VMSessionId sessionId = 0; + + /* attempt to retrieve info from the host */ + VMSessionId tmpSession; + + glError = GuestLib_UpdateInfo(glHandle); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + ERROR ("vmware plugin: 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 ("vmware plugin: Failed to get session ID: %s", GuestLib_GetErrorText(glError)); return (-1); - } + } - if (tmpSession == 0) { - ERROR ("Error: Got zero sessionId from GuestLib"); - return (-1); - } + if (tmpSession == 0) { + ERROR ("vmware plugin: Error: Got zero sessionId from GuestLib"); + return (-1); + } - if (sessionId == 0) { + if (sessionId == 0) { sessionId = tmpSession; - DEBUG ("Initial session ID is 0x%"FMT64"x", sessionId); - } else if (tmpSession != sessionId) { + DEBUG ("vmware plugin: Initial session ID is %#"PRIx64, (uint64_t) sessionId); + } else if (tmpSession != sessionId) { sessionId = tmpSession; - DEBUG ("SESSION CHANGED: New session ID is 0x%"FMT64"x\n", sessionId); - } - - /* Retrieve all the stats. */ - /* FIXME: GENERALIZE */ - 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; - vmware_submit_gauge ("cpu_reservation_mhz", value); + DEBUG ("vmware plugin: Session ID changed to %#"PRIx64, (uint64_t) sessionId); + } - glError = GuestLib_GetCpuLimitMHz(glHandle, &cpuLimitMHz); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get CPU limit: %s\n", GuestLib_GetErrorText(glError)); + /* GetElapsedMs */ + glError = GuestLib_GetElapsedMs(glHandle, &elapsedMs); + if (glError != VMGUESTLIB_ERROR_SUCCESS) + WARNING ("vmware plugin: Failed to get elapsed ms: %s", GuestLib_GetErrorText(glError)); + else + submit_vmw_counter ("total_time_in_ms", "elapsed", (derive_t) elapsedMs); + + /* GetCpuUsedMs */ + glError = GuestLib_GetCpuUsedMs(glHandle, &cpuUsedMs); + if (glError != VMGUESTLIB_ERROR_SUCCESS) + WARNING ("vmware plugin: Failed to get used ms: %s", + GuestLib_GetErrorText(glError)); + else + submit_vmw_counter ("virt_vcpu", "used", (derive_t) cpuUsedMs); + + /* GetCpuStolenMs */ + glError = GuestLib_GetCpuStolenMs(glHandle, &cpuStolenMs); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get CPU stolen: %s\n", GuestLib_GetErrorText(glError)); + if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) { + cpuStolenMs = 0; } - value = (gauge_t) cpuLimitMHz; - vmware_submit_gauge ("cpu_limit_mhz", value); + } + submit_vmw_counter ("virt_vcpu", "stolen", (derive_t) cpuStolenMs); - 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; - vmware_submit_gauge ("cpu_shares", value); + /* GetCpuReservationMHz */ + glError = GuestLib_GetCpuReservationMHz(glHandle, &cpuReservationMHz); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get CPU reservation: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("vcpu", "reservation", (gauge_t) cpuReservationMHz); - glError = GuestLib_GetCpuUsedMs(glHandle, &cpuUsedMs); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get used ms: %s\n", GuestLib_GetErrorText(glError)); - } - value = (counter_t) cpuUsedMs; - vmware_submit_counter ("cpu_used_ms", value); + /* GetCpuLimitMHz */ + glError = GuestLib_GetCpuLimitMHz(glHandle, &cpuLimitMHz); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get CPU limit: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("vcpu", "limit", (gauge_t) cpuLimitMHz); - 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; - vmware_submit_gauge ("host_processor_speed", value); + /* GetCpuShares */ + glError = GuestLib_GetCpuShares(glHandle, &cpuShares); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get cpu shares: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("vcpu", "shares", (gauge_t) cpuShares); - glError = GuestLib_GetMemReservationMB(glHandle, &memReservationMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get mem reservation: %s\n", GuestLib_GetErrorText(glError)); + /* GetHostProcessorSpeed */ + glError = GuestLib_GetHostProcessorSpeed(glHandle, &hostMHz); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get host proc speed: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("cpufreq", "", 1.0e6 * (gauge_t) hostMHz); + +#define VMW_QUERY_MEMORY(func, type) \ + vmw_query_memory (glHandle, #func, GuestLib_ ## func, type) + + VMW_QUERY_MEMORY (GetMemTargetSizeMB, "target"); + VMW_QUERY_MEMORY (GetMemUsedMB, "used"); + VMW_QUERY_MEMORY (GetMemMappedMB, "mapped"); + VMW_QUERY_MEMORY (GetMemActiveMB, "active"); + VMW_QUERY_MEMORY (GetMemOverheadMB, "overhead"); + VMW_QUERY_MEMORY (GetMemSharedMB, "shared"); + VMW_QUERY_MEMORY (GetMemSharedSavedMB, "shared_saved"); + VMW_QUERY_MEMORY (GetMemBalloonedMB, "ballooned"); + VMW_QUERY_MEMORY (GetMemSwappedMB, "swapped"); + VMW_QUERY_MEMORY (GetMemReservationMB, "reservation"); + VMW_QUERY_MEMORY (GetMemLimitMB, "limit"); + +#undef VMW_QUERY_MEMORY + + /* GetMemTargetSizeMB */ + glError = GuestLib_GetMemTargetSizeMB(glHandle, &memTargetSizeMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get target mem size: %s\n", GuestLib_GetErrorText(glError)); + if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) { + memTargetSizeMB = 0; } - value = (gauge_t) memReservationMB; - vmware_submit_gauge ("memory_reservation_mb", value); + } + submit_vmw_gauge ("memory", "target", BYTES_PER_MB * (gauge_t) memTargetSizeMB); - 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; - vmware_submit_gauge ("memory_limit_mb", value); + /* GetMemUsedMB */ + glError = GuestLib_GetMemUsedMB(glHandle, &memUsedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get used mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "used", BYTES_PER_MB * (gauge_t) memUsedMB); - 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; - vmware_submit_gauge ("memory_shares", value); + /* GetMemMappedMB */ + glError = GuestLib_GetMemMappedMB(glHandle, &memMappedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get mapped mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "mapped", BYTES_PER_MB * (gauge_t) memMappedMB); - 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; - vmware_submit_gauge ("memory_mapped_mb", value); + /* GetMemActiveMB */ + glError = GuestLib_GetMemActiveMB(glHandle, &memActiveMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get active mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "active", BYTES_PER_MB * (gauge_t) memActiveMB); - 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; - vmware_submit_gauge ("memory_active_mb", value); + /* GetMemOverheadMB */ + glError = GuestLib_GetMemOverheadMB(glHandle, &memOverheadMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get overhead mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "overhead", BYTES_PER_MB * (gauge_t) memOverheadMB); - 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; - vmware_submit_gauge ("memory_overhead_mb", value); + /* GetMemSharedMB */ + glError = GuestLib_GetMemSharedMB(glHandle, &memSharedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get shared mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "shared", BYTES_PER_MB * (gauge_t) memSharedMB); - 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; - vmware_submit_gauge ("memory_ballooned_mb", value); + /* GetMemSharedSavedMB */ + glError = GuestLib_GetMemSharedSavedMB(glHandle, &memSharedSavedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get shared saved mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "shared_saved", BYTES_PER_MB * (gauge_t) memSharedSavedMB); - 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; - vmware_submit_gauge ("memory_swapped_mb", value); + /* GetMemBalloonedMB */ + glError = GuestLib_GetMemBalloonedMB(glHandle, &memBalloonedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get ballooned mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "ballooned", BYTES_PER_MB * (gauge_t) memBalloonedMB); - glError = GuestLib_GetMemSharedMB(glHandle, &memSharedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError)); - } - value = (gauge_t) memSharedMB; - vmware_submit_gauge ("memory_shared_mb", value); + /* GetMemSwappedMB */ + glError = GuestLib_GetMemSwappedMB(glHandle, &memSwappedMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "swapped", BYTES_PER_MB * (gauge_t) memSwappedMB); - glError = GuestLib_GetMemSharedSavedMB(glHandle, &memSharedSavedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError)); - } - value = (gauge_t) memSharedSavedMB; - vmware_submit_gauge ("memory_shared_saved_mb", value); + /* GetMemReservationMB */ + glError = GuestLib_GetMemReservationMB(glHandle, &memReservationMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get mem reservation: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "reservation", BYTES_PER_MB * (gauge_t) memReservationMB); - glError = GuestLib_GetMemUsedMB(glHandle, &memUsedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get swapped mem: %s\n", GuestLib_GetErrorText(glError)); - } - value = (gauge_t) memUsedMB; - vmware_submit_gauge ("memory_used_mb", value); + /* GetMemLimitMB */ + glError = GuestLib_GetMemLimitMB(glHandle, &memLimitMB); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get mem limit: %s\n", GuestLib_GetErrorText(glError)); + } + submit_vmw_gauge ("memory", "limit", BYTES_PER_MB * (gauge_t) memLimitMB); - glError = GuestLib_GetElapsedMs(glHandle, &elapsedMs); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get elapsed ms: %s\n", GuestLib_GetErrorText(glError)); - } - value = (counter_t) elapsedMs; - vmware_submit_counter ("elapsed_ms", value); - - 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 = (counter_t) cpuStolenMs; - vmware_submit_counter ("cpu_stolen_ms", value); - - 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; - vmware_submit_gauge ("memory_target_size", value); - - glError = GuestLib_GetHostNumCpuCores(glHandle, &hostNumCpuCores); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host CPU cores: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostNumCpuCores = 0; - } - } - value = (gauge_t) hostNumCpuCores; - vmware_submit_gauge ("host_cpu_cores", value); - - glError = GuestLib_GetHostCpuUsedMs(glHandle, &hostCpuUsedMs); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host CPU used: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostCpuUsedMs = 0; - } - } - value = (counter_t) hostCpuUsedMs; - vmware_submit_counter ("host_cpu_used_ms", value); - - glError = GuestLib_GetHostMemSwappedMB(glHandle, &hostMemSwappedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host mem swapped: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemSwappedMB = 0; - } - } - value = (gauge_t) hostMemSwappedMB; - vmware_submit_gauge ("host_mem_swapped_mb", value); - - glError = GuestLib_GetHostMemSharedMB(glHandle, &hostMemSharedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host mem shared: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemSharedMB = 0; - } - } - value = (gauge_t) hostMemSharedMB; - vmware_submit_gauge ("host_mem_shared_mb", value); - - glError = GuestLib_GetHostMemUsedMB(glHandle, &hostMemUsedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host mem used: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemUsedMB = 0; - } - } - value = (gauge_t) hostMemSharedMB; - vmware_submit_gauge ("host_mem_used_mb", value); - - glError = GuestLib_GetHostMemPhysMB(glHandle, &hostMemPhysMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host phys mem: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemPhysMB = 0; - } - } - value = (gauge_t) hostMemPhysMB; - vmware_submit_gauge ("host_mem_physical_mb", value); - - glError = GuestLib_GetHostMemPhysFreeMB(glHandle, &hostMemPhysFreeMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host phys mem free: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemPhysFreeMB = 0; - } - } - value = (gauge_t) hostMemPhysFreeMB; - vmware_submit_gauge ("host_mem_physical_free_mb", value); - - glError = GuestLib_GetHostMemKernOvhdMB(glHandle, &hostMemKernOvhdMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host kernel overhead mem: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemKernOvhdMB = 0; - } - } - value = (gauge_t) hostMemKernOvhdMB; - vmware_submit_gauge ("host_mem_kernel_overhead_mb", value); - - glError = GuestLib_GetHostMemMappedMB(glHandle, &hostMemMappedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host mem mapped: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemMappedMB = 0; - } - } - value = (gauge_t) hostMemMappedMB; - vmware_submit_gauge ("host_mem_mapped_mb", value); - - glError = GuestLib_GetHostMemUnmappedMB(glHandle, &hostMemUnmappedMB); - if (glError != VMGUESTLIB_ERROR_SUCCESS) { - DEBUG ("Failed to get host mem unmapped: %s\n", GuestLib_GetErrorText(glError)); - if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION || - glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) { - hostMemUnmappedMB = 0; - } - } - value = (gauge_t) hostMemUnmappedMB; - vmware_submit_gauge ("host_mem_unmapped_mb", value); + /* GetMemShares */ + glError = GuestLib_GetMemShares(glHandle, &memShares); + if (glError != VMGUESTLIB_ERROR_SUCCESS) { + DEBUG ("vmware plugin: Failed to get mem shares: %s\n", GuestLib_GetErrorText(glError)); + memShares = 0; + } + submit_vmw_gauge ("memory", "shares", (gauge_t) memShares); - return (0); + return (0); } void module_register (void)