Skip to content

Commit

Permalink
Bugfix - Failure due duplicated records in statistic tables
Browse files Browse the repository at this point in the history
  • Loading branch information
vagifzeynalov committed Oct 9, 2021
1 parent e27581d commit f002502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ var (
"model_name",
"serial_number",
"statistic_table",
"statistic_table_row",
"statistic_name",
"statistic_flags_short",
"statistic_flags_long",
Expand Down
7 changes: 5 additions & 2 deletions smartctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -375,7 +376,7 @@ func (smart *SMARTctl) mineSmartStatus() {
func (smart *SMARTctl) mineDeviceStatistics() {
for _, page := range smart.json.Get("ata_device_statistics.pages").Array() {
table := strings.TrimSpace(page.Get("name").String())
for _, statistic := range page.Get("table").Array() {
for row, statistic := range page.Get("table").Array() {
smart.ch <- prometheus.MustNewConstMetric(
metricDeviceStatistics,
prometheus.GaugeValue,
Expand All @@ -385,6 +386,7 @@ func (smart *SMARTctl) mineDeviceStatistics() {
smart.device.model,
smart.device.serial,
table,
strconv.Itoa(row),
strings.TrimSpace(statistic.Get("name").String()),
strings.TrimSpace(statistic.Get("flags.string").String()),
smart.mineLongFlags(statistic.Get("flags"), []string{
Expand All @@ -397,7 +399,7 @@ func (smart *SMARTctl) mineDeviceStatistics() {
}
}

for _, statistic := range smart.json.Get("sata_phy_event_counters.table").Array() {
for row, statistic := range smart.json.Get("sata_phy_event_counters.table").Array() {
smart.ch <- prometheus.MustNewConstMetric(
metricDeviceStatistics,
prometheus.GaugeValue,
Expand All @@ -407,6 +409,7 @@ func (smart *SMARTctl) mineDeviceStatistics() {
smart.device.model,
smart.device.serial,
"SATA PHY Event Counters",
strconv.Itoa(row),
strings.TrimSpace(statistic.Get("name").String()),
"V---",
"valid",
Expand Down

0 comments on commit f002502

Please sign in to comment.