From d26c3a82eaea84d281132fae5309f439eea444d6 Mon Sep 17 00:00:00 2001 From: Niklas Schwarz Date: Wed, 28 Jun 2023 10:28:11 +0200 Subject: [PATCH] Add counter for the number of devices configured or dynamically discovered Signed-off-by: Niklas Schwarz --- main.go | 11 ++++++----- metrics.go | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 8e64536..87d9820 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,11 @@ func (i SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) { smart.Collect() } } + ch <- prometheus.MustNewConstMetric( + metricDeviceCount, + prometheus.GaugeValue, + float64(len(i.Devices)), + ) info.Collect() } @@ -123,11 +128,7 @@ func main() { } else { level.Info(logger).Log("msg", "No devices specified, trying to load them automatically") devices = scanDevices(logger) - } - - if len(devices) == 0 { - level.Error(logger).Log("msg", "No devices found") - os.Exit(1) + level.Info(logger).Log("msg", "Number of devices found", "count", len(devices)) } collector := SMARTctlManagerCollector{ diff --git a/metrics.go b/metrics.go index 27cf0cc..2f11d6d 100644 --- a/metrics.go +++ b/metrics.go @@ -47,6 +47,12 @@ var ( }, nil, ) + metricDeviceCount = prometheus.NewDesc( + "smartctl_device_count", + "Number of devices configured or dynamically discovered", + []string{}, + nil, + ) metricDeviceCapacityBlocks = prometheus.NewDesc( "smartctl_device_capacity_blocks", "Device capacity in blocks",