mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-12-21 02:21:55 +01:00
Add bus name & bus number to disk name, example: bus_0_megaraid_disk_01
Signed-off-by: Denys <zxzharmlesszxz@gmail.com>
This commit is contained in:
parent
3a012b5bb1
commit
7f7c652b0f
1 changed files with 16 additions and 2 deletions
18
smartctl.go
18
smartctl.go
|
@ -44,11 +44,25 @@ type SMARTctl struct {
|
|||
}
|
||||
|
||||
func extractDiskName(input string) string {
|
||||
re := regexp.MustCompile(`^(?:/dev/\S+/\S+\s\[|/dev/|\[)(?:\s\[|)(?P<disk>[a-z0-9_]+)(?:\].*|)$`)
|
||||
re := regexp.MustCompile(`^(?:/dev/(?P<bus_name>\S+)/(?P<bus_num>\S+)\s\[|/dev/|\[)(?:\s\[|)(?P<disk>[a-z0-9_]+)(?:\].*|)$`)
|
||||
match := re.FindStringSubmatch(input)
|
||||
|
||||
if len(match) > 0 {
|
||||
return match[re.SubexpIndex("disk")]
|
||||
busNameIndex := re.SubexpIndex("bus_name")
|
||||
busNumIndex := re.SubexpIndex("bus_num")
|
||||
diskIndex := re.SubexpIndex("disk")
|
||||
var name []string
|
||||
if busNameIndex != -1 && match[busNameIndex] != "" {
|
||||
name = append(name, match[busNameIndex])
|
||||
}
|
||||
if busNumIndex != -1 && match[busNumIndex] != "" {
|
||||
name = append(name, match[busNumIndex])
|
||||
}
|
||||
if diskIndex != -1 && match[diskIndex] != "" {
|
||||
name = append(name, match[diskIndex])
|
||||
}
|
||||
|
||||
return strings.Join(name, "_")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue