Skip to content

HAProxy — alert when any backend goes DOWN

HAProxy balances over 5 backends; one starts erroring and goes DOWN. Alert before users notice.

Recipe

bash
#!/usr/bin/env bash
# Reads HAProxy stats socket; prints "ok" if every backend is UP, "down N" otherwise.
SOCK="${SOCK:-/var/run/haproxy/admin.sock}"
DOWN=$(echo "show stat" | socat - "UNIX-CONNECT:$SOCK" \
        | awk -F, 'NR>1 && $2 != "FRONTEND" && $2 != "BACKEND" && $18 == "DOWN" {print $2"/"$1}')
[ -z "$DOWN" ] && echo "ok" || echo "down $DOWN"

Same thing in Enterno.io

Expose the endpoint and point an Enterno HTTP monitor at it with rule "body = ok". Multi-region check (Pro+) confirms whether DOWN is real or an edge-router blip.

Set up HTTP monitor → ← All recipes

Related recipes