#include "common.h"
#include "sysinfo.h"
#include "log.h"
#include <uvm/uvm_extern.h>
static int mib[] = {CTL_VM, VM_UVMEXP2};
static size_t len;
static struct uvmexp_sysctl uvm;
#define ZBX_SYSCTL(value) \
\
len = sizeof(value); \
if (0 != sysctl(mib, 2, &value, &len, NULL, 0)) \
{ \
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", \
zbx_strerror(errno))); \
return SYSINFO_RET_FAIL; \
}
static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.npages << uvm.pageshift);
return SYSINFO_RET_OK;
}
static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.active << uvm.pageshift);
return SYSINFO_RET_OK;
}
static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.inactive << uvm.pageshift);
return SYSINFO_RET_OK;
}
static int VM_MEMORY_WIRED(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.wired << uvm.pageshift);
return SYSINFO_RET_OK;
}
static int VM_MEMORY_ANON(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.anonpages << uvm.pageshift);
return SYSINFO_RET_OK;
}
static int VM_MEMORY_EXEC(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
SET_UI64_RESULT(result, uvm.execpages << uvm.pageshift);
return SYSINFO_RET_OK;