Uptime Monitor #1469
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Uptime Monitor | |
| on: | |
| schedule: | |
| - cron: "*/15 * * * *" | |
| workflow_dispatch: | |
| jobs: | |
| uptime-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Ensure health check URL exists | |
| run: | | |
| if [ -z "${{ secrets.HEALTHCHECK_URL }}" ]; then | |
| echo "Missing HEALTHCHECK_URL secret" | |
| exit 1 | |
| fi | |
| - name: Run uptime and latency check | |
| run: | | |
| set -e | |
| TMP_BODY=$(mktemp) | |
| STATUS=$(curl -sS -o "$TMP_BODY" -w "%{http_code}" "${{ secrets.HEALTHCHECK_URL }}") | |
| LATENCY=$(curl -sS -o /dev/null -w "%{time_total}" "${{ secrets.HEALTHCHECK_URL }}") | |
| MAX_LATENCY=${MAX_HEALTHCHECK_LATENCY_SECONDS:-2} | |
| echo "HTTP Status: $STATUS" | |
| echo "Latency Seconds: $LATENCY" | |
| echo "Response Body:" | |
| cat "$TMP_BODY" | |
| if [ "$STATUS" -ne 200 ]; then | |
| echo "Health check failed with status $STATUS" | |
| exit 1 | |
| fi | |
| awk -v l="$LATENCY" -v m="$MAX_LATENCY" 'BEGIN { if (l > m) { exit 1 } }' || { | |
| echo "Latency threshold exceeded: $LATENCY > $MAX_LATENCY" | |
| exit 1 | |
| } |