Skip to content

Commit

Permalink
Add vendor and scsi error counter logs
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Apr 2, 2024
1 parent dc9a442 commit 22967b1
Showing 7 changed files with 183 additions and 0 deletions.
48 changes: 48 additions & 0 deletions plugins/inputs/smartctl/smartctl_device.go
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@ func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, devic
"serial": device.SerialNumber,
}

if device.Vendor != "" {
tags["vendor"] = device.Vendor
}

// The JSON WWN is in decimal and needs to be converted to hex
if device.Wwn.ID != 0 && device.Wwn.Naa != 0 && device.Wwn.Oui != 0 {
tags["wwn"] = fmt.Sprintf("%01x%06x%09x", device.Wwn.Naa, device.Wwn.Oui, device.Wwn.ID)
@@ -99,5 +103,49 @@ func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, devic
acc.AddFields("smartctl_attributes", fields, attributeTags, t)
}

// Check for SCSI error counter entries
if device.Device.Type == "scsi" {
counterTags := make(map[string]string, len(tags)+1)
for k, v := range tags {
counterTags[k] = v
}

counterTags["page"] = "read"
fields := map[string]interface{}{
"errors_corrected_by_eccfast": device.ScsiErrorCounterLog.Read.ErrorsCorrectedByEccfast,
"errors_corrected_by_eccdelayed": device.ScsiErrorCounterLog.Read.ErrorsCorrectedByEccdelayed,
"errors_corrected_by_rereads_rewrites": device.ScsiErrorCounterLog.Read.ErrorsCorrectedByRereadsRewrites,
"total_errors_corrected": device.ScsiErrorCounterLog.Read.TotalErrorsCorrected,
"correction_algorithm_invocations": device.ScsiErrorCounterLog.Read.CorrectionAlgorithmInvocations,
"gigabytes_processed": device.ScsiErrorCounterLog.Read.GigabytesProcessed,
"total_uncorrected_errors": device.ScsiErrorCounterLog.Read.TotalUncorrectedErrors,
}
acc.AddFields("smartctl_scsi_error_counter_log", fields, counterTags, t)

counterTags["page"] = "write"
fields = map[string]interface{}{
"errors_corrected_by_eccfast": device.ScsiErrorCounterLog.Write.ErrorsCorrectedByEccfast,
"errors_corrected_by_eccdelayed": device.ScsiErrorCounterLog.Write.ErrorsCorrectedByEccdelayed,
"errors_corrected_by_rereads_rewrites": device.ScsiErrorCounterLog.Write.ErrorsCorrectedByRereadsRewrites,
"total_errors_corrected": device.ScsiErrorCounterLog.Write.TotalErrorsCorrected,
"correction_algorithm_invocations": device.ScsiErrorCounterLog.Write.CorrectionAlgorithmInvocations,
"gigabytes_processed": device.ScsiErrorCounterLog.Write.GigabytesProcessed,
"total_uncorrected_errors": device.ScsiErrorCounterLog.Write.TotalUncorrectedErrors,
}
acc.AddFields("smartctl_scsi_error_counter_log", fields, counterTags, t)

counterTags["page"] = "verify"
fields = map[string]interface{}{
"errors_corrected_by_eccfast": device.ScsiErrorCounterLog.Verify.ErrorsCorrectedByEccfast,
"errors_corrected_by_eccdelayed": device.ScsiErrorCounterLog.Verify.ErrorsCorrectedByEccdelayed,
"errors_corrected_by_rereads_rewrites": device.ScsiErrorCounterLog.Verify.ErrorsCorrectedByRereadsRewrites,
"total_errors_corrected": device.ScsiErrorCounterLog.Verify.TotalErrorsCorrected,
"correction_algorithm_invocations": device.ScsiErrorCounterLog.Verify.CorrectionAlgorithmInvocations,
"gigabytes_processed": device.ScsiErrorCounterLog.Verify.GigabytesProcessed,
"total_uncorrected_errors": device.ScsiErrorCounterLog.Verify.TotalUncorrectedErrors,
}
acc.AddFields("smartctl_scsi_error_counter_log", fields, counterTags, t)
}

return nil
}
31 changes: 31 additions & 0 deletions plugins/inputs/smartctl/smartctl_json.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ type smartctlDeviceJSON struct {
Type string `json:"type"`
Protocol string `json:"protocol"`
} `json:"device"`
Vendor string `json:"vendor"`
Product string `json:"product"`
ModelFamily string `json:"model_family"`
ModelName string `json:"model_name"`
SerialNumber string `json:"serial_number"`
@@ -83,6 +85,35 @@ type smartctlDeviceJSON struct {
} `json:"raw"`
} `json:"table"`
} `json:"ata_smart_attributes"`
ScsiErrorCounterLog struct {
Read struct {
ErrorsCorrectedByEccfast int `json:"errors_corrected_by_eccfast"`
ErrorsCorrectedByEccdelayed int `json:"errors_corrected_by_eccdelayed"`
ErrorsCorrectedByRereadsRewrites int `json:"errors_corrected_by_rereads_rewrites"`
TotalErrorsCorrected int `json:"total_errors_corrected"`
CorrectionAlgorithmInvocations int `json:"correction_algorithm_invocations"`
GigabytesProcessed string `json:"gigabytes_processed"`
TotalUncorrectedErrors int `json:"total_uncorrected_errors"`
} `json:"read"`
Write struct {
ErrorsCorrectedByEccfast int `json:"errors_corrected_by_eccfast"`
ErrorsCorrectedByEccdelayed int `json:"errors_corrected_by_eccdelayed"`
ErrorsCorrectedByRereadsRewrites int `json:"errors_corrected_by_rereads_rewrites"`
TotalErrorsCorrected int `json:"total_errors_corrected"`
CorrectionAlgorithmInvocations int `json:"correction_algorithm_invocations"`
GigabytesProcessed string `json:"gigabytes_processed"`
TotalUncorrectedErrors int `json:"total_uncorrected_errors"`
} `json:"write"`
Verify struct {
ErrorsCorrectedByEccfast int `json:"errors_corrected_by_eccfast"`
ErrorsCorrectedByEccdelayed int `json:"errors_corrected_by_eccdelayed"`
ErrorsCorrectedByRereadsRewrites int `json:"errors_corrected_by_rereads_rewrites"`
TotalErrorsCorrected int `json:"total_errors_corrected"`
CorrectionAlgorithmInvocations int `json:"correction_algorithm_invocations"`
GigabytesProcessed string `json:"gigabytes_processed"`
TotalUncorrectedErrors int `json:"total_uncorrected_errors"`
} `json:"verify"`
} `json:"scsi_error_counter_log"`
}

type smartctlScanJSON struct {
2 changes: 2 additions & 0 deletions plugins/inputs/smartctl/smartctl_test.go
Original file line number Diff line number Diff line change
@@ -181,6 +181,8 @@ func TestDeviceHelperProcess(t *testing.T) {
filename = "testcases_device/usb/response.json"
} else if slices.Contains(args, "/dev/bus/6") {
filename = "testcases_device/megaraid/response.json"
} else if slices.Contains(args, "/dev/sdb") {
filename = "testcases_device/scsi/response.json"
} else {
fmt.Fprint(os.Stdout, "unknown filename")
os.Exit(42) //nolint:revive // os.Exit called intentionally
1 change: 1 addition & 0 deletions plugins/inputs/smartctl/testcases_device/scsi/device
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/sdb
1 change: 1 addition & 0 deletions plugins/inputs/smartctl/testcases_device/scsi/deviceType
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scsi
4 changes: 4 additions & 0 deletions plugins/inputs/smartctl/testcases_device/scsi/expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
smartctl,model=XXXX\ XX0000NM123,name=/dev/sdb,serial=XXXXXXX,type=scsi,vendor=XXXXXXX capacity=13715978077777i,firmware="",health_ok=true,temperature=24i 1712071085987864368
smartctl_scsi_error_counter_log,model=XXXX\ XX0000NM123,name=/dev/sdb,serial=XXXXXXX,type=scsi,page=read,vendor=XXXXXXX correction_algorithm_invocations=0i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=1i,errors_corrected_by_rereads_rewrites=5i,gigabytes_processed="315926.142",total_errors_corrected=3i,total_uncorrected_errors=0i 1712071085987864368
smartctl_scsi_error_counter_log,model=XXXX\ XX0000NM123,name=/dev/sdb,serial=XXXXXXX,type=scsi,page=write,vendor=XXXXXXX correction_algorithm_invocations=20i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=0i,errors_corrected_by_rereads_rewrites=20i,gigabytes_processed="132513.233",total_errors_corrected=20i,total_uncorrected_errors=0i 1712071085987864368
smartctl_scsi_error_counter_log,model=XXXX\ XX0000NM123,name=/dev/sdb,serial=XXXXXXX,type=scsi,page=verify,vendor=XXXXXXX correction_algorithm_invocations=0i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=12i,errors_corrected_by_rereads_rewrites=0i,gigabytes_processed="1437.032",total_errors_corrected=3i,total_uncorrected_errors=0i 1712071085987864368
96 changes: 96 additions & 0 deletions plugins/inputs/smartctl/testcases_device/scsi/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"json_format_version": [
1,
0
],
"smartctl": {
"version": [
7,
2
],
"svn_revision": "5123",
"platform_info": "x86_64-linux-4.12.0-1-amd64",
"build_info": "(local build)",
"argv": [
"smartctl",
"--json",
"--all",
"/dev/sdb",
"--device",
"scsi"
],
"exit_status": 0
},
"device": {
"name": "/dev/sdb",
"info_name": "/dev/sdb",
"type": "scsi",
"protocol": "SCSI"
},
"vendor": "XXXXXXX",
"product": "XXXX000OOOO",
"model_name": "XXXX XX0000NM123",
"revision": "RSL5",
"scsi_version": "SPC-5",
"user_capacity": {
"blocks": 26789019888,
"bytes": 13715978077777
},
"logical_block_size": 512,
"physical_block_size": 4096,
"rotation_rate": 7200,
"form_factor": {
"scsi_value": 3,
"name": "3.5 inches"
},
"serial_number": "XXXXXXX",
"device_type": {
"scsi_value": 0,
"name": "disk"
},
"local_time": {
"time_t": 1711977687,
"asctime": "Sun Mar 31 13:21:27 2024 UTC"
},
"smart_status": {
"passed": true
},
"temperature": {
"current": 24,
"drive_trip": 60
},
"power_on_time": {
"hours": 32978,
"minutes": 46
},
"scsi_grown_defect_list": 0,
"scsi_error_counter_log": {
"read": {
"errors_corrected_by_eccfast": 1,
"errors_corrected_by_eccdelayed": 0,
"errors_corrected_by_rereads_rewrites": 5,
"total_errors_corrected": 3,
"correction_algorithm_invocations": 0,
"gigabytes_processed": "315926.142",
"total_uncorrected_errors": 0
},
"write": {
"errors_corrected_by_eccfast": 0,
"errors_corrected_by_eccdelayed": 0,
"errors_corrected_by_rereads_rewrites": 20,
"total_errors_corrected": 20,
"correction_algorithm_invocations": 20,
"gigabytes_processed": "132513.233",
"total_uncorrected_errors": 0
},
"verify": {
"errors_corrected_by_eccfast": 12,
"errors_corrected_by_eccdelayed": 0,
"errors_corrected_by_rereads_rewrites": 0,
"total_errors_corrected": 3,
"correction_algorithm_invocations": 0,
"gigabytes_processed": "1437.032",
"total_uncorrected_errors": 0
}
}
}

0 comments on commit 22967b1

Please sign in to comment.