Joe Williams home
I've been debugging issues with HTTP, my backend servers and HAProxy. After a quick email to the HAProxy mailing list I found out about a configuration option stats socket PATH. This will create a socket you can send commands to and get more information out of HAProxy. To do this I just used some simle unix tools, the key is socat. From the man:
socat is a relay for bidirectional data transfer between two independent data channels. Each of these data channels may be a file, pipe, device (serial line etc. or a pseudo terminal), a socket (UNIX, IP4, IP6 - raw, UDP, TCP), an SSL socket, proxy CONNECT connection, a file descriptor (stdin etc.), the GNU line editor (readline), a program, or a combination of two of these. These modes include generation of "listening" sockets, named pipes, and pseudo terminals.
Here are a few examples of how to use the stats socket. First, you need to add stats socket PATH to your configuration and restart haproxy. You should then find a socket located at the path specified, I used /tmp/haproxy. Now you can send it commands to get more information and stats from HAProxy. echo "show stat" | socat unix-connect:/tmp/haproxy stdio This will give you stats on all of your backends and frontends, some of the same stuff you see on the stats page enabled by the stats uri configuration. As an added bonus it's all in CSV. echo "show errors" | socat unix-connect:/tmp/haproxy stdio show errors will give you a capture of last error on each backend/frontend. echo "show info" | socat unix-connect:/tmp/haproxy stdio This will give you information about the running HAProxy process such as pid, uptime and etc. echo "show sess" | socat unix-connect:/tmp/haproxy stdio This will dump (possibly huge) info about all know sessions. For more details check out the docs section 9 and stats socket in section 3.1. Bonus socat fun. socat is a more full featured cousin of netcat. Both can be used in similar ways, one thing I use them for occasionally is debugging REST and etc. This was a real help when working with an API that didn't have a library, I could test things out without needing to make erroneous calls to the API. In the simplest case you can have either of them listen on a port and output all the details of the request. To do this with socat run: socat tcp-listen:8000 stdio This will listen for connections on port 8000. Doing the same thing with netcat is easy as well: netcat -l -p 8000 For instance you can see the output from creating a document in CouchDB. In one terminal: $ irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'rest_client' => true irb(main):003:0> RestClient.put("http://localhost:8000/somedb/somedoc", "{\"somekey\": \"somevalue\"}", :content_type => "application/json") In another run your mock server: $ socat tcp-listen:8000 stdio PUT /somedb/somedoc HTTP/1.1 Accept: application/xml Content-Type: application/json Accept-Encoding: gzip, deflate Content-Length: 24 Host: localhost:8000 {"somekey": "somevalue"} Oh! By the way, if you install netcat from source, don't compile with -DGAPING_SECURITY_HOLE unless you know what you are doing. :D
Fork me on GitHub