@@ -103,15 +103,32 @@ func (s *DiskIO) Gather(acc telegraf.Accumulator) error {
103
103
}
104
104
105
105
for _ , io := range diskio {
106
- if s .deviceFilter != nil && ! s .deviceFilter .Match (io .Name ) {
107
- continue
106
+
107
+ match := false
108
+ if s .deviceFilter != nil && s .deviceFilter .Match (io .Name ) {
109
+ match = true
108
110
}
109
111
110
112
tags := map [string ]string {}
111
- tags ["name" ] = s .diskName (io .Name )
113
+ var devLinks []string
114
+ tags ["name" ], devLinks = s .diskName (io .Name )
115
+
116
+ if s .deviceFilter != nil && ! match {
117
+ for _ , devLink := range devLinks {
118
+ if s .deviceFilter .Match (devLink ) {
119
+ match = true
120
+ break
121
+ }
122
+ }
123
+ if ! match {
124
+ continue
125
+ }
126
+ }
127
+
112
128
for t , v := range s .diskTags (io .Name ) {
113
129
tags [t ] = v
114
130
}
131
+
115
132
if ! s .SkipSerialNumber {
116
133
if len (io .SerialNumber ) != 0 {
117
134
tags ["serial" ] = io .SerialNumber
@@ -137,15 +154,20 @@ func (s *DiskIO) Gather(acc telegraf.Accumulator) error {
137
154
return nil
138
155
}
139
156
140
- func (s * DiskIO ) diskName (devName string ) string {
157
+ func (s * DiskIO ) diskName (devName string ) (string , []string ) {
158
+ di , err := s .diskInfo (devName )
159
+ devLinks := strings .Split (di ["DEVLINKS" ], " " )
160
+ for i , devLink := range devLinks {
161
+ devLinks [i ] = strings .TrimPrefix (devLink , "/dev/" )
162
+ }
163
+
141
164
if len (s .NameTemplates ) == 0 {
142
- return devName
165
+ return devName , devLinks
143
166
}
144
167
145
- di , err := s .diskInfo (devName )
146
168
if err != nil {
147
169
log .Printf ("W! Error gathering disk info: %s" , err )
148
- return devName
170
+ return devName , devLinks
149
171
}
150
172
151
173
for _ , nt := range s .NameTemplates {
@@ -163,11 +185,11 @@ func (s *DiskIO) diskName(devName string) string {
163
185
})
164
186
165
187
if ! miss {
166
- return name
188
+ return name , devLinks
167
189
}
168
190
}
169
191
170
- return devName
192
+ return devName , devLinks
171
193
}
172
194
173
195
func (s * DiskIO ) diskTags (devName string ) map [string ]string {
0 commit comments