Source
SET_MSG_RESULT(result, zbx_strdup(NULL, "This item is available only in daemon mode when collectors are"
/*
** 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 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/>.
**/
static struct statinfo *si = NULL;
int zbx_get_diskstat(const char *devname, zbx_uint64_t *dstat)
{
struct devstat *ds = NULL;
int ret = FAIL;
char dev[DEVSTAT_NAME_LEN + 10];
const char *pd; /* pointer to device name without '/dev/' prefix, e.g. 'da0' */
assert(devname);
for (int i = 0; i < ZBX_DSTAT_MAX; i++)
dstat[i] = (zbx_uint64_t)__UINT64_C(0);
if (NULL == si)
{
si = (struct statinfo *)zbx_malloc(si, sizeof(struct statinfo));
si->dinfo = (struct devinfo *)zbx_malloc(NULL, sizeof(struct devinfo));
memset(si->dinfo, 0, sizeof(struct devinfo));
}
pd = devname;
/* skip prefix ZBX_DEV_PFX, if present */
if ('\0' != *devname && 0 == strncmp(pd, ZBX_DEV_PFX, ZBX_CONST_STRLEN(ZBX_DEV_PFX)))
pd += ZBX_CONST_STRLEN(ZBX_DEV_PFX);
if (-1 == devstat_getdevs(NULL, si))
if (-1 == getdevs(si))
return FAIL;
for (int i = 0; i < si->dinfo->numdevs; i++)
{
ds = &si->dinfo->devices[i];