diff options
Diffstat (limited to 'src/libs/zbxsysinfo/freebsd/memory.c')
-rw-r--r-- | src/libs/zbxsysinfo/freebsd/memory.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/libs/zbxsysinfo/freebsd/memory.c b/src/libs/zbxsysinfo/freebsd/memory.c index c73e8bb48f8..f76347bd1b5 100644 --- a/src/libs/zbxsysinfo/freebsd/memory.c +++ b/src/libs/zbxsysinfo/freebsd/memory.c @@ -19,14 +19,19 @@ #include "common.h" #include "sysinfo.h" +#include "log.h" static u_int pagesize = 0; -#define ZBX_SYSCTLBYNAME(name, value) \ - \ - len = sizeof(value); \ - if (0 != sysctlbyname(name, &value, &len, NULL, 0)) \ - return SYSINFO_RET_FAIL +#define ZBX_SYSCTLBYNAME(name, value) \ + \ + len = sizeof(value); \ + if (0 != sysctlbyname(name, &value, &len, NULL, 0)) \ + { \ + SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain \"%s\" system parameter: %s", \ + name, zbx_strerror(errno))); \ + return SYSINFO_RET_FAIL; \ + } static int VM_MEMORY_TOTAL(AGENT_RESULT *result) { @@ -126,7 +131,10 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result) 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, (activepages + wiredpages + cachedpages) / (double)totalpages * 100); @@ -159,7 +167,10 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result) 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); @@ -185,7 +196,10 @@ static int VM_MEMORY_SHARED(AGENT_RESULT *result) int mib[] = {CTL_VM, VM_METER}; if (0 != sysctl(mib, 2, &vm, &len, NULL, 0)) + { + SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; + } SET_UI64_RESULT(result, (zbx_uint64_t)(vm.t_vmshr + vm.t_rmshr) * pagesize); @@ -198,7 +212,10 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) int ret = SYSINFO_RET_FAIL; if (1 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } if (0 == pagesize) { @@ -234,7 +251,10 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(mode, "shared")) VM_MEMORY_SHARED(result); else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); ret = SYSINFO_RET_FAIL; + } return ret; } |