Files
timmy-telemetry/backfill.sh
perplexity 325d28b215 Fix backfill: correct OpenMetrics timestamps (seconds not ms), safer import
- Timestamps now in unix seconds as floats (promtool requirement)
- Values as explicit floats (1.0 not 1)
- Import script stops Prometheus, writes blocks to volume, restarts
- Verification step checks both current and Feb 5 historical data
2026-03-27 01:41:21 +00:00

60 lines
1.9 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. Copy backfill file into the Prometheus data volume
echo "Step 2: Creating TSDB blocks from historical data..."
# Run promtool inside a temporary container with access to the Prometheus volume
docker run --rm \
-v timmy-telemetry_prometheus-data:/prometheus \
-v "$(pwd)/backfill.txt:/tmp/backfill.txt:ro" \
prom/prometheus:latest \
promtool tsdb create-blocks-from openmetrics /tmp/backfill.txt /prometheus
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'"