#include "common.h"
#include "sysinfo.h"
#include "stats.h"
#include "log.h"
int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int name;
long ncpu;
if (1 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
}
tmp = get_rparam(request, 0);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "online"))
name = _SC_NPROCESSORS_ONLN;
else if (0 == strcmp(tmp, "max"))
name = _SC_NPROCESSORS_CONF;
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
}
if (-1 == (ncpu = sysconf(name)))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain number of CPUs."));
return SYSINFO_RET_FAIL;
}
SET_UI64_RESULT(result, ncpu);
return SYSINFO_RET_OK;
}
int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
if (3 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
}
tmp = get_rparam(request, 0);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "all"))
cpu_num = ZBX_CPUNUM_ALL;
else if (SUCCEED != is_uint31_1(tmp, &cpu_num))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
}
tmp = get_rparam(request, 1);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "user"))
state = ZBX_CPU_STATE_USER;
else if (0 == strcmp(tmp, "iowait"))
state = ZBX_CPU_STATE_IOWAIT;
else if (0 == strcmp(tmp, "system"))
state = ZBX_CPU_STATE_SYSTEM;
else if (0 == strcmp(tmp, "idle"))
state = ZBX_CPU_STATE_IDLE;
else