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 1 commit
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
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