Skip to content

Instantly share code, notes, and snippets.

@philandstuff
Created October 8, 2012 09:34
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philandstuff/3851645 to your computer and use it in GitHub Desktop.
Save philandstuff/3851645 to your computer and use it in GitHub Desktop.
script to pump haproxy stats into statsd
#!/usr/bin/ruby
require 'socket'
HOSTNAME = `facter hostname`.chomp
SOCKET = UDPSocket.new
IO.popen(["curl","http://localhost:8000/haproxy;csv"]) do |haproxy_csv|
header_line = haproxy_csv.gets
header_line.gsub!(/# /,'')
HEADERS = header_line.split(/,/)[0..-2]
while line = haproxy_csv.gets do
stats = Hash[HEADERS.zip($_.split(/,/))]
%w(scur smax ereq econ rate).each do |statname|
SOCKET.send("haproxy.#{HOSTNAME}.#{stats['pxname']}.#{stats['svname']}.#{statname}:#{stats[statname]}|g",0,'127.0.0.1',8125)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment