Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Input Plugin Extra Attributes #6079

Merged
merged 14 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Measure smart input plugin Critical Warning attribute as integer
  • Loading branch information
GeorgeMac committed Jul 12, 2019
commit 08f23587ed0e6d5f62c30198543c05208f2f84cd
52 changes: 13 additions & 39 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ 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
Expand Down Expand Up @@ -67,14 +53,6 @@ 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
Expand Down Expand Up @@ -112,6 +90,19 @@ var (
"Error Information Log Entries": {
Name: "Error_Information_Log_Entries",
},
"Critical Warning": {
Name: "Critical_Warning",
Parse: func(fields, _ map[string]interface{}, str string) error {
var value int64
if _, err := fmt.Sscanf(str, "0x%x", &value); err != nil {
return err
}

fields["raw_value"] = value

return nil
},
},
"Available Spare": {
Name: "Available_Spare",
Parse: func(fields, deviceFields map[string]interface{}, str string) error {
Expand Down Expand Up @@ -358,23 +349,6 @@ 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 != "" {
Expand Down
48 changes: 2 additions & 46 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,55 +532,11 @@ func TestGatherNvme(t *testing.T) {
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Warning_Spare_Treshold",
"name": "Critical_Warning",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": true,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Warning_Temperature_Above_or_Under_Threshold",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": false,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Warning_Reliability_Degraded",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": false,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Warning_Read_Only",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": true,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Warning_Volative_Memory_Backup_Failed",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": false,
"raw_value": int64(9),
},
time.Now(),
),
Expand Down