From 625fbd202fbb04cdd0dd91a3fcab46be85e4fc2c Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Tue, 9 Jul 2019 11:09:31 +0100 Subject: [PATCH] Add smart input plugin nvme critical warning fields --- plugins/inputs/smart/smart.go | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index ec9b71f7..9f3f4755 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -18,6 +18,20 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) +const ( + // NVME Critical Warnings as per https://nvmexpress.org + // critical warning spare threshold + criticalWarningST uint8 = 1 << iota + // critical warning temperature above or under threshold + criticalWarningTAUT + // critical warning reliability degraded + criticalWarningRD + // critical warning read only + criticalWarningRO + // critical warning volatile backup memory failed + criticalWarningVMBF +) + var ( // Device Model: APPLE SSD SM256E // Product: HUH721212AL5204 @@ -53,6 +67,14 @@ var ( "199": "udma_crc_errors", } + nvmeCriticalWarnings = map[uint8]string{ + criticalWarningST: "Critical_Warning_Spare_Treshold", + criticalWarningTAUT: "Critical_Warning_Temperature_Above_or_Under_Threshold", + criticalWarningRD: "Critical_Warning_Reliability_Degraded", + criticalWarningRO: "Critical_Warning_Read_Only", + criticalWarningVMBF: "Critical_Warning_Volative_Memory_Backup_Failed", + } + sasNvmeAttributes = map[string]struct { ID string Name string @@ -336,6 +358,23 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, collectAttributes bool, smart } else { if collectAttributes { if matches := sasNvmeAttr.FindStringSubmatch(line); len(matches) > 2 { + if matches[1] == "Critical Warning" { + var flags uint8 + if _, err := fmt.Sscanf(matches[2], "0x%x", &flags); err != nil { + continue + } + + for flag, name := range nvmeCriticalWarnings { + tags["name"] = name + + acc.AddFields("smart_attribute", map[string]interface{}{ + "raw_value": flags&flag > 0, + }, tags) + } + + continue + } + if attr, ok := sasNvmeAttributes[matches[1]]; ok { tags["name"] = attr.Name if attr.ID != "" {