Merge pull request #129 from Knalltuete5000/devices_count

Add counter for the number of devices configured or dynamically discovered
This commit is contained in:
David Randall 2023-08-15 19:17:09 -04:00 committed by GitHub
commit f5b403b5ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

11
main.go
View file

@ -59,6 +59,11 @@ func (i *SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) {
smart.Collect() smart.Collect()
} }
} }
ch <- prometheus.MustNewConstMetric(
metricDeviceCount,
prometheus.GaugeValue,
float64(len(i.Devices)),
)
info.Collect() info.Collect()
i.mutex.Unlock() i.mutex.Unlock()
} }
@ -141,11 +146,7 @@ func main() {
} else { } else {
level.Info(logger).Log("msg", "No devices specified, trying to load them automatically") level.Info(logger).Log("msg", "No devices specified, trying to load them automatically")
devices = scanDevices(logger) devices = scanDevices(logger)
} level.Info(logger).Log("msg", "Number of devices found", "count", len(devices))
if len(devices) == 0 {
level.Error(logger).Log("msg", "No devices found")
os.Exit(1)
} }
collector := SMARTctlManagerCollector{ collector := SMARTctlManagerCollector{

View file

@ -47,6 +47,12 @@ var (
}, },
nil, nil,
) )
metricDeviceCount = prometheus.NewDesc(
"smartctl_device_count",
"Number of devices configured or dynamically discovered",
[]string{},
nil,
)
metricDeviceCapacityBlocks = prometheus.NewDesc( metricDeviceCapacityBlocks = prometheus.NewDesc(
"smartctl_device_capacity_blocks", "smartctl_device_capacity_blocks",
"Device capacity in blocks", "Device capacity in blocks",