Files
timmy-telemetry/backfill.sh

72 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Backfill historical git data into Prometheus
# Run from the timmy-telemetry directory on Hermes:
# chmod +x backfill.sh && ./backfill.sh
set -e
echo "=== Timmy Telemetry Backfill ==="
echo ""
# 1. Stop Prometheus so we can write to its TSDB safely
echo "Step 1: Stopping Prometheus..."
docker stop timmy-prometheus
# 2. Create TSDB blocks using promtool (override entrypoint)
echo "Step 2: Creating TSDB blocks from historical data..."
docker run --rm \
--entrypoint promtool \
-v timmy-telemetry_prometheus-data:/prometheus \
-v "$(pwd)/backfill.txt:/tmp/backfill.txt:ro" \
prom/prometheus:latest \
tsdb create-blocks-from openmetrics /tmp/backfill.txt /prometheus
if [ $? -ne 0 ]; then
echo ""
echo "promtool not available in image, trying alternative..."
# Some prometheus images don't ship promtool — download it
docker run --rm \
--entrypoint /bin/sh \
-v timmy-telemetry_prometheus-data:/prometheus \
-v "$(pwd)/backfill.txt:/tmp/backfill.txt:ro" \
prom/prometheus:latest \
-c "ls /bin/prom*; ls /usr/bin/prom*; which promtool" 2>&1 || true
fi
echo ""
echo "Step 3: Restarting Prometheus..."
docker start timmy-prometheus
echo ""
echo "Step 4: Waiting for Prometheus to start..."
sleep 5
# 5. Verify
echo "Step 5: Verifying..."
curl -s "http://localhost:9090/api/v1/query?query=timmy_sovereignty_score" 2>/dev/null | \
python3 -c "
import json,sys
d=json.load(sys.stdin)
r=d.get('data',{}).get('result',[])
if r:
print(f' Current sovereignty score: {r[0][\"value\"][1]}')
else:
print(' WARNING: No current data')
" 2>/dev/null || echo " Could not query Prometheus"
curl -s "http://localhost:9090/api/v1/query_range?query=timmy_sovereignty_score&start=2026-02-05T00:00:00Z&end=2026-02-06T23:59:59Z&step=86400" 2>/dev/null | \
python3 -c "
import json,sys
d=json.load(sys.stdin)
r=d.get('data',{}).get('result',[])
if r and r[0].get('values'):
print(f' Feb 5 sovereignty score: {r[0][\"values\"][0][1]} (backfill confirmed!)')
else:
print(' WARNING: No historical data for Feb 5')
" 2>/dev/null || echo " Could not verify historical data"
echo ""
echo "=== Done ==="
echo "Open Grafana: http://localhost:3033"
echo "Set time range to 'Last 60 days' or 'Last 90 days'"