Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrejs Kozlovs <andrejs.kozlovs@zabbix.com>2020-01-17 16:42:55 +0300
committerAndrejs Kozlovs <andrejs.kozlovs@zabbix.com>2020-01-17 16:56:46 +0300
commit37fd7cf2aaad9a2ee5d1183fb2052f8bb29082e0 (patch)
tree2c6a4bda5f8d45e78da1b969faa6e533c6a926d6
parent829fd332ecb7dfa8a88336472b98ff784fbce477 (diff)
...G...... [ZBXNEXT-5490] added new JSON format for inodes
* commit 'ef3bc4c0c493b344f7178045cfe7d34e2b138f60': ...G...... [ZBXNEXT-5490] rename structure name ...G...... [ZBXNEXT-5490] correct typo in aix ...G...... [ZBXNEXT-5490] correct makefiles ...G...... [ZBXNEXT-5490] add include to inodes.h ...G...... [ZBXNEXT-5490] added new JSON format for inodes ...G...... [ZBXNEXT-5490] fixed typo for HPUX (cherry picked from commit b0707386bcbeef7882ed10847341fa998b0631c3) (cherry picked from commit b8027b543f75d02d2a6ea4cf32f71bad570a09b7)
-rw-r--r--include/sysinfo.h13
-rw-r--r--src/libs/zbxsysinfo/aix/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/aix/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/aix/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/aix/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/freebsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/hpux/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/hpux/diskspace.c46
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/linux/Makefile.am1
-rw-r--r--src/libs/zbxsysinfo/linux/diskspace.c43
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.c106
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/netbsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/openbsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/osx/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/osx/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.c78
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/solaris/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/solaris/diskspace.c44
-rw-r--r--src/libs/zbxsysinfo/solaris/inodes.c80
-rw-r--r--src/libs/zbxsysinfo/solaris/inodes.h25
-rw-r--r--src/libs/zbxsysinfo/win32/diskspace.c2
34 files changed, 870 insertions, 367 deletions
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 6a1fcdaedcb..0f970a7daa2 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -318,14 +318,21 @@ MODE_FUNCTION;
typedef struct
{
- char fsname[MAX_STRING_LEN];
- char fstype[MAX_STRING_LEN];
zbx_uint64_t total;
zbx_uint64_t not_used;
zbx_uint64_t used;
double pfree;
double pused;
}
+zbx_fs_metrics_t;
+
+typedef struct
+{
+ char fsname[MAX_STRING_LEN];
+ char fstype[MAX_STRING_LEN];
+ zbx_fs_metrics_t bytes;
+ zbx_fs_metrics_t inodes;
+}
zbx_mpoint_t;
#define ZBX_LLD_MACRO_FSNAME "{#FSNAME}"
@@ -335,6 +342,8 @@ zbx_mpoint_t;
#define ZBX_SYSINFO_TAG_FSNAME "fsname"
#define ZBX_SYSINFO_TAG_FSTYPE "fstype"
#define ZBX_SYSINFO_TAG_FSDRIVETYPE "fsdrivetype"
+#define ZBX_SYSINFO_TAG_BYTES "bytes"
+#define ZBX_SYSINFO_TAG_INODES "inodes"
#define ZBX_SYSINFO_TAG_TOTAL "total"
#define ZBX_SYSINFO_TAG_FREE "free"
#define ZBX_SYSINFO_TAG_USED "used"
diff --git a/src/libs/zbxsysinfo/aix/Makefile.am b/src/libs/zbxsysinfo/aix/Makefile.am
index 0ef5213bec4..d3eb37eccad 100644
--- a/src/libs/zbxsysinfo/aix/Makefile.am
+++ b/src/libs/zbxsysinfo/aix/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
cpu.c \
diskio.c \
diskspace.c \
- inodes.c \
+ inodes.c inodes.h \
memory.c \
net.c \
proc.c \
diff --git a/src/libs/zbxsysinfo/aix/diskspace.c b/src/libs/zbxsysinfo/aix/diskspace.c
index 7c5e288999b..8285e352cd4 100644
--- a/src/libs/zbxsysinfo/aix/diskspace.c
+++ b/src/libs/zbxsysinfo/aix/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -284,7 +285,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
struct vmount *vms = NULL, *vm;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -318,14 +321,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, zbx_get_vfs_name_by_type(vm->vmt_gfstype), MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
@@ -353,11 +368,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
diff --git a/src/libs/zbxsysinfo/aix/inodes.c b/src/libs/zbxsysinfo/aix/inodes.c
index a2916248eb3..d738a963aa1 100644
--- a/src/libs/zbxsysinfo/aix/inodes.c
+++ b/src/libs/zbxsysinfo/aix/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# ifdef HAVE_SYS_STATVFS64
@@ -38,10 +40,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# endif
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -57,54 +94,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/aix/inodes.h b/src/libs/zbxsysinfo/aix/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/aix/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/freebsd/Makefile.am b/src/libs/zbxsysinfo/freebsd/Makefile.am
index 168551a1b1a..7cb13e8a222 100644
--- a/src/libs/zbxsysinfo/freebsd/Makefile.am
+++ b/src/libs/zbxsysinfo/freebsd/Makefile.am
@@ -10,7 +10,7 @@ libspecsysinfo_a_SOURCES = \
diskio.c \
diskspace.c \
freebsd.c \
- inodes.c \
+ inodes.c inodes.h \
kernel.c \
memory.c \
net.c \
diff --git a/src/libs/zbxsysinfo/freebsd/diskspace.c b/src/libs/zbxsysinfo/freebsd/diskspace.c
index b7de4cdcb5c..859e7c0e681 100644
--- a/src/libs/zbxsysinfo/freebsd/diskspace.c
+++ b/src/libs/zbxsysinfo/freebsd/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -232,7 +233,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
struct statfs *mntbuf;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -255,14 +258,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mntbuf[i].f_fstypename, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -285,11 +300,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.c b/src/libs/zbxsysinfo/freebsd/inodes.c
index 9b3984dd6a4..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/freebsd/inodes.c
+++ b/src/libs/zbxsysinfo/freebsd/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,54 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.h b/src/libs/zbxsysinfo/freebsd/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/freebsd/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/hpux/Makefile.am b/src/libs/zbxsysinfo/hpux/Makefile.am
index 7f314be4ed4..d25fb54e380 100644
--- a/src/libs/zbxsysinfo/hpux/Makefile.am
+++ b/src/libs/zbxsysinfo/hpux/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
diskio.c \
diskspace.c \
hpux.c \
- inodes.c \
+ inodes.c inodes.h \
memory.c \
net.c \
proc.c \
diff --git a/src/libs/zbxsysinfo/hpux/diskspace.c b/src/libs/zbxsysinfo/hpux/diskspace.c
index 2912f3f8356..7d63689a41d 100644
--- a/src/libs/zbxsysinfo/hpux/diskspace.c
+++ b/src/libs/zbxsysinfo/hpux/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -236,7 +237,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
FILE *f;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -261,14 +264,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
- zbx_strlcpy(mntpoint->fstype, zmt->mnt_type, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ zbx_strlcpy(mntpoint->fstype, mt->mnt_type, MAX_STRING_LEN);
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -295,11 +310,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/hpux/inodes.c b/src/libs/zbxsysinfo/hpux/inodes.c
index 9b3984dd6a4..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/hpux/inodes.c
+++ b/src/libs/zbxsysinfo/hpux/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,54 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/hpux/inodes.h b/src/libs/zbxsysinfo/hpux/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/hpux/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/linux/Makefile.am b/src/libs/zbxsysinfo/linux/Makefile.am
index e3f124e742c..d4cad212187 100644
--- a/src/libs/zbxsysinfo/linux/Makefile.am
+++ b/src/libs/zbxsysinfo/linux/Makefile.am
@@ -12,6 +12,7 @@ libspecsysinfo_a_SOURCES = \
hardware.c \
hardware.h \
inodes.c \
+ inodes.h \
kernel.c \
linux.c \
memory.c \
diff --git a/src/libs/zbxsysinfo/linux/diskspace.c b/src/libs/zbxsysinfo/linux/diskspace.c
index a3e33458069..89e32c491cb 100644
--- a/src/libs/zbxsysinfo/linux/diskspace.c
+++ b/src/libs/zbxsysinfo/linux/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -183,7 +184,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
char line[MAX_STRING_LEN], *p, *mpoint, *mtype, *error;
FILE *f;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
struct zbx_json j;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -223,15 +226,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mtype, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -263,11 +277,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/linux/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c
index 557513af923..a7f04224612 100644
--- a/src/libs/zbxsysinfo/linux/inodes.c
+++ b/src/libs/zbxsysinfo/linux/inodes.c
@@ -20,23 +20,25 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
#define get_string(field) #field
-#define validate(result, structure, field) \
+#define validate(error, structure, field) \
\
do \
{ \
if (__UINT64_C(0xffffffffffffffff) == structure.field) \
{ \
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain filesystem information:" \
- " value of " get_string(field) " is unknown.")); \
+ error = zbx_strdup(NULL, "Cannot obtain filesystem information: value of " \
+ get_string(field) " is unknown."); \
return SYSINFO_RET_FAIL; \
} \
} \
while(0)
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -45,10 +47,51 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s", zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ validate(*error, s, f_files);
+ *itotal = (zbx_uint64_t)s.f_files;
+
+ validate(*error, s, ZBX_FFREE);
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+
+ validate(*error, s, f_ffree);
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ validate(*error, s, f_favail);
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = (100.0 * (total - s.ZBX_FFREE)) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -64,70 +107,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- validate(result, s, f_files);
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- validate(result, s, ZBX_FFREE);
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- validate(result, s, f_files);
- validate(result, s, f_ffree);
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- validate(result, s, f_files);
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- validate(result, s, f_ffree);
- validate(result, s, f_favail);
- total -= s.f_ffree - s.f_favail;
-#endif
- validate(result, s, ZBX_FFREE);
-
- if (0 != total)
- {
- SET_DBL_RESULT(result, (100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- validate(result, s, f_files);
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- validate(result, s, f_ffree);
- validate(result, s, f_favail);
- total -= s.f_ffree - s.f_favail;
-#endif
- validate(result, s, ZBX_FFREE);
-
- if (0 != total)
- {
- SET_DBL_RESULT(result, (100.0 * (total - s.ZBX_FFREE)) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/linux/inodes.h b/src/libs/zbxsysinfo/linux/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/linux/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/netbsd/Makefile.am b/src/libs/zbxsysinfo/netbsd/Makefile.am
index fa0eb1de131..770609d1356 100644
--- a/src/libs/zbxsysinfo/netbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/netbsd/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
cpu.c \
diskio.c \
diskspace.c \
- inodes.c \
+ inodes.c inodes.h \
kernel.c \
memory.c \
net.c \
diff --git a/src/libs/zbxsysinfo/netbsd/diskspace.c b/src/libs/zbxsysinfo/netbsd/diskspace.c
index 7803c91812e..86329a324bb 100644
--- a/src/libs/zbxsysinfo/netbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/netbsd/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -232,7 +233,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
struct statvfs *mntbuf;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -256,14 +259,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mntbuf[i].f_fstypename, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -286,11 +301,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.c b/src/libs/zbxsysinfo/netbsd/inodes.c
index 9b3984dd6a4..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/netbsd/inodes.c
+++ b/src/libs/zbxsysinfo/netbsd/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,54 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.h b/src/libs/zbxsysinfo/netbsd/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/netbsd/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/openbsd/Makefile.am b/src/libs/zbxsysinfo/openbsd/Makefile.am
index caf6e463d52..e9df7703311 100644
--- a/src/libs/zbxsysinfo/openbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/openbsd/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
cpu.c \
diskio.c \
diskspace.c \
- inodes.c \
+ inodes.c inodes.h \
kernel.c \
memory.c \
net.c \
diff --git a/src/libs/zbxsysinfo/openbsd/diskspace.c b/src/libs/zbxsysinfo/openbsd/diskspace.c
index b7de4cdcb5c..859e7c0e681 100644
--- a/src/libs/zbxsysinfo/openbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/openbsd/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -232,7 +233,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
struct statfs *mntbuf;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -255,14 +258,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mntbuf[i].f_fstypename, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -285,11 +300,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.c b/src/libs/zbxsysinfo/openbsd/inodes.c
index 9b3984dd6a4..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/openbsd/inodes.c
+++ b/src/libs/zbxsysinfo/openbsd/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,54 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.h b/src/libs/zbxsysinfo/openbsd/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/openbsd/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/osx/Makefile.am b/src/libs/zbxsysinfo/osx/Makefile.am
index 01ffeffccab..d19a785a021 100644
--- a/src/libs/zbxsysinfo/osx/Makefile.am
+++ b/src/libs/zbxsysinfo/osx/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
cpu.c \
diskio.c \
diskspace.c \
- inodes.c \
+ inodes.c inodes.h \
kernel.c \
memory.c \
net.c \
diff --git a/src/libs/zbxsysinfo/osx/diskspace.c b/src/libs/zbxsysinfo/osx/diskspace.c
index aec4735795b..cbe96d22da5 100644
--- a/src/libs/zbxsysinfo/osx/diskspace.c
+++ b/src/libs/zbxsysinfo/osx/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -232,7 +233,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
struct statfs *mntbuf;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -255,14 +258,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mntbuf[i].f_fstypename, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -285,11 +300,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/osx/inodes.c b/src/libs/zbxsysinfo/osx/inodes.c
index 9b3984dd6a4..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/osx/inodes.c
+++ b/src/libs/zbxsysinfo/osx/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,54 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/osx/inodes.h b/src/libs/zbxsysinfo/osx/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/osx/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/solaris/Makefile.am b/src/libs/zbxsysinfo/solaris/Makefile.am
index 40a454c0236..a2f8e6fe46b 100644
--- a/src/libs/zbxsysinfo/solaris/Makefile.am
+++ b/src/libs/zbxsysinfo/solaris/Makefile.am
@@ -9,7 +9,7 @@ libspecsysinfo_a_SOURCES = \
cpu.c \
diskio.c \
diskspace.c \
- inodes.c \
+ inodes.c inodes.h \
kernel.c \
memory.c \
net.c \
diff --git a/src/libs/zbxsysinfo/solaris/diskspace.c b/src/libs/zbxsysinfo/solaris/diskspace.c
index cc51d4ab96f..669f77ccf02 100644
--- a/src/libs/zbxsysinfo/solaris/diskspace.c
+++ b/src/libs/zbxsysinfo/solaris/diskspace.c
@@ -22,6 +22,7 @@
#include "zbxjson.h"
#include "log.h"
#include "zbxalgo.h"
+#include "inodes.h"
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
@@ -240,7 +241,9 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
FILE *f;
struct zbx_json j;
zbx_uint64_t total, not_used, used;
+ zbx_uint64_t itotal, inot_used, iused;
double pfree, pused;
+ double ipfree, ipused;
char *error;
zbx_vector_ptr_t mntpoints;
zbx_mpoint_t *mntpoint;
@@ -265,14 +268,26 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_free(error);
continue;
}
+ if (SYSINFO_RET_OK != get_fs_inode_stat(mpoint, &itotal, &inot_used, &iused, &ipfree, &ipused, "pused",
+ &error))
+ {
+ zbx_free(error);
+ continue;
+ }
+
mntpoint = (zbx_mpoint_t *)zbx_malloc(NULL, sizeof(zbx_mpoint_t));
zbx_strlcpy(mntpoint->fsname, mpoint, MAX_STRING_LEN);
zbx_strlcpy(mntpoint->fstype, mt.mnt_fstype, MAX_STRING_LEN);
- mntpoint->total = total;
- mntpoint->used = used;
- mntpoint->not_used = not_used;
- mntpoint->pfree = pfree;
- mntpoint->pused = pused;
+ mntpoint->bytes.total = total;
+ mntpoint->bytes.used = used;
+ mntpoint->bytes.not_used = not_used;
+ mntpoint->bytes.pfree = pfree;
+ mntpoint->bytes.pused = pused;
+ mntpoint->inodes.total = itotal;
+ mntpoint->inodes.used = iused;
+ mntpoint->inodes.not_used = inot_used;
+ mntpoint->inodes.pfree = ipfree;
+ mntpoint->inodes.pused = ipused;
zbx_vector_ptr_append(&mntpoints, mntpoint);
}
@@ -298,11 +313,20 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_json_addobject(&j, NULL);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mntpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mntpoint->fstype, ZBX_JSON_TYPE_STRING);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->total);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->not_used);
- zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->used);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->pfree);
- zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->pused);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->bytes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->bytes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->bytes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->bytes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->bytes.pused);
+ zbx_json_close(&j);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_INODES);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mntpoint->inodes.total);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mntpoint->inodes.not_used);
+ zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mntpoint->inodes.used);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mntpoint->inodes.pfree);
+ zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mntpoint->inodes.pused);
+ zbx_json_close(&j);
zbx_json_close(&j);
}
}
diff --git a/src/libs/zbxsysinfo/solaris/inodes.c b/src/libs/zbxsysinfo/solaris/inodes.c
index ac884176183..2c64a83492b 100644
--- a/src/libs/zbxsysinfo/solaris/inodes.c
+++ b/src/libs/zbxsysinfo/solaris/inodes.c
@@ -20,8 +20,10 @@
#include "common.h"
#include "sysinfo.h"
#include "log.h"
+#include "inodes.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -30,10 +32,45 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
# define ZBX_STATFS statfs
# define ZBX_FFREE f_ffree
#endif
- char *fsname, *mode;
zbx_uint64_t total;
struct ZBX_STATFS s;
+ if (0 != ZBX_STATFS(fs, &s))
+ {
+ *error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
+ zbx_strerror(errno));
+ return SYSINFO_RET_FAIL;
+ }
+
+ *itotal = (zbx_uint64_t)s.f_files;
+ *ifree = (zbx_uint64_t)s.ZBX_FFREE;
+ *iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
+ total = s.f_files;
+#ifdef HAVE_SYS_STATVFS_H
+ total -= s.f_ffree - s.f_favail;
+#endif
+ if (0 != total)
+ {
+ *pfree = (100.0 * s.ZBX_FFREE) / total;
+ *pused = 100.0 - (double)(100.0 * s.ZBX_FFREE) / total;
+ }
+ else
+ {
+ if (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused"))
+ {
+ *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ return SYSINFO_RET_OK;
+}
+
+static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ char *fsname, *mode, *error;
+ zbx_uint64_t total, free, used;
+ double pfree, pused;
+
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
@@ -49,56 +86,31 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (0 != ZBX_STATFS(fsname, &s))
+ if (SYSINFO_RET_OK != get_fs_inode_stat(fsname, &total, &free, &used, &pfree, &pused, mode, &error))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
- zbx_strerror(errno)));
+ SET_MSG_RESULT(result, error);
return SYSINFO_RET_FAIL;
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
{
- SET_UI64_RESULT(result, s.f_files);
+ SET_UI64_RESULT(result, total);
}
else if (0 == strcmp(mode, "free"))
{
- SET_UI64_RESULT(result, s.ZBX_FFREE);
+ SET_UI64_RESULT(result, free);
}
else if (0 == strcmp(mode, "used"))
{
- SET_UI64_RESULT(result, s.f_files - s.f_ffree);
+ SET_UI64_RESULT(result, used);
}
else if (0 == strcmp(mode, "pfree"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pfree);
}
else if (0 == strcmp(mode, "pused"))
{
- total = s.f_files;
-#ifdef HAVE_SYS_STATVFS_H
- total -= s.f_ffree - s.f_favail;
-#endif
- if (0 != total)
- {
- SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total);
- }
- else
- {
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot calculate percentage because total is zero."));
- return SYSINFO_RET_FAIL;
- }
+ SET_DBL_RESULT(result, pused);
}
else
{
diff --git a/src/libs/zbxsysinfo/solaris/inodes.h b/src/libs/zbxsysinfo/solaris/inodes.h
new file mode 100644
index 00000000000..df1415d2fa6
--- /dev/null
+++ b/src/libs/zbxsysinfo/solaris/inodes.h
@@ -0,0 +1,25 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 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.
+**/
+
+#ifndef ZABBIX_INODES_H
+#define ZABBIX_INODES_H
+
+int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree, zbx_uint64_t *iused, double *pfree,
+ double *pused, const char *mode, char **error);
+#endif
diff --git a/src/libs/zbxsysinfo/win32/diskspace.c b/src/libs/zbxsysinfo/win32/diskspace.c
index 68bac1cacd3..c7188394e62 100644
--- a/src/libs/zbxsysinfo/win32/diskspace.c
+++ b/src/libs/zbxsysinfo/win32/diskspace.c
@@ -422,12 +422,14 @@ static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE time
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSNAME, mpoint->fsname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSTYPE, mpoint->fstype, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_SYSINFO_TAG_FSDRIVETYPE, mpoint->fsdrivetype, ZBX_JSON_TYPE_STRING);
+ zbx_json_addobject(&j, ZBX_SYSINFO_TAG_BYTES);
zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_TOTAL, mpoint->total);
zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_FREE, mpoint->not_used);
zbx_json_adduint64(&j, ZBX_SYSINFO_TAG_USED, mpoint->used);
zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PFREE, mpoint->pfree);
zbx_json_addfloat(&j, ZBX_SYSINFO_TAG_PUSED, mpoint->pused);
zbx_json_close(&j);
+ zbx_json_close(&j);
}
zbx_free(mpoint_local.fsname);
}