- 
      
- 
        Save chrismay/915862 to your computer and use it in GitHub Desktop. 
| #!/opt/csw/bin/ruby | |
| # | |
| # run with something like iostat -nx 10 | iostat_to_graphite.rb | |
| # | |
| require 'socket' | |
| graphite_host='graphite' | |
| graphite_port=2003 | |
| hostname=`hostname`.chomp | |
| ARGF.each do |line| | |
| tstamp = Time.now.to_i | |
| if (line !~ /extended device|r\/s/) then | |
| s = TCPSocket.open(graphite_host, graphite_port) | |
| parts = line.split(' ') | |
| device = parts[10].gsub(/[\/\(\): ]/,'_') | |
| prefix = "servers.#{hostname}.iostat.#{device}" | |
| s.puts "#{prefix}.reads_sec #{parts[0]} #{tstamp}" | |
| s.puts "#{prefix}.writes_sec #{parts[1]} #{tstamp}" | |
| s.puts "#{prefix}.kreads_sec #{parts[2]} #{tstamp}" | |
| s.puts "#{prefix}.kwrites_sec #{parts[3]} #{tstamp}" | |
| s.puts "#{prefix}.pc_wait #{parts[8]} #{tstamp}" | |
| s.puts "#{prefix}.pc_busy #{parts[9]} #{tstamp}" | |
| s.close | |
| end | |
| end | 
and the same for centos
if (/sd|md/.match(line)) then
s = TCPSocket.open(graphite_host, graphite_port)
parts =  line.split(' ')
device = parts[0].gsub(/[/(): ]/,'_')
prefix = "iostat.#{device}"
s.puts "#{prefix}.rrqm_s #{parts[1].to_i} #{tstamp}"
s.puts "#{prefix}.wrqm_s #{parts[2].to_i} #{tstamp}"
s.puts "#{prefix}.r_s #{parts[3].to_i} #{tstamp}"
s.puts "#{prefix}.w_s #{parts[4].to_i} #{tstamp}"
s.puts "#{prefix}.rkB_s #{parts[5].to_i} #{tstamp}"
s.puts "#{prefix}.wkB_s #{parts[6].to_i} #{tstamp}"
s.puts "#{prefix}.avgrq-sz #{parts[7].to_i} #{tstamp}"
s.puts "#{prefix}.avgqu-sz #{parts[8].to_i} #{tstamp}"
s.puts "#{prefix}.await #{parts[9].to_i} #{tstamp}"
s.puts "#{prefix}.svctm #{parts[10].to_i} #{tstamp}"
s.puts "#{prefix}.util #{parts[11].to_i} #{tstamp}"
and the same for
zpool iostat: