Skip to content

Instantly share code, notes, and snippets.

@vpereira
Created November 9, 2012 10:50
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 vpereira/4045115 to your computer and use it in GitHub Desktop.
Save vpereira/4045115 to your computer and use it in GitHub Desktop.
simple iostats in ruby
def read_file
File.open('/proc/diskstats').collect do |line|
entries = line.split
next unless entries[2] =~/sda/
[entries[2],entries[4],entries[5]]
end.compact.flatten
end
while true
time_1 = Time.now.to_f
arr1 = read_file
sleep 1
arr2 = read_file
time_2 = Time.now.to_f
delta_time = time_2 - time_1
puts "#{arr1[0]}\tread: #{(arr2[1].to_f - arr1[1].to_f) / delta_time} bytes/sec\twrite: #{(arr2[2].to_f - arr2[1].to_f)/delta_time} bytes/sec"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment