A quick sketch of haproxy config with lua to provide an HTTP API to query stick tables in JSON format. Probably has a few rough edges around output as kv_pairs() doesn't really understand its output, just building up strings. A proper table traversal function would be better, and verifying its actually valid JSON would be even better.
- http://localhost:8000/ is the front end
- http://localhost:8001/ is the usual admin panel
- port 8002 is used for peer syncing, the goal is to have the peer table queryable across nodes, but right now this doesn't work, the stick table needs to be attached to a backend to be visible to lua.
/tmp/haproxy.{state,sock,pid}
are the usual things
$ git clone https://gist.github.com/dch/63dd70f626b4203c2769298c9c371958.git /tmp/haproxy
$ cd /tmp/haproxy
$ haproxy -L local -db -d -V -f haproxy.conf
$ wrk -c 5 -d 1 http://localhost:8000/
Running 1s test @ http://localhost:8000/
2 threads and 5 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.79ms 3.20ms 14.71ms 83.53%
Req/Sec 8.52k 3.03k 17.79k 90.91%
18693 requests in 1.10s, 1.79MB read
Requests/sec: 16946.99
Transfer/sec: 1.62MB
$ curl http://localhost:8000/
{
"::ffff:127.0.0.1": 18696
}
Making the table name, and threshold, configurable as parameters would be a nice addition.