Skip to content

Haproxy tcp check

Michael Filonenko edited this page Nov 12, 2018 · 1 revision

Haproxy tcp-check for tarantool

Ping-based msgpack tcp-check for tarantool

global

defaults
    mode tcp
    timeout connect   5s
    timeout client    5s
    timeout server    5s

listen tnt
    bind 127.0.0.1:4401
    mode tcp
    log 127.0.0.1:5050 kern
    option tcplog
    option log-health-checks

    # <--- BEGIN
    option tcp-check
    tcp-check comment "Waiting for greetings"
    tcp-check expect rstring Tarantool

    tcp-check send-binary 058200400101
    tcp-check comment "Waiting for response"
    tcp-check comment "MsgPack Int for packet size"
    tcp-check expect binary CE00000018
    tcp-check comment "MsgPack Map"
    tcp-check expect binary 83
    tcp-check comment "MsgPack expect Key 0 (code) is 0"
    tcp-check expect binary 00CE00000000
    tcp-check comment "MsgPack\ expect\ Key 1 (sync) is 1"
    tcp-check expect binary 01CF0000000000000001
    # <--- END

    server localhost 127.0.0.1:3300 check
    server localhost1 127.0.0.1:3301 check
    server localhost2 127.0.0.1:3302 check

Lua-eval based msgpack (better if replication)

global

defaults
    mode tcp
    timeout connect   5s
    timeout client    5s
    timeout server    5s

listen tnt
    bind 127.0.0.1:4401
    mode tcp
    log 127.0.0.1:5050 kern
    option tcplog
    option log-health-checks

    # <--- BEGIN
    tcp-check expect string Tarantool
    # Python:
    # >>> import msgpack
    # >>> header = msgpack.dumps({1: 1, 0: 8})
    # >>> body = msgpack.dumps({39: 'local i=box.info() return not i.ro and i.status == "running" and "HAPR" .. "OXYOK"', 33: []})
    # >>> length = msgpack.dumps(len(header + body))
    # >>> (length + header + body).hex()
    tcp-check send-binary 5e820008010182219027da00526c6f63616c20693d626f782e696e666f28292072657475726e206e6f7420692e726f20616e6420692e737461747573203d3d202272756e6e696e672220616e6420224841505222202e2e20224f58594f4b22
    tcp-check expect string HAPROXYOK
    # <--- END

    server localhost 127.0.0.1:3300 check
    server localhost1 127.0.0.1:3301 check
    server localhost2 127.0.0.1:3302 check
Clone this wiki locally