Skip to content

Instantly share code, notes, and snippets.

@junaid18183
Last active November 4, 2020 09:29
Show Gist options
  • Save junaid18183/56897c2bed3b3c6008a5 to your computer and use it in GitHub Desktop.
Save junaid18183/56897c2bed3b3c6008a5 to your computer and use it in GitHub Desktop.
Haproxy stats with Socat
#Source - http://www.haproxy.org/download/1.5/doc/configuration.txt
# Section - 9.2. Unix Socket commands
#show stat [<iid> <type> <sid>]
# Dump statistics in the CSV format. By passing <id>, <type> and <sid>, it is
# possible to dump only selected items :
# - <iid> is a proxy ID, -1 to dump everything
# - <type> selects the type of dumpable objects : 1 for frontends, 2 for
# backends, 4 for servers, -1 for everything. These values can be ORed,
# for example:
# 1 + 2 = 3 -> frontend + backend.
# 1 + 2 + 4 = 7 -> frontend + backend + server.
# - <sid> is a server ID, -1 to dump everything from the selected proxy.
# Get iid(unique proxy id) of HAProxy Backend Pool.
echo "show stat -1 2 -1" | socat unix-connect:/var/run/test.3.sock stdio | awk -F ',' '/^[[:alnum:]]/ { print $1"="$28 }'
VIP:www1.juned.com:127.0.0.45:80=1
VIP:www2.juned.com:127.0.0.14:80=2
VIP:www2.juned.com:127.0.0.14:443=3
VIP:tiber4.juned.com:127.0.0.10:80=4
VIP:tiber4.juned.com:127.0.0.10:443=5
VIP:tiber1.juned.com:127.0.0.17:80=6
VIP:tiber1.juned.com:127.0.0.17:443=7
VIP:tiber7.juned.com:127.0.0.31:80=8
VIP:tiber7.juned.com:127.0.0.31:443=9
#Get the Backends of iid 8 i.e VIP:tiber7.juned.com:127.0.0.31:80
echo "show stat 8 4 -1" | socat unix-connect:/var/run/test.3.sock stdio | awk -F ',' '/^[[:alnum:]]/ { print $2":"$18 }' | awk -F : '{print $2,$5}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment