Skip to content

Instantly share code, notes, and snippets.

@chrismay
Created April 12, 2011 16:37
Show Gist options
  • Save chrismay/915862 to your computer and use it in GitHub Desktop.
Save chrismay/915862 to your computer and use it in GitHub Desktop.
send Solaris iostats to Graphite
#!/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
@igalic
Copy link

igalic commented Jun 3, 2013

and the same for zpool iostat:

parts = line.split(' ')
device = parts[0].gsub(/[\/\(\): ]/,'_')
prefix = "servers.#{hostname}.iostat.#{device}"
s.puts "#{prefix}.reads_sec #{parts[3]} #{tstamp}"
s.puts "#{prefix}.writes_sec #{parts[4]} #{tstamp}"
s.puts "#{prefix}.kreads_sec #{parts[5]} #{tstamp}"
s.puts "#{prefix}.kwrites_sec #{parts[6]} #{tstamp}"
s.puts "#{prefix}.capacity_alloc #{parts[1]} #{tstamp}"
s.puts "#{prefix}.capacity_free #{parts[2]} #{tstamp}" 

@cooki
Copy link

cooki commented Nov 28, 2015

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}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment