#include "zbxsysinfo.h"
#include "../sysinfo.h"
#include "../common/stats.h"
#include "zbxnum.h"
#include <sys/dr.h>
int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
char *tmp;
lpar_info_format2_t buf;
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"))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
}
if (0 != lpar_get_info(LPAR_INFO_FORMAT2, &buf, sizeof(buf)))
{
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
SET_UI64_RESULT(result, buf.online_lcpus);
return SYSINFO_RET_OK;
#else
SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for Perfstat API."));
return SYSINFO_RET_FAIL;
#endif
}
int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode, res;
if (4 < 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 != zbx_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, "system"))
state = ZBX_CPU_STATE_SYSTEM;
else if (0 == strcmp(tmp, "idle"))
state = ZBX_CPU_STATE_IDLE;
else if (0 == strcmp(tmp, "iowait"))
state = ZBX_CPU_STATE_IOWAIT;