mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-11-16 01:33:07 +01:00
Automatically load the available devices
This commit is contained in:
parent
315d1538aa
commit
593ca96a99
3 changed files with 25 additions and 5 deletions
11
main.go
11
main.go
|
@ -36,6 +36,17 @@ func (i SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) {
|
|||
|
||||
func init() {
|
||||
options = loadOptions()
|
||||
|
||||
if len(options.SMARTctl.Devices) == 0 {
|
||||
logger.Debug("No devices specified, trying to load them automatically")
|
||||
json := readSMARTctlDevices()
|
||||
devices := json.Get("devices").Array()
|
||||
for _, d := range devices {
|
||||
device := d.Get("name").String()
|
||||
logger.Debug("Found device: %s", device)
|
||||
options.SMARTctl.Devices = append(options.SMARTctl.Devices, device)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -55,6 +55,15 @@ func readSMARTctl(device string) gjson.Result {
|
|||
return parseJSON(string(out))
|
||||
}
|
||||
|
||||
func readSMARTctlDevices() gjson.Result {
|
||||
logger.Debug("Collecting devices")
|
||||
out, err := exec.Command(options.SMARTctl.SMARTctlLocation, "--json", "--scan-open").Output()
|
||||
if err != nil {
|
||||
logger.Warning("S.M.A.R.T. output reading error: %s", err)
|
||||
}
|
||||
return parseJSON(string(out))
|
||||
}
|
||||
|
||||
// Select json source and parse
|
||||
func readData(device string) gjson.Result {
|
||||
if options.SMARTctl.FakeJSON {
|
||||
|
|
|
@ -4,8 +4,8 @@ smartctl_exporter:
|
|||
fake_json: no
|
||||
smartctl_location: /usr/sbin/smartctl
|
||||
collect_not_more_than_period: 20s
|
||||
devices:
|
||||
- /dev/nvme0
|
||||
- /dev/nvme1
|
||||
- /dev/nvme2
|
||||
- /dev/nvme3
|
||||
# devices:
|
||||
# - /dev/nvme0
|
||||
# - /dev/nvme1
|
||||
# - /dev/nvme2
|
||||
# - /dev/nvme3
|
||||
|
|
Loading…
Reference in a new issue