Source
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
static int get_swap_size(zbx_uint64_t *total, zbx_uint64_t *free, zbx_uint64_t *used, double *pfree, double *pused,
char **error)
{
int mib[2];
size_t len;
struct uvmexp v;
mib[0] = CTL_VM;
mib[1] = VM_UVMEXP;
len = sizeof(v);
if (0 != sysctl(mib, 2, &v, &len, NULL, 0))
{
*error = zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno));
return SYSINFO_RET_FAIL;
}
/* int pagesize; size of a page (PAGE_SIZE): must be power of 2 */
/* int swpages; number of PAGE_SIZE'ed swap pages */
/* int swpginuse; number of swap pages in use */
if (NULL != total)
*total = (zbx_uint64_t)v.swpages * v.pagesize;
if (NULL != free)
*free = (zbx_uint64_t)(v.swpages - v.swpginuse) * v.pagesize;
if (NULL != used)
*used = (zbx_uint64_t)v.swpginuse * v.pagesize;
if (NULL != pfree)
*pfree = 0 != v.swpages ? (double)(100.0 * (v.swpages - v.swpginuse)) / v.swpages : 100;
if (NULL != pused)
*pused = 0 != v.swpages ? (double)(100.0 * v.swpginuse) / v.swpages : 0;
return SYSINFO_RET_OK;
}
static int SYSTEM_SWAP_TOTAL(AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;