From 2c2b4aa970b635c04eb8d4b53a9f6b26d33a819e Mon Sep 17 00:00:00 2001 From: Deezzir Date: Thu, 19 Dec 2024 21:13:06 -0500 Subject: [PATCH 1/3] Do not export smart_status if object is not present Signed-off-by: Deezzir --- smartctl.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/smartctl.go b/smartctl.go index eb94130..9207bd1 100644 --- a/smartctl.go +++ b/smartctl.go @@ -468,12 +468,16 @@ func (smart *SMARTctl) mineSCSIBytesWritten() { } func (smart *SMARTctl) mineSmartStatus() { - smart.ch <- prometheus.MustNewConstMetric( - metricDeviceSmartStatus, - prometheus.GaugeValue, - smart.json.Get("smart_status.passed").Float(), - smart.device.device, - ) + passed_raw := smart.json.Get("smart_status.passed") + + if passed_raw.Exists() { + smart.ch <- prometheus.MustNewConstMetric( + metricDeviceSmartStatus, + prometheus.GaugeValue, + passed_raw.Float(), + smart.device.device, + ) + } } func (smart *SMARTctl) mineDeviceStatistics() { From b47737b0bea6974693da7b5583859ffc53508198 Mon Sep 17 00:00:00 2001 From: Deezzir Date: Thu, 19 Dec 2024 21:38:04 -0500 Subject: [PATCH 2/3] Rename var Signed-off-by: Deezzir --- smartctl.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/smartctl.go b/smartctl.go index 9207bd1..4909e40 100644 --- a/smartctl.go +++ b/smartctl.go @@ -468,13 +468,12 @@ func (smart *SMARTctl) mineSCSIBytesWritten() { } func (smart *SMARTctl) mineSmartStatus() { - passed_raw := smart.json.Get("smart_status.passed") - - if passed_raw.Exists() { + smartStatus := smart.json.Get("smart_status.passed") + if smartStatus.Exists() { smart.ch <- prometheus.MustNewConstMetric( metricDeviceSmartStatus, prometheus.GaugeValue, - passed_raw.Float(), + smartStatus.Float(), smart.device.device, ) } From c2cce7bb2cb47adb82e7afeafe50eb3daa82aae6 Mon Sep 17 00:00:00 2001 From: Deezzir Date: Thu, 19 Dec 2024 21:42:18 -0500 Subject: [PATCH 3/3] Check for `smart_status` object presense Signed-off-by: Deezzir --- smartctl.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smartctl.go b/smartctl.go index 4909e40..b136b8b 100644 --- a/smartctl.go +++ b/smartctl.go @@ -468,12 +468,12 @@ func (smart *SMARTctl) mineSCSIBytesWritten() { } func (smart *SMARTctl) mineSmartStatus() { - smartStatus := smart.json.Get("smart_status.passed") + smartStatus := smart.json.Get("smart_status") if smartStatus.Exists() { smart.ch <- prometheus.MustNewConstMetric( metricDeviceSmartStatus, prometheus.GaugeValue, - smartStatus.Float(), + smartStatus.Get("passed").Float(), smart.device.device, ) }