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
- encoding–“text”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 toVMGuestLib_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()
.
voidVMGuestLib_StatFree(char *reply, size_t replySize);
- reply– the pointer that was supplied by thereplyparameter ofVMGuestLib_StatGet().
- replySize– the size that was supplied by thereplySizeparameter ofVMGuestLib_StatGet().
C code with StatGet and StatFree functions
shows these two function calls used in a sample routine:
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; }