From b6a5db6fdd93bbe2031db9b2cbdcfed41f4b1204 Mon Sep 17 00:00:00 2001 From: Piotr Szczepanik Date: Sun, 24 May 2020 00:19:26 +0200 Subject: [PATCH] Add missing nvme attributes to smart plugin --- plugins/inputs/smart/smart.go | 55 ++++++++++++- plugins/inputs/smart/smart_test.go | 124 ++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index b34174a337cf5..63d16aad3e35e 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -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, }, } ) @@ -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 { diff --git a/plugins/inputs/smart/smart_test.go b/plugins/inputs/smart/smart_test.go index 3ea6e309f4e8d..465ce9317e1e2 100644 --- a/plugins/inputs/smart/smart_test.go +++ b/plugins/inputs/smart/smart_test.go @@ -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": ".", @@ -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(), @@ -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 ` )