Skip to content
Newer
Older
100755 60 lines (44 sloc) 1.98 KB
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
1 #!/usr/bin/env ruby
2
3 # because CloudKick wants a license to merge...
4 # ----------------------------------------------------------------------------
5 # "THE BEER-WARE LICENSE" (Revision 42):
6 # <lo@petalphile.com> wrote this file. As long as you retain this notice you
7 # can do whatever you want with this stuff. If we meet some day, and you think
8 # this stuff is worth it, you can buy me a beer in return
9 # ----------------------------------------------------------------------------
10
731560c takes socket 'show stats' and grabs total connections, connection rat…
C. Flores authored Dec 8, 2010
11 ### the script:
12
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
13 # takes HAProxy stats and grabs connections, rate, and check time
14 # for every listener and every backend server, using a format like
15 # "metric groupname_servername_request_rate int 10
16
17 # variables you may actually need to change
18
19 # change this if the file is elsewhere
20 config = "/etc/haproxy/haproxy.cfg" || raise("Expecting haproxy configuration file in /etc/haproxy/haproxy.cfg")
21
22 # grab the statistics socket from above
23 socket = `awk '/stats socket/ {print $3}' #{config}`.chomp || raise("Expecting \'stats socket <UNIX_socket_path>\' in #{config}")
24
25 # where haproxy lives and pid (either in conf or static location)
26 exec = `which haproxy`.chomp || raise("Where the F is haproxy?")
27 pid = `pidof haproxy`.chomp.to_i || nil
28
29
30
31 if ( pid )
32 puts "status ok haproxy is running"
33 conn = `lsof -ln -i |grep -c #{pid}`.chomp.to_i
34 # removes the listener and stats socket
35 conn = conn - 2
36 puts "metric connections int #{conn}"
37 # grab statistics from the socket
38
39 require 'socket'
731560c takes socket 'show stats' and grabs total connections, connection rat…
C. Flores authored Dec 8, 2010
40
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
41 ctl=UNIXSocket.new(socket)
42 ctl.puts "show stat"
731560c takes socket 'show stats' and grabs total connections, connection rat…
C. Flores authored Dec 8, 2010
43
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
44 while (line = ctl.gets) do
45 if (line =~ /^[^#]\w+/)
46 line = line.split(",")
3b6fb91 Monitor queues to backend servers;
C. Flores authored Jan 11, 2011
47 host = "#{line[0]}_#{line[1]}"
48 puts "metric #{host}_request_rate int #{line[47]}" if line[47].to_i > 0
cb3ea48 s/guage/gauge/
C. Flores authored Jan 11, 2011
49 puts "metric #{host}_total_requests gauge #{line[49]}" if line[49].to_i > 0
3b6fb91 Monitor queues to backend servers;
C. Flores authored Jan 11, 2011
50 puts "metric #{host}_health_check_duration int #{line[35]}" if line[35].to_i > 0
51 puts "metric ${host}_current_queue int #{line[3]}" if line[3].to_i > 0
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
52 end
53 end
731560c takes socket 'show stats' and grabs total connections, connection rat…
C. Flores authored Dec 8, 2010
54
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
55 ctl.close
56
57 else
6bf8008 s/critical/err/g
C. Flores authored Oct 2, 2011
58 puts "status err haproxy is not running!"
37fec20 takes HAProxy stats and grabs connections, rate, and check time for t…
C. Flores authored Dec 8, 2010
59 end
Something went wrong with that request. Please try again.