Skip to content

Prometheus — alert when a scrape target is unreachable

Prometheus itself is alive, but one of its targets has up==0 — data stops flowing, graphs go blank, and alertmanager rules built on that target don't fire (no data = no alert).

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/prom-target
# */1 * * * * root /opt/prom-target.sh

PROM=${PROM_URL:-http://localhost:9090}

DOWN=$(curl -fsS "$PROM/api/v1/query" --data-urlencode 'query=up==0' \
  | jq -r '.data.result | length')

if [ "${DOWN:-0}" -gt 0 ]; then
  TARGETS=$(curl -fsS "$PROM/api/v1/query" --data-urlencode 'query=up==0' \
    | jq -r '.data.result | map(.metric.instance) | join(",")')
  curl -fsS "$HEARTBEAT_URL" --data "down_targets=$DOWN,instances=$TARGETS"
  exit 2
fi
echo "OK (no down targets)"

Same thing in Enterno.io

Stand up an Enterno heartbeat on 1-minute intervals — a meta-monitor "monitoring the monitoring" that alerts when Prometheus loses sight of a target before any user notices.

Set up HTTP monitor → ← All recipes

Related recipes