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:
authorAleksejs Sestakovs <aleksejs.sestakovs@zabbix.com>2022-11-09 12:11:53 +0300
committerAleksejs Sestakovs <aleksejs.sestakovs@zabbix.com>2022-11-09 12:24:48 +0300
commitd2f12c70dfbd1dc1f3a9c8799f61a083103718be (patch)
tree34002ba25b86638c6f7a9434a17ed4cb2c26bf97
parent651b2dde2f96b14b78079b84ad24ab452c8a90e9 (diff)
...G...... [ZBX-21823] fixed vfs.fs.inode and vfs.fs.get to handle file systems with zero total inodes count
* commit '6a8963b239523b89b0c8b01e8f418c4497dbf4d3': ...G...... [ZBX-21823] fixed agent2 vfs.fs.size to correspond to agentd .D........ [ZBX-21823] added changelog ...G...... [ZBX-21823] fixed vfs.fs.get to include file systems with zero inodes count; fixed vfs.fs.inode[,pfree/pused] to not become not supported if inodes total count is zero (cherry picked from commit 32f78a0c1b1e39814cc83962d81d86a061272438) (cherry picked from commit b1d418bf3a2934e4c45ba949c1c9d4356286df7e) (cherry picked from commit 46ec18edcc541f1e2b2d35ee1d62d78754a1bc6e)
-rw-r--r--ChangeLog.d/bugfix/ZBX-218231
-rw-r--r--src/go/plugins/vfs/fs/fs_nix.go34
-rw-r--r--src/libs/zbxsysinfo/aix/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.c5
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/osf/inodes.c18
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.c4
-rw-r--r--src/libs/zbxsysinfo/solaris/inodes.c4
11 files changed, 47 insertions, 39 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-21823 b/ChangeLog.d/bugfix/ZBX-21823
new file mode 100644
index 00000000000..d62c47a2281
--- /dev/null
+++ b/ChangeLog.d/bugfix/ZBX-21823
@@ -0,0 +1 @@
+...G...... [ZBX-21823] fixed vfs.fs.inode and vfs.fs.get to handle file systems with zero total inodes count (asestakovs)
diff --git a/src/go/plugins/vfs/fs/fs_nix.go b/src/go/plugins/vfs/fs/fs_nix.go
index fcdc1fa984a..28631b42a2a 100644
--- a/src/go/plugins/vfs/fs/fs_nix.go
+++ b/src/go/plugins/vfs/fs/fs_nix.go
@@ -55,9 +55,7 @@ func (p *Plugin) getFsInfoStats() (data []*FsInfoNew, err error) {
continue
}
- if bytes.Total > 0 && inodes.Total > 0 {
- fsmap[*info.FsName] = &FsInfoNew{info.FsName, info.FsType, nil, nil, bytes, inodes, info.FsOptions}
- }
+ fsmap[*info.FsName] = &FsInfoNew{info.FsName, info.FsType, nil, nil, bytes, inodes, info.FsOptions}
}
allData, err = p.getFsInfo()
@@ -109,6 +107,8 @@ func (p *Plugin) getFsInfo() (data []*FsInfo, err error) {
}
func getFsStats(path string) (stats *FsStats, err error) {
+ var pused float64
+
fs := unix.Statfs_t{}
err = unix.Statfs(path, &fs)
if err != nil {
@@ -123,19 +123,30 @@ func getFsStats(path string) (stats *FsStats, err error) {
total := fs.Blocks * uint64(fs.Bsize)
free := available * uint64(fs.Bsize)
used := (fs.Blocks - fs.Bfree) * uint64(fs.Bsize)
- pfree := 100.00 * float64(available) / float64(fs.Blocks-fs.Bfree+fs.Bavail)
+ pfree := float64(fs.Blocks-fs.Bfree+fs.Bavail)
+
+ if pfree > 0 {
+ pfree = 100.00 * float64(available) / pfree
+ pused = 100 - pfree
+ } else {
+ pfree = 0
+ pused = 0
+ }
+
stats = &FsStats{
Total: total,
Free: free,
Used: used,
PFree: pfree,
- PUsed: 100 - pfree,
+ PUsed: pused,
}
return
}
func getFsInode(path string) (stats *FsStats, err error) {
+ var pfree, pused float64
+
fs := unix.Statfs_t{}
err = unix.Statfs(path, &fs)
if err != nil {
@@ -145,12 +156,21 @@ func getFsInode(path string) (stats *FsStats, err error) {
total := fs.Files
free := fs.Ffree
used := fs.Files - fs.Ffree
+
+ if 0 < total {
+ pfree = 100 * float64(free) / float64(total)
+ pused = 100 * float64(total-free) / float64(total)
+ } else {
+ pfree = 100.0
+ pused = 0.0
+ }
+
stats = &FsStats{
Total: total,
Free: free,
Used: used,
- PFree: 100 * float64(free) / float64(total),
- PUsed: 100 * float64(total-free) / float64(total),
+ PFree: pfree,
+ PUsed: pused,
}
return
diff --git a/src/libs/zbxsysinfo/aix/inodes.c b/src/libs/zbxsysinfo/aix/inodes.c
index 46b4801e2bd..77e631060bc 100644
--- a/src/libs/zbxsysinfo/aix/inodes.c
+++ b/src/libs/zbxsysinfo/aix/inodes.c
@@ -65,8 +65,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.c b/src/libs/zbxsysinfo/freebsd/inodes.c
index 6824e7f5e5c..697e50e5155 100644
--- a/src/libs/zbxsysinfo/freebsd/inodes.c
+++ b/src/libs/zbxsysinfo/freebsd/inodes.c
@@ -57,8 +57,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/hpux/inodes.c b/src/libs/zbxsysinfo/hpux/inodes.c
index 01e4358b196..509fee26cba 100644
--- a/src/libs/zbxsysinfo/hpux/inodes.c
+++ b/src/libs/zbxsysinfo/hpux/inodes.c
@@ -57,8 +57,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/linux/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c
index 0ea0c231ed9..c29da19eae1 100644
--- a/src/libs/zbxsysinfo/linux/inodes.c
+++ b/src/libs/zbxsysinfo/linux/inodes.c
@@ -77,9 +77,10 @@ while(0)
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
+
return SYSINFO_RET_OK;
#undef ZBX_STATFS
#undef ZBX_FFREE
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.c b/src/libs/zbxsysinfo/netbsd/inodes.c
index 01e4358b196..509fee26cba 100644
--- a/src/libs/zbxsysinfo/netbsd/inodes.c
+++ b/src/libs/zbxsysinfo/netbsd/inodes.c
@@ -57,8 +57,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.c b/src/libs/zbxsysinfo/openbsd/inodes.c
index 01e4358b196..509fee26cba 100644
--- a/src/libs/zbxsysinfo/openbsd/inodes.c
+++ b/src/libs/zbxsysinfo/openbsd/inodes.c
@@ -57,8 +57,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/osf/inodes.c b/src/libs/zbxsysinfo/osf/inodes.c
index 81c236c737c..51513fd9bf5 100644
--- a/src/libs/zbxsysinfo/osf/inodes.c
+++ b/src/libs/zbxsysinfo/osf/inodes.c
@@ -75,13 +75,7 @@ static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
#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, 0 != total ? (double)(100.0 * s.ZBX_FFREE) / total : 100.0);
}
else if (0 == strcmp(mode, "pused"))
{
@@ -89,15 +83,7 @@ static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
#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, 0 != total ? 100.0 - (double)(100.0 * s.ZBX_FFREE) / total : 0.0);
}
else
{
diff --git a/src/libs/zbxsysinfo/osx/inodes.c b/src/libs/zbxsysinfo/osx/inodes.c
index 8bd59aeb155..cd257f83da3 100644
--- a/src/libs/zbxsysinfo/osx/inodes.c
+++ b/src/libs/zbxsysinfo/osx/inodes.c
@@ -57,8 +57,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;
diff --git a/src/libs/zbxsysinfo/solaris/inodes.c b/src/libs/zbxsysinfo/solaris/inodes.c
index 5c7cc6bac73..317934e5ae5 100644
--- a/src/libs/zbxsysinfo/solaris/inodes.c
+++ b/src/libs/zbxsysinfo/solaris/inodes.c
@@ -56,8 +56,8 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
}
else if (NULL != mode && (0 == strcmp(mode, "pfree") || 0 == strcmp(mode, "pused")))
{
- *error = zbx_strdup(NULL, "Cannot calculate percentage because total is zero.");
- return SYSINFO_RET_FAIL;
+ *pfree = 100.0;
+ *pused = 0.0;
}
return SYSINFO_RET_OK;