From 3e177068398fa3aa41484ddc7e0b0fc50fdb9eec Mon Sep 17 00:00:00 2001 From: Octavian Cerna Date: Sun, 26 Jul 2020 23:48:49 +0300 Subject: [PATCH] Add a new metric smartctl_device_error_log_count for the SMART error log counts. --- metrics.go | 12 ++++++++++++ smartctl.go | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/metrics.go b/metrics.go index a0a2f37..f08298b 100644 --- a/metrics.go +++ b/metrics.go @@ -188,4 +188,16 @@ var ( }, nil, ) + metricDeviceErrorLogCount = prometheus.NewDesc( + "smartctl_device_error_log_count", + "Device SMART error log count", + []string{ + "device", + "model_family", + "model_name", + "serial_number", + "error_log_type", + }, + nil, + ) ) diff --git a/smartctl.go b/smartctl.go index 5d0c977..0958cf7 100644 --- a/smartctl.go +++ b/smartctl.go @@ -52,6 +52,7 @@ func (smart *SMARTctl) Collect() { smart.mineDeviceSCTStatus() smart.mineDeviceStatistics() smart.mineDeviceStatus() + smart.mineDeviceErrorLog() } func (smart *SMARTctl) mineExitStatus() { @@ -312,3 +313,18 @@ func (smart *SMARTctl) mineDeviceStatus() { smart.device.serial, ) } + +func (smart *SMARTctl) mineDeviceErrorLog() { + for logType, status := range smart.json.Get("ata_smart_error_log").Map() { + smart.ch <- prometheus.MustNewConstMetric( + metricDeviceErrorLogCount, + prometheus.GaugeValue, + status.Get("count").Float(), + smart.device.device, + smart.device.family, + smart.device.model, + smart.device.serial, + logType, + ) + } +}