fix(inputs.disk): Add inodes_used_percent field (#14267)
This commit is contained in:
parent
0d106d5822
commit
dce3bbd679
|
|
@ -63,6 +63,7 @@ docker run -v /:/hostfs:ro -e HOST_MOUNT_PREFIX=/hostfs -e HOST_PROC=/hostfs/pro
|
||||||
- inodes_free (integer, files)
|
- inodes_free (integer, files)
|
||||||
- inodes_total (integer, files)
|
- inodes_total (integer, files)
|
||||||
- inodes_used (integer, files)
|
- inodes_used (integer, files)
|
||||||
|
- inodes_used_percent (float, percent)
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
|
@ -85,11 +86,11 @@ sudo setfacl -R -m u:telegraf:X /var/lib/docker/volumes/
|
||||||
## Example Output
|
## Example Output
|
||||||
|
|
||||||
```text
|
```text
|
||||||
disk,fstype=hfs,mode=ro,path=/ free=398407520256i,inodes_free=97267461i,inodes_total=121847806i,inodes_used=24580345i,total=499088621568i,used=100418957312i,used_percent=20.131039916242397 1453832006274071563
|
disk,fstype=hfs,mode=ro,path=/ free=398407520256i,inodes_free=97267461i,inodes_total=121847806i,inodes_used=24580345i,total=499088621568i,used=100418957312i,used_percent=20.131039916242397,inodes_used_percent=20.1729894 1453832006274071563
|
||||||
disk,fstype=devfs,mode=rw,path=/dev free=0i,inodes_free=0i,inodes_total=628i,inodes_used=628i,total=185856i,used=185856i,used_percent=100 1453832006274137913
|
disk,fstype=devfs,mode=rw,path=/dev free=0i,inodes_free=0i,inodes_total=628i,inodes_used=628i,total=185856i,used=185856i,used_percent=100,inodes_used_percent=100 1453832006274137913
|
||||||
disk,fstype=autofs,mode=rw,path=/net free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274157077
|
disk,fstype=autofs,mode=rw,path=/net free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0,inodes_used_percent=0 1453832006274157077
|
||||||
disk,fstype=autofs,mode=rw,path=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274169688
|
disk,fstype=autofs,mode=rw,path=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0,inodes_used_percent=0 1453832006274169688
|
||||||
disk,device=dm-1,fstype=xfs,label=lvg-lv,mode=rw,path=/mnt inodes_free=8388605i,inodes_used=3i,total=17112760320i,free=16959598592i,used=153161728i,used_percent=0.8950147441789215,inodes_total=8388608i 1677001387000000000
|
disk,device=dm-1,fstype=xfs,label=lvg-lv,mode=rw,path=/mnt inodes_free=8388605i,inodes_used=3i,total=17112760320i,free=16959598592i,used=153161728i,used_percent=0.8950147441789215,inodes_total=8388608i,inodes_used_percent=0.0017530778 1677001387000000000
|
||||||
```
|
```
|
||||||
|
|
||||||
[statfs]: http://man7.org/linux/man-pages/man2/statfs.2.html
|
[statfs]: http://man7.org/linux/man-pages/man2/statfs.2.html
|
||||||
|
|
|
||||||
|
|
@ -75,14 +75,21 @@ func (ds *DiskStats) Gather(acc telegraf.Accumulator) error {
|
||||||
(float64(du.Used) + float64(du.Free)) * 100
|
(float64(du.Used) + float64(du.Free)) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inodesUsedPercent float64
|
||||||
|
if du.InodesUsed+du.InodesFree > 0 {
|
||||||
|
inodesUsedPercent = float64(du.InodesUsed) /
|
||||||
|
(float64(du.InodesUsed) + float64(du.InodesFree)) * 100
|
||||||
|
}
|
||||||
|
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"total": du.Total,
|
"total": du.Total,
|
||||||
"free": du.Free,
|
"free": du.Free,
|
||||||
"used": du.Used,
|
"used": du.Used,
|
||||||
"used_percent": usedPercent,
|
"used_percent": usedPercent,
|
||||||
"inodes_total": du.InodesTotal,
|
"inodes_total": du.InodesTotal,
|
||||||
"inodes_free": du.InodesFree,
|
"inodes_free": du.InodesFree,
|
||||||
"inodes_used": du.InodesUsed,
|
"inodes_used": du.InodesUsed,
|
||||||
|
"inodes_used_percent": inodesUsedPercent,
|
||||||
}
|
}
|
||||||
acc.AddGauge("disk", fields, tags)
|
acc.AddGauge("disk", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func TestDiskUsage(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
numDiskMetrics := acc.NFields()
|
numDiskMetrics := acc.NFields()
|
||||||
expectedAllDiskMetrics := 21
|
expectedAllDiskMetrics := 24
|
||||||
require.Equal(t, expectedAllDiskMetrics, numDiskMetrics)
|
require.Equal(t, expectedAllDiskMetrics, numDiskMetrics)
|
||||||
|
|
||||||
tags1 := map[string]string{
|
tags1 := map[string]string{
|
||||||
|
|
@ -116,31 +116,34 @@ func TestDiskUsage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fields1 := map[string]interface{}{
|
fields1 := map[string]interface{}{
|
||||||
"total": uint64(128),
|
"total": uint64(128),
|
||||||
"used": uint64(100),
|
"used": uint64(100),
|
||||||
"free": uint64(23),
|
"free": uint64(23),
|
||||||
"inodes_total": uint64(1234),
|
"inodes_total": uint64(1234),
|
||||||
"inodes_free": uint64(234),
|
"inodes_free": uint64(234),
|
||||||
"inodes_used": uint64(1000),
|
"inodes_used": uint64(1000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
}
|
}
|
||||||
fields2 := map[string]interface{}{
|
fields2 := map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
}
|
}
|
||||||
fields3 := map[string]interface{}{
|
fields3 := map[string]interface{}{
|
||||||
"total": uint64(128),
|
"total": uint64(128),
|
||||||
"used": uint64(100),
|
"used": uint64(100),
|
||||||
"free": uint64(23),
|
"free": uint64(23),
|
||||||
"inodes_total": uint64(1234),
|
"inodes_total": uint64(1234),
|
||||||
"inodes_free": uint64(234),
|
"inodes_free": uint64(234),
|
||||||
"inodes_used": uint64(1000),
|
"inodes_used": uint64(1000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "disk", fields1, tags1)
|
acc.AssertContainsTaggedFields(t, "disk", fields1, tags1)
|
||||||
acc.AssertContainsTaggedFields(t, "disk", fields2, tags2)
|
acc.AssertContainsTaggedFields(t, "disk", fields2, tags2)
|
||||||
|
|
@ -150,18 +153,18 @@ func TestDiskUsage(t *testing.T) {
|
||||||
// and /home not matching the /dev in MountPoints
|
// and /home not matching the /dev in MountPoints
|
||||||
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/dev"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/dev"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8, acc.NFields())
|
||||||
|
|
||||||
// We should see all the diskpoints as MountPoints includes both
|
// We should see all the diskpoints as MountPoints includes both
|
||||||
// /, /home, and /var/rootbind
|
// /, /home, and /var/rootbind
|
||||||
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/home", "/var/rootbind"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/home", "/var/rootbind"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7*4, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8*4, acc.NFields())
|
||||||
|
|
||||||
// We should see all the mounts as MountPoints except the bind mound
|
// We should see all the mounts as MountPoints except the bind mound
|
||||||
err = (&DiskStats{ps: &mps, IgnoreMountOpts: []string{"bind"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, IgnoreMountOpts: []string{"bind"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7*6, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8*6, acc.NFields())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiskUsageHostMountPrefix(t *testing.T) {
|
func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
|
|
@ -196,13 +199,14 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
"mode": "ro",
|
"mode": "ro",
|
||||||
},
|
},
|
||||||
expectedFields: map[string]interface{}{
|
expectedFields: map[string]interface{}{
|
||||||
"total": uint64(42),
|
"total": uint64(42),
|
||||||
"used": uint64(0),
|
"used": uint64(0),
|
||||||
"free": uint64(0),
|
"free": uint64(0),
|
||||||
"inodes_total": uint64(0),
|
"inodes_total": uint64(0),
|
||||||
"inodes_free": uint64(0),
|
"inodes_free": uint64(0),
|
||||||
"inodes_used": uint64(0),
|
"inodes_used": uint64(0),
|
||||||
"used_percent": float64(0),
|
"used_percent": float64(0),
|
||||||
|
"inodes_used_percent": float64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -229,13 +233,14 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
"mode": "ro",
|
"mode": "ro",
|
||||||
},
|
},
|
||||||
expectedFields: map[string]interface{}{
|
expectedFields: map[string]interface{}{
|
||||||
"total": uint64(42),
|
"total": uint64(42),
|
||||||
"used": uint64(0),
|
"used": uint64(0),
|
||||||
"free": uint64(0),
|
"free": uint64(0),
|
||||||
"inodes_total": uint64(0),
|
"inodes_total": uint64(0),
|
||||||
"inodes_free": uint64(0),
|
"inodes_free": uint64(0),
|
||||||
"inodes_used": uint64(0),
|
"inodes_used": uint64(0),
|
||||||
"used_percent": float64(0),
|
"used_percent": float64(0),
|
||||||
|
"inodes_used_percent": float64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -262,13 +267,14 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
"mode": "ro",
|
"mode": "ro",
|
||||||
},
|
},
|
||||||
expectedFields: map[string]interface{}{
|
expectedFields: map[string]interface{}{
|
||||||
"total": uint64(42),
|
"total": uint64(42),
|
||||||
"used": uint64(0),
|
"used": uint64(0),
|
||||||
"free": uint64(0),
|
"free": uint64(0),
|
||||||
"inodes_total": uint64(0),
|
"inodes_total": uint64(0),
|
||||||
"inodes_free": uint64(0),
|
"inodes_free": uint64(0),
|
||||||
"inodes_used": uint64(0),
|
"inodes_used": uint64(0),
|
||||||
"used_percent": float64(0),
|
"used_percent": float64(0),
|
||||||
|
"inodes_used_percent": float64(0),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -424,7 +430,7 @@ func TestDiskStats(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
numDiskMetrics := acc.NFields()
|
numDiskMetrics := acc.NFields()
|
||||||
expectedAllDiskMetrics := 21
|
expectedAllDiskMetrics := 24
|
||||||
require.Equal(t, expectedAllDiskMetrics, numDiskMetrics)
|
require.Equal(t, expectedAllDiskMetrics, numDiskMetrics)
|
||||||
|
|
||||||
tags1 := map[string]string{
|
tags1 := map[string]string{
|
||||||
|
|
@ -441,22 +447,24 @@ func TestDiskStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fields1 := map[string]interface{}{
|
fields1 := map[string]interface{}{
|
||||||
"total": uint64(128),
|
"total": uint64(128),
|
||||||
"used": uint64(100),
|
"used": uint64(100),
|
||||||
"free": uint64(23),
|
"free": uint64(23),
|
||||||
"inodes_total": uint64(1234),
|
"inodes_total": uint64(1234),
|
||||||
"inodes_free": uint64(234),
|
"inodes_free": uint64(234),
|
||||||
"inodes_used": uint64(1000),
|
"inodes_used": uint64(1000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
}
|
}
|
||||||
fields2 := map[string]interface{}{
|
fields2 := map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "disk", fields1, tags1)
|
acc.AssertContainsTaggedFields(t, "disk", fields1, tags1)
|
||||||
acc.AssertContainsTaggedFields(t, "disk", fields2, tags2)
|
acc.AssertContainsTaggedFields(t, "disk", fields2, tags2)
|
||||||
|
|
@ -465,18 +473,18 @@ func TestDiskStats(t *testing.T) {
|
||||||
// and /home and /var/rootbind not matching the /dev in MountPoints
|
// and /home and /var/rootbind not matching the /dev in MountPoints
|
||||||
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/dev"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/dev"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8, acc.NFields())
|
||||||
|
|
||||||
// We should see all the diskpoints as MountPoints includes both
|
// We should see all the diskpoints as MountPoints includes both
|
||||||
// /, /home, and /var/rootbind
|
// /, /home, and /var/rootbind
|
||||||
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/home", "/var/rootbind"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, MountPoints: []string{"/", "/home", "/var/rootbind"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7*4, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8*4, acc.NFields())
|
||||||
|
|
||||||
// We should see all the mounts as MountPoints except the bind mound
|
// We should see all the mounts as MountPoints except the bind mound
|
||||||
err = (&DiskStats{ps: &mps, IgnoreMountOpts: []string{"bind"}}).Gather(&acc)
|
err = (&DiskStats{ps: &mps, IgnoreMountOpts: []string{"bind"}}).Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expectedAllDiskMetrics+7*6, acc.NFields())
|
require.Equal(t, expectedAllDiskMetrics+8*6, acc.NFields())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiskUsageIssues(t *testing.T) {
|
func TestDiskUsageIssues(t *testing.T) {
|
||||||
|
|
@ -511,13 +519,14 @@ func TestDiskUsageIssues(t *testing.T) {
|
||||||
"path": "/tmp",
|
"path": "/tmp",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
},
|
},
|
||||||
time.Unix(0, 0),
|
time.Unix(0, 0),
|
||||||
telegraf.Gauge,
|
telegraf.Gauge,
|
||||||
|
|
@ -531,13 +540,14 @@ func TestDiskUsageIssues(t *testing.T) {
|
||||||
"path": "/",
|
"path": "/",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
},
|
},
|
||||||
time.Unix(0, 0),
|
time.Unix(0, 0),
|
||||||
telegraf.Gauge,
|
telegraf.Gauge,
|
||||||
|
|
@ -565,13 +575,14 @@ func TestDiskUsageIssues(t *testing.T) {
|
||||||
"path": "/",
|
"path": "/",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
},
|
},
|
||||||
time.Unix(0, 0),
|
time.Unix(0, 0),
|
||||||
telegraf.Gauge,
|
telegraf.Gauge,
|
||||||
|
|
@ -585,13 +596,14 @@ func TestDiskUsageIssues(t *testing.T) {
|
||||||
"path": "/mnt/storage",
|
"path": "/mnt/storage",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"total": uint64(256),
|
"total": uint64(256),
|
||||||
"used": uint64(200),
|
"used": uint64(200),
|
||||||
"free": uint64(46),
|
"free": uint64(46),
|
||||||
"inodes_total": uint64(2468),
|
"inodes_total": uint64(2468),
|
||||||
"inodes_free": uint64(468),
|
"inodes_free": uint64(468),
|
||||||
"inodes_used": uint64(2000),
|
"inodes_used": uint64(2000),
|
||||||
"used_percent": float64(81.30081300813008),
|
"used_percent": float64(81.30081300813008),
|
||||||
|
"inodes_used_percent": float64(81.03727714748784),
|
||||||
},
|
},
|
||||||
time.Unix(0, 0),
|
time.Unix(0, 0),
|
||||||
telegraf.Gauge,
|
telegraf.Gauge,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue