Skip to content

Instantly share code, notes, and snippets.

@skottler
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skottler/198d05914bd8d4bf499d to your computer and use it in GitHub Desktop.
Save skottler/198d05914bd8d4bf499d to your computer and use it in GitHub Desktop.
Ohai.plugin(:Trim) do
# This ohai plugin provides data about TRIM support on each underlying block
# device available on the system. Its functionality is rather simple - it
# iterates over each physical device, ignoring partitions, and then runs
# hdparm to find the drives' capabilities, finally grepping for TRIM support.
provides "block_device/trim"
depends "block_device"
collect_data(:default) do
devices = shell_out("ls /dev/sd[a-z]").stdout.lines
if devices
devices.each do |device|
device = device.chomp
so = shell_out("hdparm -I #{device} | grep 'TRIM supported'")
block_device[device.gsub(/.*\//, '').to_sym][:trim] = so.exitstatus == 0 ? true : false
end
block_device
end
end
end
"sda": {
"size": "$SIZE",
"removable": "0",
"model": "$MODEL",
"rev": "$REV",
"state": "running",
"timeout": "90",
"vendor": "$VENDOR",
"trim": false
},
"sdb": {
"size": "$SIZE",
"removable": "0",
"model": "$MODEL",
"rev": "$REV",
"state": "running",
"timeout": "30",
"vendor": "$VENDOR",
"trim": true
},
"sdc": {
"size": "$SIZE",
"removable": "0",
"model": "$MODEL",
"rev": "$REV",
"state": "running",
"timeout": "30",
"vendor": "$VENDOR",
"trim": true
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment