Created
November 9, 2012 10:50
-
-
Save vpereira/4045115 to your computer and use it in GitHub Desktop.
simple iostats in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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