Skip to content

Commit

Permalink
Add device tags to smart_attributes (influxdata#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcv81 authored and bitcharmer committed Oct 18, 2019
1 parent 0981979 commit 7914c13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
10 changes: 6 additions & 4 deletions plugins/inputs/smart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ Defaults!SMARTCTL !logfile, !syslog, !pam_session
- tags:
- capacity
- device
- device_model
- enabled
- health
- model
- serial_no
- wwn
- fields:
Expand All @@ -104,10 +103,13 @@ Defaults!SMARTCTL !logfile, !syslog, !pam_session

- smart_attribute:
- tags:
- capacity
- device
- enabled
- fail
- flags
- id
- model
- name
- serial_no
- wwn
Expand Down Expand Up @@ -163,6 +165,6 @@ smartctl --info --health --attributes --tolerance=verypermissive --nocheck NOCHE

```
smart_device,enabled=Enabled,host=mbpro.local,device=rdisk0,model=APPLE\ SSD\ SM0512F,serial_no=S1K5NYCD964433,wwn=5002538655584d30,capacity=500277790720 udma_crc_errors=0i,exit_status=0i,health_ok=true,read_error_rate=0i,temp_c=40i 1502536854000000000
smart_attribute,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=199,name=UDMA_CRC_Error_Count,flags=-O-RC-,fail=-,host=mbpro.local,device=rdisk0 threshold=0i,raw_value=0i,exit_status=0i,value=200i,worst=200i 1502536854000000000
smart_attribute,device=rdisk0,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=240,name=Unknown_SSD_Attribute,flags=-O---K,fail=-,host=mbpro.local exit_status=0i,value=100i,worst=100i,threshold=0i,raw_value=0i 1502536854000000000
smart_attribute,capacity=500277790720,device=rdisk0,enabled=Enabled,fail=-,flags=-O-RC-,host=mbpro.local,id=199,model=APPLE\ SSD\ SM0512F,name=UDMA_CRC_Error_Count,serial_no=S1K5NYCD964433,wwn=5002538655584d30 exit_status=0i,raw_value=0i,threshold=0i,value=200i,worst=200i 1502536854000000000
smart_attribute,capacity=500277790720,device=rdisk0,enabled=Enabled,fail=-,flags=-O---K,host=mbpro.local,id=199,model=APPLE\ SSD\ SM0512F,name=Unknown_SSD_Attribute,serial_no=S1K5NYCD964433,wwn=5002538655584d30 exit_status=0i,raw_value=0i,threshold=0i,value=100i,worst=100i 1502536854000000000
```
13 changes: 5 additions & 8 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,11 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, collectAttributes bool, smart
fields := make(map[string]interface{})

if collectAttributes {
deviceNode := strings.Split(device, " ")[0]
tags["device"] = path.Base(deviceNode)

if serial, ok := deviceTags["serial_no"]; ok {
tags["serial_no"] = serial
}
if wwn, ok := deviceTags["wwn"]; ok {
tags["wwn"] = wwn
keys := [...]string{"device", "model", "serial_no", "wwn", "capacity", "enabled"}
for _, key := range keys {
if value, ok := deviceTags[key]; ok {
tags[key] = value
}
}
}

Expand Down
43 changes: 43 additions & 0 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "1",
"name": "Raw_Read_Error_Rate",
"flags": "-O-RC-",
Expand All @@ -67,8 +70,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "5",
"name": "Reallocated_Sector_Ct",
"flags": "PO--CK",
Expand All @@ -85,8 +91,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "9",
"name": "Power_On_Hours",
"flags": "-O--CK",
Expand All @@ -103,8 +112,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "12",
"name": "Power_Cycle_Count",
"flags": "-O--CK",
Expand All @@ -121,8 +133,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "169",
"name": "Unknown_Attribute",
"flags": "PO--C-",
Expand All @@ -139,8 +154,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "173",
"name": "Wear_Leveling_Count",
"flags": "-O--CK",
Expand All @@ -157,8 +175,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "190",
"name": "Airflow_Temperature_Cel",
"flags": "-O---K",
Expand All @@ -175,8 +196,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "192",
"name": "Power-Off_Retract_Count",
"flags": "-O--C-",
Expand All @@ -193,8 +217,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "194",
"name": "Temperature_Celsius",
"flags": "-O---K",
Expand All @@ -211,8 +238,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "197",
"name": "Current_Pending_Sector",
"flags": "-O---K",
Expand All @@ -229,8 +259,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "199",
"name": "UDMA_CRC_Error_Count",
"flags": "-O-RC-",
Expand All @@ -247,8 +280,11 @@ func TestGatherAttributes(t *testing.T) {
},
map[string]string{
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
"id": "240",
"name": "Head_Flying_Hours",
"flags": "------",
Expand Down Expand Up @@ -466,6 +502,7 @@ func TestGatherNvme(t *testing.T) {
"id": "9",
"name": "Power_On_Hours",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 6038,
Expand All @@ -478,6 +515,7 @@ func TestGatherNvme(t *testing.T) {
"id": "12",
"name": "Power_Cycle_Count",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 472,
Expand All @@ -489,6 +527,7 @@ func TestGatherNvme(t *testing.T) {
"device": ".",
"name": "Media_and_Data_Integrity_Errors",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 0,
Expand All @@ -500,6 +539,7 @@ func TestGatherNvme(t *testing.T) {
"device": ".",
"name": "Error_Information_Log_Entries",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 119699,
Expand All @@ -511,6 +551,7 @@ func TestGatherNvme(t *testing.T) {
"device": ".",
"name": "Available_Spare",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 100,
Expand All @@ -523,6 +564,7 @@ func TestGatherNvme(t *testing.T) {
"id": "194",
"name": "Temperature_Celsius",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": 38,
Expand All @@ -534,6 +576,7 @@ func TestGatherNvme(t *testing.T) {
"device": ".",
"name": "Critical_Warning",
"serial_no": "D704940282?",
"model": "TS128GMTE850",
},
map[string]interface{}{
"raw_value": int64(9),
Expand Down

0 comments on commit 7914c13

Please sign in to comment.