Guest Statistics Interfaces
You have a choice of three interfaces to fetch the new statistics: the guest SDK library, CLI, or raw RPC.
Guest SDK Library
The Guest SDK library now offers two new functions, get and free.
VMGuestLib_StatGet
/* Semi-structured hypervisor statistics collection, for troubleshooting.
*/
VMGuestLibError
VMGuestLib_StatGet(const char *encoding, // IN
const char *stat,    // IN
char **reply,        // OUT
size_t *replySize); // OUT
encodingtext or “xml” or “json” or “yaml” – if not specified, “text” is the default.
stat – the statistic to print. See examples below.
reply – a pointer to be set with a buffer containing the formatted reply. All current formats return null-terminated C strings, but future formats may not; the caller should treat the buffer as binary unless the format is known. The buffer must later be freed by a call to VMGuestLib_StatFree().
replySize – a pointer to receive the size of data in the buffer.
VMGuestLib_StatFree
To free the memory returned by VMGuestLib_StatGet, call VMGuestLib_StatFree().
void
VMGuestLib_StatFree(char *reply, size_t replySize);
reply – the pointer that was supplied by the reply parameter of VMGuestLib_StatGet().
replySize – the size that was supplied by the replySize parameter of VMGuestLib_StatGet().
Example: C code with StatGet and StatFree functions shows these two function calls used in a sample routine:
Example: C code with StatGet and StatFree functions
/*
* Retrieves semi-structured statistics on ESXi host.
*/
static int
StatGetRaw(const char *encoding, // IN
const char *stat,   // IN
const char *param)  // IN
{
   int exitStatus = EXIT_SUCCESS;
   VMGuestLibError glError;
   char *result = NULL;
   size_t resultSize = 0;
   char *arg = g_strdup_printf("%s %s", stat, param);
 
   glError = VMGuestLib_StatGet(encoding, arg, &result, &resultSize);
   if (glError != VMGUESTLIB_ERROR_SUCCESS) {
      exitStatus = EX_TEMPFAIL;
   } else {
      g_print("%*s", (int)resultSize, result);
   }
   VMGuestLib_StatFree(result, resultSize);
   g_free(arg);
   return exitStatus;
}
 
Command Line Interface
The command name varies with each of the three OS types available, but all three have a -v option to show the VMware Tools version number.
Linux: vmware-toolbox-cmd stat raw <encoding> <stat>
Mac: vmware-tools-cli stat raw <encoding> <stat>
Windows: VMwareToolboxCmd.exe stat raw <encoding> <stat>
These commands are provided for debugging and scripting; the implementation is a wrapper on top of the VMGuestLib_StatGet() call described above.
Raw RPC interface
The raw RPC interface varies for one of the three OS types available.
Linux: vmtoolsd --cmd="guestlib.stat.get <encoding> <stat>"
Mac: vmtoolsd --cmd="guestlib.stat.get <encoding> <stat>"
Windows: vmtoolsd.exe --cmd="guestlib.stat.get <encoding> <stat>"
This is a raw form of the statistics API. Function calls or CLI are preferred.