feat(inputs.disk): Add label as tag (#12696)
This commit is contained in:
parent
29916dfee0
commit
caf14adb17
|
|
@ -54,6 +54,7 @@ docker run -v /:/hostfs:ro -e HOST_MOUNT_PREFIX=/hostfs -e HOST_PROC=/hostfs/pro
|
||||||
- device (device file)
|
- device (device file)
|
||||||
- path (mount point path)
|
- path (mount point path)
|
||||||
- mode (whether the mount is rw or ro)
|
- mode (whether the mount is rw or ro)
|
||||||
|
- label (devicemapper labels, only if present)
|
||||||
- fields:
|
- fields:
|
||||||
- free (integer, bytes)
|
- free (integer, bytes)
|
||||||
- total (integer, bytes)
|
- total (integer, bytes)
|
||||||
|
|
@ -88,6 +89,7 @@ disk,fstype=hfs,mode=ro,path=/ free=398407520256i,inodes_free=97267461i,inodes_t
|
||||||
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 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 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 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
|
||||||
```
|
```
|
||||||
|
|
||||||
[statfs]: http://man7.org/linux/man-pages/man2/statfs.2.html
|
[statfs]: http://man7.org/linux/man-pages/man2/statfs.2.html
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
|
|
@ -53,13 +54,21 @@ func (ds *DiskStats) Gather(acc telegraf.Accumulator) error {
|
||||||
// Skip dummy filesystem (procfs, cgroupfs, ...)
|
// Skip dummy filesystem (procfs, cgroupfs, ...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device := partitions[i].Device
|
||||||
mountOpts := MountOptions(partitions[i].Opts)
|
mountOpts := MountOptions(partitions[i].Opts)
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"path": du.Path,
|
"path": du.Path,
|
||||||
"device": strings.ReplaceAll(partitions[i].Device, "/dev/", ""),
|
"device": strings.ReplaceAll(device, "/dev/", ""),
|
||||||
"fstype": du.Fstype,
|
"fstype": du.Fstype,
|
||||||
"mode": mountOpts.Mode(),
|
"mode": mountOpts.Mode(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label, err := disk.Label(strings.TrimPrefix(device, "/dev/"))
|
||||||
|
if err == nil && label != "" {
|
||||||
|
tags["label"] = label
|
||||||
|
}
|
||||||
|
|
||||||
var usedPercent float64
|
var usedPercent float64
|
||||||
if du.Used+du.Free > 0 {
|
if du.Used+du.Free > 0 {
|
||||||
usedPercent = float64(du.Used) /
|
usedPercent = float64(du.Used) /
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue