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

fix(inputs.smartctl): Add additional fields #15332

Merged
merged 2 commits into from
May 10, 2024
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
47 changes: 46 additions & 1 deletion plugins/inputs/smartctl/smartctl_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, devic
tags := map[string]string{
"name": device.Device.Name,
"type": device.Device.Type,
"model": device.ModelName,
"serial": device.SerialNumber,
}

if device.ModelName != "" {
tags["model"] = device.ModelName
}
if device.Vendor != "" {
tags["vendor"] = device.Vendor
}
Expand All @@ -62,6 +64,49 @@ func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, devic
"firmware": device.FirmwareVersion,
}

if device.SCSIVendor != "" {
fields["scsi_vendor"] = device.SCSIVendor
}
if device.SCSIModelName != "" {
fields["scsi_model"] = device.SCSIModelName
}
if device.SCSIRevision != "" {
fields["scsi_revision"] = device.SCSIRevision
}
if device.SCSIVersion != "" {
fields["scsi_version"] = device.SCSIVersion
}
if device.SCSITransportProtocol.Name != "" {
fields["scsi_transport_protocol"] = device.SCSITransportProtocol.Name
}
if device.SCSIProtectionType != 0 {
fields["scsi_protection_type"] = device.SCSIProtectionType
}
if device.SCSIProtectionIntervalBytesPerLB != 0 {
fields["scsi_protection_interval_bytes_per_lb"] = device.SCSIProtectionIntervalBytesPerLB
}
if device.SCSIGrownDefectList != 0 {
fields["scsi_grown_defect_list"] = device.SCSIGrownDefectList
}
if device.LogicalBlockSize != 0 {
fields["logical_block_size"] = device.LogicalBlockSize
}
if device.RotationRate != 0 {
fields["rotation_rate"] = device.RotationRate
}
if device.SCSIStartStopCycleCounter.SpecifiedCycleCountOverDeviceLifetime != 0 {
fields["specified_cycle_count_over_device_lifetime"] = device.SCSIStartStopCycleCounter.SpecifiedCycleCountOverDeviceLifetime
}
if device.SCSIStartStopCycleCounter.AccumulatedStartStopCycles != 0 {
fields["accumulated_start_stop_cycles"] = device.SCSIStartStopCycleCounter.AccumulatedStartStopCycles
}
if device.PowerOnTime.Hours != 0 {
fields["power_on_hours"] = device.PowerOnTime.Hours
}
if device.PowerOnTime.Minutes != 0 {
fields["power_on_minutes"] = device.PowerOnTime.Minutes
}

// Add NVMe specific fields
if device.Device.Type == "nvme" {
fields["critical_warning"] = device.NvmeSmartHealthInformationLog.CriticalWarning
Expand Down
34 changes: 27 additions & 7 deletions plugins/inputs/smartctl/smartctl_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,33 @@ 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"`
FirmwareVersion string `json:"firmware_version"`
Wwn struct {
Vendor string `json:"vendor"`
Product string `json:"product"`
ModelFamily string `json:"model_family"`
ModelName string `json:"model_name"`
SerialNumber string `json:"serial_number"`
FirmwareVersion string `json:"firmware_version"`
SCSIVendor string `json:"scsi_vendor"`
SCSIModelName string `json:"scsi_model_name"`
SCSIRevision string `json:"scsi_revision"`
SCSIVersion string `json:"scsi_version"`
SCSIProtectionType int `json:"scsi_protection_type"`
SCSIProtectionIntervalBytesPerLB int `json:"scsi_protection_interval_bytes_per_lb"`
SCSIGrownDefectList int `json:"scsi_grown_defect_list"`
LogicalBlockSize int `json:"logical_block_size"`
RotationRate int `json:"rotation_rate"`
SCSITransportProtocol struct {
Name string `json:"name"`
} `json:"scsi_transport_protocol"`
SCSIStartStopCycleCounter struct {
SpecifiedCycleCountOverDeviceLifetime int `json:"specified_cycle_count_over_device_lifetime"`
AccumulatedStartStopCycles int `json:"accumulated_start_stop_cycles"`
} `json:"scsi_start_stop_cycle_counter"`
PowerOnTime struct {
Hours int `json:"hours"`
Minutes int `json:"minutes"`
} `json:"power_on_time"`
Wwn struct {
Naa int `json:"naa"`
Oui int `json:"oui"`
ID int64 `json:"id"`
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/smartctl/smartctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func TestDeviceHelperProcess(t *testing.T) {
filename = "testcases_device/megaraid/response.json"
} else if slices.Contains(args, "/dev/sdb") {
filename = "testcases_device/scsi/response.json"
} else if slices.Contains(args, "/dev/sdaa") {
filename = "testcases_device/scsi_extended/response.json"
} else {
fmt.Fprint(os.Stdout, "unknown filename")
os.Exit(42) //nolint:revive // os.Exit called intentionally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smartctl,model=ST6000NM0115-1YZ110,name=/dev/bus/6,serial=ZAD2C11G,type=sat+megaraid\,14,wwn=5000c500a496983d capacity=6001175126016i,firmware="SN04",health_ok=true,temperature=25i 1711726425026052398
smartctl,model=ST6000NM0115-1YZ110,name=/dev/bus/6,serial=ZAD2C11G,type=sat+megaraid\,14,wwn=5000c500a496983d capacity=6001175126016i,firmware="SN04",health_ok=true,logical_block_size=512i,power_on_hours=44316i,rotation_rate=7200i,temperature=25i 1711726425026052398
smartctl_attributes,model=ST6000NM0115-1YZ110,name=Raw_Read_Error_Rate,serial=ZAD2C11G,type=sat+megaraid\,14,wwn=5000c500a496983d raw_value=181426040i,threshold=44i,value=83i,worst=64i 1711726425026052398
smartctl_attributes,model=ST6000NM0115-1YZ110,name=Spin_Up_Time,serial=ZAD2C11G,type=sat+megaraid\,14,wwn=5000c500a496983d raw_value=0i,threshold=0i,value=91i,worst=91i 1711726425026052398
smartctl_attributes,model=ST6000NM0115-1YZ110,name=Start_Stop_Count,serial=ZAD2C11G,type=sat+megaraid\,14,wwn=5000c500a496983d raw_value=62i,threshold=20i,value=100i,worst=100i 1711726425026052398
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/smartctl/testcases_device/nvme/expected.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
smartctl,model=Sabrent\ Rocket\ 4.0\ 1TB,name=/dev/nvme0,serial=6D1107091C9583054511,type=nvme available_spare=100i,available_spare_threshold=5i,capacity=1000204886016i,controller_busy_time=1635i,critical_comp_time=0i,critical_warning=0i,data_units_read=28337502i,data_units_written=76471882i,firmware="RKT401.3",health_ok=true,host_reads=294243226i,host_writes=733021025i,media_errors=0i,num_err_log_entries=4871i,percentage_used=4i,power_cycles=1815i,power_on_hours=8733i,temperature=48i,unsafe_shutdowns=39i,warning_temp_time=0i 1711480345635747372
smartctl,model=Sabrent\ Rocket\ 4.0\ 1TB,name=/dev/nvme0,serial=6D1107091C9583054511,type=nvme available_spare=100i,available_spare_threshold=5i,capacity=1000204886016i,controller_busy_time=1635i,critical_comp_time=0i,critical_warning=0i,data_units_read=28337502i,data_units_written=76471882i,firmware="RKT401.3",health_ok=true,host_reads=294243226i,host_writes=733021025i,media_errors=0i,num_err_log_entries=4871i,percentage_used=4i,power_cycles=1815i,power_on_hours=8733i,temperature=48i,unsafe_shutdowns=39i,warning_temp_time=0i,logical_block_size=512i 1711480345635747372
2 changes: 1 addition & 1 deletion plugins/inputs/smartctl/testcases_device/scsi/expected.out
Original file line number Diff line number Diff line change
@@ -1,4 +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,model=XXXX\ XX0000NM123,name=/dev/sdb,serial=XXXXXXX,type=scsi,vendor=XXXXXXX capacity=13715978077777i,firmware="",health_ok=true,logical_block_size=512i,power_on_hours=32978i,power_on_minutes=46i,rotation_rate=7200i,scsi_version="SPC-5",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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/sdaa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
smartctl,name=/dev/sdaa,serial=XYZZZZ,type=scsi accumulated_start_stop_cycles=220i,capacity=13715978079776i,firmware="",health_ok=true,logical_block_size=512i,power_on_hours=34222i,power_on_minutes=9i,rotation_rate=7200i,scsi_model="SEAGATE ST0000000",scsi_protection_interval_bytes_per_lb=8i,scsi_protection_type=2i,scsi_revision="RSL5",scsi_transport_protocol="SAS (SPL-4)",scsi_vendor="XYZZZZZZ",scsi_version="SPC-5",specified_cycle_count_over_device_lifetime=50000i,temperature=24i 1715282104914128775
smartctl_scsi_error_counter_log,name=/dev/sdaa,page=read,serial=XYZZZZ,type=scsi correction_algorithm_invocations=0i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=0i,errors_corrected_by_rereads_rewrites=0i,gigabytes_processed="316009.846",total_errors_corrected=0i,total_uncorrected_errors=0i 1715282104914128775
smartctl_scsi_error_counter_log,name=/dev/sdaa,page=write,serial=XYZZZZ,type=scsi correction_algorithm_invocations=20i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=0i,errors_corrected_by_rereads_rewrites=20i,gigabytes_processed="132824.923",total_errors_corrected=20i,total_uncorrected_errors=0i 1715282104914128775
smartctl_scsi_error_counter_log,name=/dev/sdaa,page=verify,serial=XYZZZZ,type=scsi correction_algorithm_invocations=0i,errors_corrected_by_eccdelayed=0i,errors_corrected_by_eccfast=0i,errors_corrected_by_rereads_rewrites=0i,gigabytes_processed="1467.278",total_errors_corrected=0i,total_uncorrected_errors=0i 1715282104914128775
196 changes: 196 additions & 0 deletions plugins/inputs/smartctl/testcases_device/scsi_extended/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"json_format_version": [
1,
0
],
"smartctl": {
"version": [
7,
4
],
"pre_release": false,
"svn_revision": "6328",
"platform_info": "x86_64-linux-4.14.0-1-amd64",
"build_info": "(local build)",
"argv": [
"smartctl",
"--json",
"--all",
"/dev/sdaa",
"--device",
"scsi"
],
"exit_status": 0
},
"local_time": {
"time_t": 1712853808,
"asctime": "Thu Apr 11 16:43:28 2024 UTC"
},
"device": {
"name": "/dev/sdaa",
"info_name": "/dev/sdaa",
"type": "scsi",
"protocol": "SCSI"
},
"scsi_vendor": "XYZZZZZZ",
"scsi_product": "ST100000000",
"scsi_model_name": "SEAGATE ST0000000",
"scsi_revision": "RSL5",
"scsi_version": "SPC-5",
"user_capacity": {
"blocks": 26789019748,
"bytes": 13715978079776
},
"logical_block_size": 512,
"physical_block_size": 4096,
"scsi_protection_type": 2,
"scsi_protection_interval_bytes_per_lb": 8,
"scsi_lb_provisioning": {
"name": "fully provisioned",
"value": 0,
"management_enabled": {
"name": "LBPME",
"value": 0
},
"read_zeros": {
"name": "LBPRZ",
"value": 0
}
},
"rotation_rate": 7200,
"form_factor": {
"scsi_value": 2,
"name": "3.5 inches"
},
"logical_unit_id": "0x5000cb0847",
"serial_number": "XYZZZZ",
"device_type": {
"scsi_terminology": "Peripheral Device Type [PDT]",
"scsi_value": 0,
"name": "disk"
},
"scsi_transport_protocol": {
"name": "SAS (SPL-4)",
"value": 6
},
"smart_support": {
"available": true,
"enabled": true
},
"temperature_warning": {
"enabled": true
},
"smart_status": {
"passed": true
},
"temperature": {
"current": 24,
"drive_trip": 60
},
"power_on_time": {
"hours": 34222,
"minutes": 9
},
"scsi_start_stop_cycle_counter": {
"year_of_manufacture": "2019",
"week_of_manufacture": "35",
"specified_cycle_count_over_device_lifetime": 50000,
"accumulated_start_stop_cycles": 220,
"specified_load_unload_count_over_device_lifetime": 600000,
"accumulated_load_unload_cycles": 1606
},
"scsi_grown_defect_list": 0,
"seagate_farm_log": {
"supported": true
},
"scsi_error_counter_log": {
"read": {
"errors_corrected_by_eccfast": 0,
"errors_corrected_by_eccdelayed": 0,
"errors_corrected_by_rereads_rewrites": 0,
"total_errors_corrected": 0,
"correction_algorithm_invocations": 0,
"gigabytes_processed": "316009.846",
"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": "132824.923",
"total_uncorrected_errors": 0
},
"verify": {
"errors_corrected_by_eccfast": 0,
"errors_corrected_by_eccdelayed": 0,
"errors_corrected_by_rereads_rewrites": 0,
"total_errors_corrected": 0,
"correction_algorithm_invocations": 0,
"gigabytes_processed": "1467.278",
"total_uncorrected_errors": 0
}
},
"scsi_self_test_0": {
"code": {
"value": 2,
"string": "Background long"
},
"result": {
"value": 0,
"string": "Completed"
},
"power_on_time": {
"hours": 90,
"aka": "accumulated_power_on_hours"
}
},
"scsi_self_test_1": {
"code": {
"value": 2,
"string": "Background long"
},
"result": {
"value": 0,
"string": "Completed"
},
"power_on_time": {
"hours": 66,
"aka": "accumulated_power_on_hours"
}
},
"scsi_self_test_2": {
"code": {
"value": 7,
"string": "Reserved(7)"
},
"result": {
"value": 0,
"string": "Completed"
},
"failed_segment": {
"value": 80,
"aka": "self_test_number"
},
"power_on_time": {
"hours": 5,
"aka": "accumulated_power_on_hours"
}
},
"scsi_self_test_3": {
"code": {
"value": 1,
"string": "Background short"
},
"result": {
"value": 0,
"string": "Completed"
},
"power_on_time": {
"hours": 2,
"aka": "accumulated_power_on_hours"
}
},
"scsi_extended_self_test_seconds": 80400
}
2 changes: 1 addition & 1 deletion plugins/inputs/smartctl/testcases_device/usb/expected.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
smartctl,model=SanDisk\ pSSD,name=/dev/sda,serial=06c9f4c44,type=sat,wwn=5001b4409f6c444c capacity=15693664256i,firmware="3",health_ok=true,temperature=0i 1711480345675066854
smartctl,model=SanDisk\ pSSD,name=/dev/sda,serial=06c9f4c44,type=sat,wwn=5001b4409f6c444c capacity=15693664256i,firmware="3",health_ok=true,logical_block_size=512i,power_on_hours=11i,temperature=0i 1711480345675066854
smartctl_attributes,model=SanDisk\ pSSD,name=Reallocated_Sector_Ct,serial=06c9f4c44,type=sat,wwn=5001b4409f6c444c raw_value=0i,threshold=0i,value=100i,worst=100i 1711480345675066854
smartctl_attributes,model=SanDisk\ pSSD,name=Power_On_Hours,serial=06c9f4c44,type=sat,wwn=5001b4409f6c444c raw_value=11i,threshold=0i,value=100i,worst=100i 1711480345675066854
smartctl_attributes,model=SanDisk\ pSSD,name=Power_Cycle_Count,serial=06c9f4c44,type=sat,wwn=5001b4409f6c444c raw_value=223i,threshold=0i,value=100i,worst=100i 1711480345675066854
Expand Down
Loading