2023-09-22 14:10:28 -06:00
|
|
|
# frozen_string_literal: true
|
2023-09-21 18:03:25 -06:00
|
|
|
|
|
|
|
class DiskInfo
|
|
|
|
def self.gather_info
|
|
|
|
disk_info = []
|
|
|
|
|
|
|
|
# Get additional disk details using `lsblk` command
|
|
|
|
lsblk_output = `lsblk -J`.strip
|
|
|
|
lsblk_json = JSON.parse(lsblk_output)
|
2023-09-22 14:10:28 -06:00
|
|
|
|
2023-09-21 18:03:25 -06:00
|
|
|
lsblk_json['blockdevices'].each do |device|
|
2023-09-22 14:10:28 -06:00
|
|
|
next unless device['type'] == 'disk' # We only want disk devices
|
|
|
|
|
|
|
|
# Skip swap partitions
|
|
|
|
next if device['mountpoints']&.include?('[SWAP]')
|
|
|
|
|
|
|
|
# Determine if the disk is SSD or HDD
|
|
|
|
rotational_info = File.read("/sys/block/#{device['name']}/queue/rotational").strip
|
|
|
|
type = rotational_info == '1' ? 'HDD' : 'SSD'
|
|
|
|
|
|
|
|
# Get transport type using udevadm
|
|
|
|
transport = `udevadm info --query=property --name=#{device['name']} | grep ID_BUS | cut -d= -f2`.strip
|
|
|
|
|
|
|
|
# Get disk model from /sys filesystem
|
|
|
|
model_path = "/sys/block/#{device['name']}/device/model"
|
|
|
|
model = File.exist?(model_path) ? File.read(model_path).strip : 'Unknown'
|
2023-09-21 18:03:25 -06:00
|
|
|
|
|
|
|
disk = {
|
2023-09-22 14:10:28 -06:00
|
|
|
model:,
|
|
|
|
type:,
|
|
|
|
transport: transport || 'Unknown'
|
2023-09-21 18:03:25 -06:00
|
|
|
}
|
|
|
|
disk_info << disk
|
2023-09-24 17:31:26 -06:00
|
|
|
File.open('runtime_log.log', 'a') { |f| f.puts("#{disk}") }
|
2023-09-21 18:03:25 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
disk_info
|
|
|
|
end
|
|
|
|
end
|