Skip to content

Instantly share code, notes, and snippets.

@bpaquet
Last active December 26, 2015 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bpaquet/7153979 to your computer and use it in GitHub Desktop.
Save bpaquet/7153979 to your computer and use it in GitHub Desktop.
Script for monitoring haproxy status from collect.d
#!/bin/sh
sock='<%= @socket %>'
host="$(hostname -f)"
pause=10
while getopts "h:p:s:" c; do
case $c in
h) host=$OPTARG;;
p) pause=$OPTARG;;
s) sock=$OPTARG;;
*) echo "Usage: $0 [-h <hostname>] [-p <seconds>] [-s <sockfile>]";;
esac
done
while [ $? -eq 0 ]; do
time="$(date +%s)"
echo 'show stat' | socat - UNIX-CLIENT:$sock \
|while IFS=',' read pxname svname qcur qmax scur smax slim stot bin bout dreq dresp ereq econ eresp wretr wredis status weight act bck chkfail chkdown lastchg downtime qlimit pid iid sid throttle lbtot tracked type rate rate_lim rate_max check_status check_code check_duration hrsp_1xx hrsp_2xx hrsp_3xx hrsp_4xx hrsp_5xx hrsp_other hanafail req_rate req_rate_max req_tot cli_abrt srv_abrt comp_in comp_out comp_byp comp_rsp; do
if [ "$svname" = 'BACKEND' ] || [ "$svname" = 'FRONTEND' ]; then
name=$(echo $svname | tr '[:upper:]' '[:lower:]')
echo "PUTVAL $host/haproxy/counter-$name.$pxname.session $time:${stot:-0}"
echo "PUTVAL $host/haproxy/counter-$name.$pxname.bytes_in $time:${bin:-0}"
echo "PUTVAL $host/haproxy/counter-$name.$pxname.bytes_out $time:${bout:-0}"
echo "PUTVAL $host/haproxy/counter-$name.$pxname.downtime $time:${downtime:-0}"
echo "PUTVAL $host/haproxy/counter-$name.$pxname.errors $time:${ereq:-0}"
echo "PUTVAL $host/haproxy/gauge-$name.$pxname.session interval=$pause N:${scur:-0}"
fi
done
sleep $pause
done
LoadPlugin "exec"
<Plugin "exec">
Exec "haproxy:haproxy" "/usr/local/bin/haproxy-stats" "-p" "10"
</Plugin>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment