#include "zbxsysinfo.h"
#include "../sysinfo.h"
#include "zbxstr.h"
#include "zbxthreads.h"
#include "zbxjson.h"
#include "zbxalgo.h"
#include "perfstat/perfstat.h"
int user_perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char *counter, *error = NULL;
double value;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
if (1 != request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
goto out;
}
if (NULL == (counter = get_rparam(request, 0)) || '\0' == *counter)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
goto out;
}
if (SUCCEED != get_perf_counter_value_by_name(counter, &value, &error))
{
SET_MSG_RESULT(result, error != NULL ? error :
zbx_strdup(NULL, "Cannot obtain performance information from collector."));
goto out;
}
SET_DBL_RESULT(result, value);
ret = SYSINFO_RET_OK;
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
return ret;
}
static int perf_counter_ex(const char *function, AGENT_REQUEST *request, AGENT_RESULT *result,
zbx_perf_counter_lang_t lang)
{
char counterpath[PDH_MAX_COUNTER_PATH], *tmp, *error = NULL;
int interval, ret = SYSINFO_RET_FAIL;
double value;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", function);
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
goto out;
}
tmp = get_rparam(request, 0);
if (NULL == tmp || '\0' == *tmp)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
goto out;
}
zbx_strscpy(counterpath, tmp);
if (NULL == (tmp = get_rparam(request, 1)) || '\0' == *tmp)
{
interval = 1;
}
else if (FAIL == zbx_is_uint31(tmp, &interval))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));