Skip to content

Commit c6c8142

Browse files
committed
support SAS temperature
1 parent 7c35d59 commit c6c8142

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

webapp/backend/pkg/models/collector/smart.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ type SmartInfo struct {
235235
ScsiVersion string `json:"scsi_version"`
236236
ScsiGrownDefectList int64 `json:"scsi_grown_defect_list"`
237237
ScsiErrorCounterLog ScsiErrorCounterLog `json:"scsi_error_counter_log"`
238+
239+
ScsiEnvironmentalReports map[string]ScsiTemperatureData `json:"scsi_environmental_reports"`
240+
}
241+
242+
type ScsiTemperatureData struct {
243+
ParameterCode int `json:"parameter_code"`
244+
Current int64 `json:"current"`
245+
LifetimeMaximum int64 `json:"lifetime_maximum"`
246+
LifetimeMinimum int64 `json:"lifetime_minimum"`
247+
MaximumSincePowerOn int64 `json:"maximum_since_power_on"`
248+
MinimumSincePowerOn int64 `json:"minimum_since_power_on"`
238249
}
239250

240251
// Capacity finds the total capacity of the device in bytes, or 0 if unknown.

webapp/backend/pkg/models/measurements/smart.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package measurements
22

33
import (
44
"fmt"
5-
"github.com/analogj/scrutiny/webapp/backend/pkg"
6-
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
7-
"github.com/analogj/scrutiny/webapp/backend/pkg/thresholds"
85
"log"
96
"strconv"
107
"strings"
118
"time"
9+
10+
"github.com/analogj/scrutiny/webapp/backend/pkg"
11+
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
12+
"github.com/analogj/scrutiny/webapp/backend/pkg/thresholds"
1213
)
1314

1415
type Smart struct {
@@ -100,7 +101,7 @@ func NewSmartFromInfluxDB(attrs map[string]interface{}) (*Smart, error) {
100101
return &sm, nil
101102
}
102103

103-
//Parse Collector SMART data results and create Smart object (and associated SmartAtaAttribute entries)
104+
// Parse Collector SMART data results and create Smart object (and associated SmartAtaAttribute entries)
104105
func (sm *Smart) FromCollectorSmartInfo(wwn string, info collector.SmartInfo) error {
105106
sm.DeviceWWN = wwn
106107
sm.Date = time.Unix(info.LocalTime.TimeT, 0)
@@ -121,13 +122,13 @@ func (sm *Smart) FromCollectorSmartInfo(wwn string, info collector.SmartInfo) er
121122
} else if sm.DeviceProtocol == pkg.DeviceProtocolNvme {
122123
sm.ProcessNvmeSmartInfo(info.NvmeSmartHealthInformationLog)
123124
} else if sm.DeviceProtocol == pkg.DeviceProtocolScsi {
124-
sm.ProcessScsiSmartInfo(info.ScsiGrownDefectList, info.ScsiErrorCounterLog)
125+
sm.ProcessScsiSmartInfo(info.ScsiGrownDefectList, info.ScsiErrorCounterLog, info.ScsiEnvironmentalReports)
125126
}
126127

127128
return nil
128129
}
129130

130-
//generate SmartAtaAttribute entries from Scrutiny Collector Smart data.
131+
// generate SmartAtaAttribute entries from Scrutiny Collector Smart data.
131132
func (sm *Smart) ProcessAtaSmartInfo(tableItems []collector.AtaSmartAttributesTableItem) {
132133
for _, collectorAttr := range tableItems {
133134
attrModel := SmartAtaAttribute{
@@ -155,7 +156,7 @@ func (sm *Smart) ProcessAtaSmartInfo(tableItems []collector.AtaSmartAttributesTa
155156
}
156157
}
157158

158-
//generate SmartNvmeAttribute entries from Scrutiny Collector Smart data.
159+
// generate SmartNvmeAttribute entries from Scrutiny Collector Smart data.
159160
func (sm *Smart) ProcessNvmeSmartInfo(nvmeSmartHealthInformationLog collector.NvmeSmartHealthInformationLog) {
160161

161162
sm.Attributes = map[string]SmartAttribute{
@@ -185,9 +186,11 @@ func (sm *Smart) ProcessNvmeSmartInfo(nvmeSmartHealthInformationLog collector.Nv
185186
}
186187
}
187188

188-
//generate SmartScsiAttribute entries from Scrutiny Collector Smart data.
189-
func (sm *Smart) ProcessScsiSmartInfo(defectGrownList int64, scsiErrorCounterLog collector.ScsiErrorCounterLog) {
189+
// generate SmartScsiAttribute entries from Scrutiny Collector Smart data.
190+
func (sm *Smart) ProcessScsiSmartInfo(defectGrownList int64, scsiErrorCounterLog collector.ScsiErrorCounterLog, temperature map[string]collector.ScsiTemperatureData) {
190191
sm.Attributes = map[string]SmartAttribute{
192+
"temperature": (&SmartNvmeAttribute{AttributeId: "temperature", Value: getScsiTemperature(temperature), Threshold: -1}).PopulateAttributeStatus(),
193+
191194
"scsi_grown_defect_list": (&SmartScsiAttribute{AttributeId: "scsi_grown_defect_list", Value: defectGrownList, Threshold: 0}).PopulateAttributeStatus(),
192195
"read_errors_corrected_by_eccfast": (&SmartScsiAttribute{AttributeId: "read_errors_corrected_by_eccfast", Value: scsiErrorCounterLog.Read.ErrorsCorrectedByEccfast, Threshold: -1}).PopulateAttributeStatus(),
193196
"read_errors_corrected_by_eccdelayed": (&SmartScsiAttribute{AttributeId: "read_errors_corrected_by_eccdelayed", Value: scsiErrorCounterLog.Read.ErrorsCorrectedByEccdelayed, Threshold: -1}).PopulateAttributeStatus(),
@@ -210,3 +213,12 @@ func (sm *Smart) ProcessScsiSmartInfo(defectGrownList int64, scsiErrorCounterLog
210213
}
211214
}
212215
}
216+
217+
func getScsiTemperature(s map[string]collector.ScsiTemperatureData) int64 {
218+
temp, ok := s["temperature_1"]
219+
if !ok {
220+
return 0
221+
}
222+
223+
return temp.Current
224+
}

0 commit comments

Comments
 (0)