From 8689dd4a659a2c509735d24f538e87d09ada24e9 Mon Sep 17 00:00:00 2001 From: izenn Date: Fri, 3 Feb 2023 16:40:05 -0600 Subject: [PATCH 1/2] add disk label to disk input plugin --- plugins/inputs/disk/disk.go | 1 + plugins/inputs/system/ps.go | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/disk/disk.go b/plugins/inputs/disk/disk.go index 8b8d8bcedb0d7..770700d2a5fe4 100644 --- a/plugins/inputs/disk/disk.go +++ b/plugins/inputs/disk/disk.go @@ -57,6 +57,7 @@ func (ds *DiskStats) Gather(acc telegraf.Accumulator) error { tags := map[string]string{ "path": du.Path, "device": strings.ReplaceAll(partitions[i].Device, "/dev/", ""), + "label": partitions[i].Label, "fstype": du.Fstype, "mode": mountOpts.Mode(), } diff --git a/plugins/inputs/system/ps.go b/plugins/inputs/system/ps.go index 49acfd8f13092..569d38fc649a0 100644 --- a/plugins/inputs/system/ps.go +++ b/plugins/inputs/system/ps.go @@ -17,7 +17,7 @@ import ( type PS interface { CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) - DiskUsage(mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) + DiskUsage(mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string) ([]*disk.UsageStat, []*PartitionStatExtended, error) NetIO() ([]net.IOCountersStat, error) NetProto() ([]net.ProtoCountersStat, error) DiskIO(names []string) (map[string]disk.IOCountersStat, error) @@ -46,6 +46,14 @@ type SystemPS struct { type SystemPSDisk struct{} +type PartitionStatExtended struct { + Device string `json:"device"` + Mountpoint string `json:"mountpoint"` + Fstype string `json:"fstype"` + Opts []string `json:"opts"` + Label string `json:"label"` +} + func (s *SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) { var cpuTimes []cpu.TimesStat if perCPU { @@ -94,7 +102,7 @@ func (s *SystemPS) DiskUsage( mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string, -) ([]*disk.UsageStat, []*disk.PartitionStat, error) { +) ([]*disk.UsageStat, []*PartitionStatExtended, error) { parts, err := s.Partitions(true) if err != nil { return nil, nil, err @@ -123,7 +131,7 @@ func (s *SystemPS) DiskUsage( fstypeExcludeSet.add("autofs") var usage []*disk.UsageStat - var partitions []*disk.PartitionStat + var partitions []*PartitionStatExtended hostMountPrefix := s.OSGetenv("HOST_MOUNT_PREFIX") partitionRange: @@ -174,7 +182,13 @@ partitionRange: du.Path = filepath.Join("/", strings.TrimPrefix(p.Mountpoint, hostMountPrefix)) du.Fstype = p.Fstype usage = append(usage, du) - partitions = append(partitions, &p) + e := PartitionStatExtended{Device: p.Device, Mountpoint: p.Mountpoint, Fstype: p.Fstype, Opts: p.Opts} + m := strings.Count(p.Device, "/dev/") + if (m > 0) { + label, _ := disk.Label(strings.Replace(p.Device, "/dev/", "", 1)) + e.Label = label + } + partitions = append(partitions, &e) } return usage, partitions, nil From 2701ec4d87d97f79ca05f3a636e9cc4ea8994872 Mon Sep 17 00:00:00 2001 From: izenn Date: Fri, 3 Feb 2023 16:51:49 -0600 Subject: [PATCH 2/2] update readme for disk plugin --- plugins/inputs/disk/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/disk/README.md b/plugins/inputs/disk/README.md index 11ed24a08b567..3fffc6e55ff7c 100644 --- a/plugins/inputs/disk/README.md +++ b/plugins/inputs/disk/README.md @@ -54,6 +54,7 @@ docker run -v /:/hostfs:ro -e HOST_MOUNT_PREFIX=/hostfs -e HOST_PROC=/hostfs/pro - device (device file) - path (mount point path) - mode (whether the mount is rw or ro) + - label (disk label if present) - fields: - free (integer, bytes) - total (integer, bytes) @@ -84,7 +85,7 @@ sudo setfacl -R -m u:telegraf:X /var/lib/docker/volumes/ ## Example Output ```shell -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,label=root,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=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=/home free=0i,inodes_free=0i,inodes_total=0i,inodes_used=0i,total=0i,used=0i,used_percent=0 1453832006274169688