static int VM_MEMORY_TOTAL(AGENT_RESULT *result) { unsigned long totalbytes; size_t len; ZBX_SYSCTLBYNAME("hw.physmem", totalbytes); SET_UI64_RESULT(result, (zbx_uint64_t)totalbytes); return SYSINFO_RET_OK; }
static int VM_MEMORY_BUFFERS(AGENT_RESULT *result) { u_int bufspace; size_t len; ZBX_SYSCTLBYNAME("vfs.bufspace", bufspace); SET_UI64_RESULT(result, bufspace); return SYSINFO_RET_OK; }
static int VM_MEMORY_FREE(AGENT_RESULT *result) { u_int freepages; size_t len; ZBX_SYSCTLBYNAME("vm.stats.vm.v_free_count", freepages); SET_UI64_RESULT(result, (zbx_uint64_t)freepages * pagesize); return SYSINFO_RET_OK; }
static int VM_MEMORY_CACHED(AGENT_RESULT *result) { u_int cachedpages; size_t len; ZBX_SYSCTLBYNAME("vm.stats.vm.v_cache_count", cachedpages); SET_UI64_RESULT(result, (zbx_uint64_t)cachedpages * pagesize); return SYSINFO_RET_OK; }
static int VM_MEMORY_INACTIVE(AGENT_RESULT *result) { u_int inactivepages; size_t len; ZBX_SYSCTLBYNAME("vm.stats.vm.v_inactive_count", inactivepages); SET_UI64_RESULT(result, (zbx_uint64_t)inactivepages * pagesize); return SYSINFO_RET_OK; }
static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result) { u_int inactivepages, cachedpages, freepages, totalpages; size_t len; ZBX_SYSCTLBYNAME("vm.stats.vm.v_inactive_count", inactivepages); ZBX_SYSCTLBYNAME("vm.stats.vm.v_cache_count", cachedpages); ZBX_SYSCTLBYNAME("vm.stats.vm.v_free_count", freepages); ZBX_SYSCTLBYNAME("vm.stats.vm.v_page_count", totalpages); if (0 == totalpages) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero.")); return SYSINFO_RET_FAIL; } SET_DBL_RESULT(result, (inactivepages + cachedpages + freepages) / (double)totalpages * 100); return SYSINFO_RET_OK; }
int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { char *mode; int ret; if (1 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; } if (0 == pagesize) { size_t len; ZBX_SYSCTLBYNAME("vm.stats.vm.v_page_size", pagesize); } mode = get_rparam(request, 0); if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) ret = VM_MEMORY_TOTAL(result); else if (0 == strcmp(mode, "active")) ret = VM_MEMORY_ACTIVE(result); else if (0 == strcmp(mode, "inactive")) ret = VM_MEMORY_INACTIVE(result); else if (0 == strcmp(mode, "wired")) ret = VM_MEMORY_WIRED(result); else if (0 == strcmp(mode, "cached")) ret = VM_MEMORY_CACHED(result); else if (0 == strcmp(mode, "free")) ret = VM_MEMORY_FREE(result); else if (0 == strcmp(mode, "used")) ret = VM_MEMORY_USED(result); else if (0 == strcmp(mode, "pused")) ret = VM_MEMORY_PUSED(result); else if (0 == strcmp(mode, "available")) ret = VM_MEMORY_AVAILABLE(result); else if (0 == strcmp(mode, "pavailable")) ret = VM_MEMORY_PAVAILABLE(result); else if (0 == strcmp(mode, "buffers")) ret = VM_MEMORY_BUFFERS(result); else if (0 == strcmp(mode, "shared")) ret = VM_MEMORY_SHARED(result); else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); ret = SYSINFO_RET_FAIL; } return ret; }