@@ -2,6 +2,7 @@ package system
22
33import (
44 "os"
5+ "strings"
56
67 "github.com/influxdata/telegraf"
78 "github.com/influxdata/telegraf/internal"
@@ -84,9 +85,14 @@ func (s *systemPS) DiskUsage(
8485 for _ , filter := range fstypeExclude {
8586 fstypeExcludeSet [filter ] = true
8687 }
88+ paths := make (map [string ]bool )
89+ for _ , part := range parts {
90+ paths [part .Mountpoint ] = true
91+ }
8792
8893 var usage []* disk.UsageStat
8994 var partitions []* disk.PartitionStat
95+ hostMountPrefix := s .OSGetenv ("HOST_MOUNT_PREFIX" )
9096
9197 for i := range parts {
9298 p := parts [i ]
@@ -105,15 +111,20 @@ func (s *systemPS) DiskUsage(
105111 continue
106112 }
107113
108- mountpoint := s .OSGetenv ("HOST_MOUNT_PREFIX" ) + p .Mountpoint
109- if _ , err := s .OSStat (mountpoint ); err != nil {
114+ // If there's a host mount prefix, exclude any paths which conflict
115+ // with the prefix.
116+ if len (hostMountPrefix ) > 0 &&
117+ ! strings .HasPrefix (p .Mountpoint , hostMountPrefix ) &&
118+ paths [hostMountPrefix + p .Mountpoint ] {
110119 continue
111120 }
112- du , err := s .PSDiskUsage (mountpoint )
121+
122+ du , err := s .PSDiskUsage (p .Mountpoint )
113123 if err != nil {
114124 continue
115125 }
116- du .Path = p .Mountpoint
126+
127+ du .Path = strings .TrimPrefix (p .Mountpoint , hostMountPrefix )
117128 du .Fstype = p .Fstype
118129 usage = append (usage , du )
119130 partitions = append (partitions , & p )
0 commit comments