Created
October 8, 2012 09:34
-
-
Save philandstuff/3851645 to your computer and use it in GitHub Desktop.
script to pump haproxy stats into statsd
This file contains hidden or 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
#!/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