mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-11-16 01:33:07 +01:00
Add support for autoscan device types and predictable device paths
This adds a new command line option allowing for customization of autodetected device types and enables use of special "by-id" device type that forces use of predictable device paths (/dev/disk/by-id/...) Relevant change to device name parsing regular expression is included now, so predictable device paths are now also usable when directly specified. Signed-off-by: Piotr Dobrowolski <admin@tastycode.pl>
This commit is contained in:
parent
1c9c6943e8
commit
4c5f721e11
3 changed files with 10 additions and 2 deletions
4
main.go
4
main.go
|
@ -108,6 +108,10 @@ var (
|
||||||
"smartctl.device-include",
|
"smartctl.device-include",
|
||||||
"Regexp of devices to exclude from automatic scanning. (mutually exclusive to device-exclude)",
|
"Regexp of devices to exclude from automatic scanning. (mutually exclusive to device-exclude)",
|
||||||
).Default("").String()
|
).Default("").String()
|
||||||
|
smartctlDeviceTypes = kingpin.Flag(
|
||||||
|
"smartctl.device-type",
|
||||||
|
"Device type to use during automatic scan. Special by-id value forces predictable device names. (repeatable)",
|
||||||
|
).Strings()
|
||||||
smartctlFakeData = kingpin.Flag("smartctl.fake-data",
|
smartctlFakeData = kingpin.Flag("smartctl.fake-data",
|
||||||
"The device to monitor (repeatable)",
|
"The device to monitor (repeatable)",
|
||||||
).Default("false").Hidden().Bool()
|
).Default("false").Hidden().Bool()
|
||||||
|
|
|
@ -77,7 +77,11 @@ func readSMARTctl(logger log.Logger, device Device) (gjson.Result, bool) {
|
||||||
|
|
||||||
func readSMARTctlDevices(logger log.Logger) gjson.Result {
|
func readSMARTctlDevices(logger log.Logger) gjson.Result {
|
||||||
level.Debug(logger).Log("msg", "Scanning for devices")
|
level.Debug(logger).Log("msg", "Scanning for devices")
|
||||||
out, err := exec.Command(*smartctlPath, "--json", "--scan").Output()
|
var scanArgs []string = []string{"--json", "--scan"}
|
||||||
|
for _, d := range *smartctlDeviceTypes {
|
||||||
|
scanArgs = append(scanArgs, "--device", d)
|
||||||
|
}
|
||||||
|
out, err := exec.Command(*smartctlPath, scanArgs...).Output()
|
||||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
level.Debug(logger).Log("msg", "Exit Status", "exit_code", exiterr.ExitCode())
|
level.Debug(logger).Log("msg", "Exit Status", "exit_code", exiterr.ExitCode())
|
||||||
// The smartctl command returns 2 if devices are sleeping, ignore this error.
|
// The smartctl command returns 2 if devices are sleeping, ignore this error.
|
||||||
|
|
|
@ -44,7 +44,7 @@ type SMARTctl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractDiskName(input string) string {
|
func extractDiskName(input string) string {
|
||||||
re := regexp.MustCompile(`^(?:/dev/(?P<bus_name>\S+)/(?P<bus_num>\S+)\s\[|/dev/|\[)(?:\s\[|)(?P<disk>[a-z0-9_]+)(?:\].*|)$`)
|
re := regexp.MustCompile(`^(?:/dev/(?P<bus_name>\S+)/(?P<bus_num>\S+)\s\[|/dev/(?:disk\/by-id\/|disk\/by-path\/|)|\[)(?:\s\[|)(?P<disk>[A-Za-z0-9_\-]+)(?:\].*|)$`)
|
||||||
match := re.FindStringSubmatch(input)
|
match := re.FindStringSubmatch(input)
|
||||||
|
|
||||||
if len(match) > 0 {
|
if len(match) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue