Source
/* Example of XINTFRAC = 125.000000 / 64.000000 = 1.953125. Apparently XINTFRAC is a period (in nanoseconds) */
/*
** Copyright (C) 2001-2024 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
int system_stat(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *section, *type;
/* maximum seconds to wait for vmstat data on the first call */
int wait = ZBX_MAX_WAIT_VMSTAT;
zbx_collector_data *collector = get_collector();
if (!VMSTAT_COLLECTOR_STARTED(collector))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Collector is not started."));
return SYSINFO_RET_FAIL;
}
/* if vmstat data is not available yet wait for collector to gather it */
if (0 == collector->vmstat.data_available)
{
collector->vmstat.enabled = 1;
while (wait--)
{
zbx_sleep(1);
if (1 == collector->vmstat.data_available)
break;
}
if (0 == collector->vmstat.data_available)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "No data available in collector."));
return SYSINFO_RET_FAIL;
}
}
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
}
section = get_rparam(request, 0);
type = get_rparam(request, 1);
if (NULL == section)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));