diff --git a/plugins/inputs/disk/disk.go b/plugins/inputs/disk/disk.go index 66199f7ee5be7..0827c5bda62f0 100644 --- a/plugins/inputs/disk/disk.go +++ b/plugins/inputs/disk/disk.go @@ -49,6 +49,9 @@ func (ds *Disk) Gather(acc telegraf.Accumulator) error { } device := partitions[i].Device + if device == "none" || device == "" { + device = partitions[i].Fstype + } mountOpts := mountOptions(partitions[i].Opts) tags := map[string]string{ "path": du.Path, diff --git a/plugins/inputs/disk/disk_test.go b/plugins/inputs/disk/disk_test.go index 3df6af86bba95..2e2f7b65fbe81 100644 --- a/plugins/inputs/disk/disk_test.go +++ b/plugins/inputs/disk/disk_test.go @@ -273,6 +273,72 @@ func TestDiskUsageHostMountPrefix(t *testing.T) { "inodes_used_percent": float64(0), }, }, + { + name: "virtual filesystem with none device", + partitionStats: []disk.PartitionStat{ + { + Device: "none", + Mountpoint: "/tmp", + Fstype: "tmpfs", + Opts: []string{"rw"}, + }, + }, + usageStats: []*disk.UsageStat{ + { + Path: "/tmp", + Total: 42, + }, + }, + expectedTags: map[string]string{ + "path": fmt.Sprintf("%ctmp", os.PathSeparator), + "device": "tmpfs", + "fstype": "tmpfs", + "mode": "rw", + }, + expectedFields: map[string]interface{}{ + "total": uint64(42), + "used": uint64(0), + "free": uint64(0), + "inodes_total": uint64(0), + "inodes_free": uint64(0), + "inodes_used": uint64(0), + "used_percent": float64(0), + "inodes_used_percent": float64(0), + }, + }, + { + name: "virtual filesystem with empty device", + partitionStats: []disk.PartitionStat{ + { + Device: "", + Mountpoint: "/sys", + Fstype: "sysfs", + Opts: []string{"ro"}, + }, + }, + usageStats: []*disk.UsageStat{ + { + Path: "/sys", + Total: 42, + }, + }, + expectedTags: map[string]string{ + "path": fmt.Sprintf("%csys", os.PathSeparator), + "device": "sysfs", + "fstype": "sysfs", + "mode": "ro", + }, + expectedFields: map[string]interface{}{ + "total": uint64(42), + "used": uint64(0), + "free": uint64(0), + "inodes_total": uint64(0), + "inodes_free": uint64(0), + "inodes_used": uint64(0), + "used_percent": float64(0), + "inodes_used_percent": float64(0), + }, + }, } for _, tt := range tests {