Add a new metric smartctl_device_state for the device state from ATA SCT.

This commit is contained in:
Octavian Cerna 2020-07-26 22:54:54 +03:00
parent 9e10465744
commit 3feff84fbb
2 changed files with 27 additions and 0 deletions

View file

@ -151,6 +151,17 @@ var (
}, },
nil, nil,
) )
metricDeviceState = prometheus.NewDesc(
"smartctl_device_state",
"Device state (0=active, 1=standby, 2=sleep, 3=dst, 4=offline, 5=sct)",
[]string{
"device",
"model_family",
"model_name",
"serial_number",
},
nil,
)
metricDeviceStatistics = prometheus.NewDesc( metricDeviceStatistics = prometheus.NewDesc(
"smartctl_device_statistics", "smartctl_device_statistics",
"Device statistics", "Device statistics",

View file

@ -49,6 +49,7 @@ func (smart *SMARTctl) Collect() {
smart.mineRotationRate() smart.mineRotationRate()
smart.mineTemperatures() smart.mineTemperatures()
smart.minePowerCycleCount() smart.minePowerCycleCount()
smart.mineDeviceSCTStatus()
smart.mineDeviceStatistics() smart.mineDeviceStatistics()
smart.mineDeviceStatus() smart.mineDeviceStatus()
} }
@ -231,6 +232,21 @@ func (smart *SMARTctl) minePowerCycleCount() {
) )
} }
func (smart *SMARTctl) mineDeviceSCTStatus() {
status := smart.json.Get("ata_sct_status")
if status.Exists() {
smart.ch <- prometheus.MustNewConstMetric(
metricDeviceState,
prometheus.GaugeValue,
status.Get("device_state").Float(),
smart.device.device,
smart.device.family,
smart.device.model,
smart.device.serial,
)
}
}
func (smart *SMARTctl) mineDeviceStatistics() { func (smart *SMARTctl) mineDeviceStatistics() {
for _, page := range smart.json.Get("ata_device_statistics.pages").Array() { for _, page := range smart.json.Get("ata_device_statistics.pages").Array() {
table := strings.TrimSpace(page.Get("name").String()) table := strings.TrimSpace(page.Get("name").String())