Skip to content

Commit

Permalink
Diskio plugin: make devices glob also match devlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Mangold committed May 8, 2019
1 parent c2643d5 commit 1187e97
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions plugins/inputs/diskio/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,32 @@ func (s *DiskIO) Gather(acc telegraf.Accumulator) error {
}

for _, io := range diskio {
if s.deviceFilter != nil && !s.deviceFilter.Match(io.Name) {
continue

match := false
if s.deviceFilter != nil && s.deviceFilter.Match(io.Name) {
match = true
}

tags := map[string]string{}
tags["name"] = s.diskName(io.Name)
var devLinks []string
tags["name"], devLinks = s.diskName(io.Name)

if s.deviceFilter != nil && !match {
for _, devLink := range devLinks {
if s.deviceFilter.Match(devLink) {
match = true
break
}
}
if !match {
continue
}
}

for t, v := range s.diskTags(io.Name) {
tags[t] = v
}

if !s.SkipSerialNumber {
if len(io.SerialNumber) != 0 {
tags["serial"] = io.SerialNumber
Expand All @@ -137,15 +154,20 @@ func (s *DiskIO) Gather(acc telegraf.Accumulator) error {
return nil
}

func (s *DiskIO) diskName(devName string) string {
func (s *DiskIO) diskName(devName string) (string,[]string) {
di, err := s.diskInfo(devName)
devLinks := strings.Split(di["DEVLINKS"]," ")
for i, devLink := range devLinks {
devLinks[i] = strings.TrimPrefix(devLink,"/dev/")
}

if len(s.NameTemplates) == 0 {
return devName
return devName, devLinks
}

di, err := s.diskInfo(devName)
if err != nil {
log.Printf("W! Error gathering disk info: %s", err)
return devName
return devName, devLinks
}

for _, nt := range s.NameTemplates {
Expand All @@ -163,11 +185,11 @@ func (s *DiskIO) diskName(devName string) string {
})

if !miss {
return name
return name, devLinks
}
}

return devName
return devName, devLinks
}

func (s *DiskIO) diskTags(devName string) map[string]string {
Expand Down

0 comments on commit 1187e97

Please sign in to comment.