forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-uptime-report.sh
More file actions
executable file
·54 lines (45 loc) · 1.66 KB
/
Copy pathgenerate-uptime-report.sh
File metadata and controls
executable file
·54 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
# generate-uptime-report.sh
# Queries Prometheus for 30-day uptime per endpoint and prints a Markdown report.
# Usage: PROMETHEUS_URL=http://localhost:9090 ./generate-uptime-report.sh
set -euo pipefail
PROMETHEUS_URL="${PROMETHEUS_URL:-http://localhost:9090}"
REPORT_DIR="${REPORT_DIR:-/tmp/nova-uptime-reports}"
DATE=$(date +%Y-%m)
mkdir -p "$REPORT_DIR"
REPORT_FILE="$REPORT_DIR/uptime-${DATE}.md"
query_uptime() {
local instance="$1"
curl -sf "${PROMETHEUS_URL}/api/v1/query" \
--data-urlencode "query=avg_over_time(probe_success{job=\"blackbox-uptime\",instance=\"${instance}\"}[30d]) * 100" \
| jq -r '.data.result[0].value[1] // "N/A"'
}
ENDPOINTS=(
"${API_HEALTH_URL:-http://backend:4000/health}"
"${FRONTEND_URL:-http://frontend:3000}"
"${STELLAR_RPC_URL:-https://horizon-testnet.stellar.org}"
)
{
echo "# Nova Rewards — Monthly Uptime Report (${DATE})"
echo ""
echo "Generated: $(date -u '+%Y-%m-%d %H:%M UTC')"
echo ""
echo "| Endpoint | 30-day Uptime | SLA Target | Status |"
echo "|----------|--------------|------------|--------|"
for endpoint in "${ENDPOINTS[@]}"; do
uptime=$(query_uptime "$endpoint")
if [[ "$uptime" == "N/A" ]]; then
status="⚠️ No data"
elif (( $(echo "$uptime >= 99.9" | bc -l) )); then
status="✅ Met"
else
status="❌ Breached"
fi
printf "| %s | %.3f%% | 99.9%% | %s |\n" "$endpoint" "${uptime:-0}" "$status"
done
echo ""
echo "SLA definition: 99.9% monthly uptime = max ~43 minutes downtime/month."
echo "Runbook: [docs/ops/incident-response.md](../docs/ops/incident-response.md)"
} | tee "$REPORT_FILE"
echo ""
echo "Report saved to $REPORT_FILE"