Skip to content

Commit

Permalink
Added field tag for WWN
Browse files Browse the repository at this point in the history
Added WWN to both smart_device and smart_attribute measurements. And
added serial_no also to smart_attribute.
  • Loading branch information
rickard-von-essen committed Aug 12, 2017
1 parent c9c7122 commit da606ac
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 64 deletions.
18 changes: 14 additions & 4 deletions plugins/inputs/smart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ smartctl -s on <device>
- `enabled`
- `health`
- `serial_no`
- `wwn`
* Fields:
- `exit_status`
- `health_ok`
Expand All @@ -51,6 +52,8 @@ smartctl -s on <device>
- `flags`
- `id`
- `name`
- `serial_no`
- `wwn`
* Fields:
- `exit_status`
- `raw_value`
Expand All @@ -74,6 +77,14 @@ The `exit_status` field captures the exit status of the smartctl command which
is defined by a bitmask. For the interpretation of the bitmask see the man page for
smartctl.

### Device Names

Device names, e.g., `/dev/sda`, are *not persistent*, and may be
subject to change across reboots or system changes. Instead, you can the
*World Wide Name* (WWN) or serial number to identify devices. On Linux block
devices can be referenced by the WWN in the following location:
`/dev/disk/by-id/`.

## Configuration

```toml
Expand Down Expand Up @@ -118,8 +129,7 @@ the configuration to execute that.

Example output from an _Apple SSD_:
```
> smart_attribute,device=/dev/rdisk0,id=194,name=Temperature_Celsius,flags=-O---K,fail=-,host=STIZ0039.lan exit_status=0i,value=64i,worst=21i,threshold=0i,raw_value=36i 1487632495000000000
> smart_attribute,device=/dev/rdisk0,id=197,name=Current_Pending_Sector,flags=-O---K,fail=-,host=STIZ0039.lan exit_status=0i,value=100i,worst=100i,threshold=0i,raw_value=0i 1487632495000000000
> smart_attribute,device=/dev/rdisk0,id=199,name=UDMA_CRC_Error_Count,flags=-O-RC-,fail=-,host=STIZ0039.lan exit_status=0i,value=200i,worst=200i,threshold=0i,raw_value=0i 1487632495000000000
> smart_device,host=mbpro.local,device=/dev/rdisk0,model=APPLE\ SSD\ SM0512F,serial_no=S1K5NYCD964433,capacity=500277790720,enabled=Enabled temp_c=39i,udma_crc_errors=0i,exit_status=0i,health_ok=true,read_error_rate=0i 1502255921000000000
> smart_attribute,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=199,name=UDMA_CRC_Error_Count,flags=-O-RC-,fail=-,host=mbpro.local,device=/dev/rdisk0 threshold=0i,raw_value=0i,exit_status=0i,value=200i,worst=200i 1502536854000000000
> smart_attribute,device=/dev/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_device,enabled=Enabled,host=mbpro.local,device=/dev/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
```
14 changes: 14 additions & 0 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var (
modelInInfo = regexp.MustCompile("^Device Model:\\s+(.*)$")
// Serial Number: S0X5NZBC422720
serialInInfo = regexp.MustCompile("^Serial Number:\\s+(.*)$")
// LU WWN Device Id: 5 002538 655584d30
wwnInInfo = regexp.MustCompile("^LU WWN Device Id:\\s+(.*)$")
// User Capacity: 251,000,193,024 bytes [251 GB]
usercapacityInInfo = regexp.MustCompile("^User Capacity:\\s+([0-9,]+)\\s+bytes.*$")
// SMART support is: Enabled
Expand Down Expand Up @@ -210,6 +212,11 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, path, nockec
device_tags["serial_no"] = serial[1]
}

wwn := wwnInInfo.FindStringSubmatch(line)
if len(wwn) > 1 {
device_tags["wwn"] = strings.Replace(wwn[1], " ", "", -1)
}

capacity := usercapacityInInfo.FindStringSubmatch(line)
if len(capacity) > 1 {
device_tags["capacity"] = strings.Replace(capacity[1], ",", "", -1)
Expand All @@ -234,6 +241,13 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, path, nockec
fields := make(map[string]interface{})

tags["device"] = strings.Split(device, " ")[0]

if serial, ok := device_tags["serial_no"]; ok {
tags["serial_no"] = serial
}
if wwn, ok := device_tags["wwn"]; ok {
tags["wwn"] = wwn
}
tags["id"] = attr[1]
tags["name"] = attr[2]
tags["flags"] = attr[3]
Expand Down
146 changes: 86 additions & 60 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "1",
"name": "Raw_Read_Error_Rate",
"flags": "-O-RC-",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "1",
"name": "Raw_Read_Error_Rate",
"flags": "-O-RC-",
"fail": "-",
},
},
{
Expand All @@ -105,11 +107,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "5",
"name": "Reallocated_Sector_Ct",
"flags": "PO--CK",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "5",
"name": "Reallocated_Sector_Ct",
"flags": "PO--CK",
"fail": "-",
},
},
{
Expand All @@ -121,11 +125,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "9",
"name": "Power_On_Hours",
"flags": "-O--CK",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "9",
"name": "Power_On_Hours",
"flags": "-O--CK",
"fail": "-",
},
},
{
Expand All @@ -137,11 +143,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "12",
"name": "Power_Cycle_Count",
"flags": "-O--CK",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "12",
"name": "Power_Cycle_Count",
"flags": "-O--CK",
"fail": "-",
},
},
{
Expand All @@ -153,11 +161,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "169",
"name": "Unknown_Attribute",
"flags": "PO--C-",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "169",
"name": "Unknown_Attribute",
"flags": "PO--C-",
"fail": "-",
},
},
{
Expand All @@ -169,11 +179,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "173",
"name": "Wear_Leveling_Count",
"flags": "-O--CK",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "173",
"name": "Wear_Leveling_Count",
"flags": "-O--CK",
"fail": "-",
},
},
{
Expand All @@ -185,11 +197,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "190",
"name": "Airflow_Temperature_Cel",
"flags": "-O---K",
"fail": "Past",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "190",
"name": "Airflow_Temperature_Cel",
"flags": "-O---K",
"fail": "Past",
},
},
{
Expand All @@ -201,11 +215,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "192",
"name": "Power-Off_Retract_Count",
"flags": "-O--C-",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "192",
"name": "Power-Off_Retract_Count",
"flags": "-O--C-",
"fail": "-",
},
},
{
Expand All @@ -217,11 +233,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "194",
"name": "Temperature_Celsius",
"flags": "-O---K",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "194",
"name": "Temperature_Celsius",
"flags": "-O---K",
"fail": "-",
},
},
{
Expand All @@ -233,11 +251,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "197",
"name": "Current_Pending_Sector",
"flags": "-O---K",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "197",
"name": "Current_Pending_Sector",
"flags": "-O---K",
"fail": "-",
},
},
{
Expand All @@ -249,11 +269,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "199",
"name": "UDMA_CRC_Error_Count",
"flags": "-O-RC-",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "199",
"name": "UDMA_CRC_Error_Count",
"flags": "-O-RC-",
"fail": "-",
},
},
{
Expand All @@ -265,11 +287,13 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"id": "240",
"name": "Head_Flying_Hours",
"flags": "------",
"fail": "-",
"device": "/dev/ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "240",
"name": "Head_Flying_Hours",
"flags": "------",
"fail": "-",
},
},
}
Expand All @@ -296,6 +320,7 @@ func TestGatherAttributes(t *testing.T) {
"device": "/dev/ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
},
Expand Down Expand Up @@ -341,6 +366,7 @@ func TestGatherNoAttributes(t *testing.T) {
"device": "/dev/ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"enabled": "Enabled",
"capacity": "251000193024",
},
Expand Down

0 comments on commit da606ac

Please sign in to comment.