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

Add missing nvme attributes to smart plugin #7575

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
55 changes: 51 additions & 4 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,48 @@ var (
},
},
"Available Spare": {
Name: "Available_Spare",
Parse: func(fields, deviceFields map[string]interface{}, str string) error {
return parseCommaSeparatedInt(fields, deviceFields, strings.TrimSuffix(str, "%"))
},
Name: "Available_Spare",
Parse: parsePercentageInt,
},
"Available Spare Threshold": {
Name: "Available_Spare_Threshold",
Parse: parsePercentageInt,
},
"Percentage Used": {
Name: "Percentage_Used",
Parse: parsePercentageInt,
},
"Data Units Read": {
Name: "Data_Units_Read",
Parse: parseDataUnits,
},
"Data Units Written": {
Name: "Data_Units_Written",
Parse: parseDataUnits,
},
"Host Read Commands": {
Name: "Host_Read_Commands",
Parse: parseCommaSeparatedInt,
},
"Host Write Commands": {
Name: "Host_Write_Commands",
Parse: parseCommaSeparatedInt,
},
"Controller Busy Time": {
Name: "Controller_Busy_Time",
Parse: parseCommaSeparatedInt,
},
"Unsafe Shutdowns": {
Name: "Unsafe_Shutdowns",
Parse: parseCommaSeparatedInt,
},
"Warning Comp. Temperature Time": {
Name: "Warning_Temperature_Time",
Parse: parseCommaSeparatedInt,
},
"Critical Comp. Temperature Time": {
Name: "Critical_Temperature_Time",
Parse: parseCommaSeparatedInt,
},
}
)
Expand Down Expand Up @@ -432,6 +470,15 @@ func parseCommaSeparatedInt(fields, _ map[string]interface{}, str string) error
return nil
}

func parsePercentageInt(fields, deviceFields map[string]interface{}, str string) error {
return parseCommaSeparatedInt(fields, deviceFields, strings.TrimSuffix(str, "%"))
}

func parseDataUnits(fields, deviceFields map[string]interface{}, str string) error {
units := strings.Fields(str)[0]
return parseCommaSeparatedInt(fields, deviceFields, units)
}

func parseTemperature(fields, deviceFields map[string]interface{}, str string) error {
var temp int64
if _, err := fmt.Sscanf(str, "%d C", &temp); err != nil {
Expand Down
124 changes: 122 additions & 2 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,18 @@ func TestGatherNvme(t *testing.T) {
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Available_Spare_Threshold",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 10,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
Expand All @@ -636,6 +648,114 @@ func TestGatherNvme(t *testing.T) {
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Percentage_Used",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(16),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Data_Units_Read",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(11836935),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Data_Units_Written",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(62288091),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Host_Read_Commands",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(135924188),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Host_Write_Commands",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(7715573429),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Controller_Busy_Time",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(4042),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Unsafe_Shutdowns",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(355),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Warning_Temperature_Time",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(11),
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"name": "Critical_Temperature_Time",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(7),
},
time.Now(),
),
}

testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(),
Expand Down Expand Up @@ -1089,7 +1209,7 @@ Power On Hours: 6,038
Unsafe Shutdowns: 355
Media and Data Integrity Errors: 0
Error Information Log Entries: 119,699
Warning Comp. Temperature Time: 0
Critical Comp. Temperature Time: 0
Warning Comp. Temperature Time: 11
Critical Comp. Temperature Time: 7
`
)