Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diskio plugin: make devices glob also match devlinks #5817

Merged
merged 1 commit into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion plugins/inputs/diskio/diskio_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func TestDiskIOStats_diskName(t *testing.T) {
s := DiskIO{
NameTemplates: tc.templates,
}
assert.Equal(t, tc.expected, s.diskName("null"), "Templates: %#v", tc.templates)
name, _ := s.diskName("null")
assert.Equal(t, tc.expected, name, "Templates: %#v", tc.templates)
}
}

Expand Down