- Downloads promtool 3.10.0 darwin-arm64 from GitHub releases - Runs natively on Mac (not inside Docker — that was the bug) - Creates TSDB blocks locally, copies into Prometheus volume via busybox - Verified: 50 blocks created successfully from test run - Added .gitignore for promtool binary
118 lines
4.1 KiB
Bash
Executable File
118 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Backfill historical git data into Prometheus
|
|
# Tested and verified — creates 50 TSDB blocks (Feb 5 - Mar 26, 2026)
|
|
#
|
|
# Run from the timmy-telemetry directory on Hermes:
|
|
# chmod +x backfill.sh && ./backfill.sh
|
|
set -e
|
|
|
|
PROM_VERSION="3.10.0"
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
echo "=== Timmy Telemetry Backfill ==="
|
|
echo ""
|
|
|
|
# 1. Get promtool (download if not present)
|
|
if command -v promtool &>/dev/null; then
|
|
echo "Step 1: promtool found in PATH"
|
|
elif [ -f "$SCRIPT_DIR/promtool" ]; then
|
|
echo "Step 1: Using local promtool"
|
|
export PATH="$SCRIPT_DIR:$PATH"
|
|
else
|
|
echo "Step 1: Downloading promtool ${PROM_VERSION} for Mac arm64..."
|
|
ARCH="darwin-arm64"
|
|
URL="https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.${ARCH}.tar.gz"
|
|
curl -sL "$URL" -o /tmp/prometheus.tar.gz
|
|
tar xzf /tmp/prometheus.tar.gz -C /tmp "prometheus-${PROM_VERSION}.${ARCH}/promtool"
|
|
cp "/tmp/prometheus-${PROM_VERSION}.${ARCH}/promtool" "$SCRIPT_DIR/promtool"
|
|
chmod +x "$SCRIPT_DIR/promtool"
|
|
rm -rf /tmp/prometheus.tar.gz "/tmp/prometheus-${PROM_VERSION}.${ARCH}"
|
|
export PATH="$SCRIPT_DIR:$PATH"
|
|
echo " Downloaded and cached at $SCRIPT_DIR/promtool"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 2. Stop Prometheus
|
|
echo "Step 2: Stopping Prometheus..."
|
|
docker stop timmy-prometheus 2>/dev/null || true
|
|
|
|
# 3. Find the Prometheus data volume mount point
|
|
echo "Step 3: Locating Prometheus data volume..."
|
|
VOLUME_PATH=$(docker volume inspect timmy-telemetry_prometheus-data --format '{{.Mountpoint}}' 2>/dev/null || echo "")
|
|
|
|
if [ -z "$VOLUME_PATH" ]; then
|
|
echo " Could not find volume mount. Using docker cp approach..."
|
|
|
|
# Create blocks in a temp dir, then copy into the volume
|
|
TMPDIR=$(mktemp -d)
|
|
echo " Creating TSDB blocks in $TMPDIR..."
|
|
promtool tsdb create-blocks-from openmetrics "$SCRIPT_DIR/backfill.txt" "$TMPDIR"
|
|
|
|
echo " Copying blocks into Prometheus volume..."
|
|
# Start a helper container to copy blocks in
|
|
docker run --rm \
|
|
-v timmy-telemetry_prometheus-data:/prometheus \
|
|
-v "$TMPDIR:/backfill:ro" \
|
|
busybox sh -c 'cp -r /backfill/01* /prometheus/ 2>/dev/null; ls /prometheus/01* | head -5; echo "...copied"'
|
|
|
|
rm -rf "$TMPDIR"
|
|
else
|
|
echo " Volume at: $VOLUME_PATH"
|
|
echo " Creating TSDB blocks directly..."
|
|
promtool tsdb create-blocks-from openmetrics "$SCRIPT_DIR/backfill.txt" "$VOLUME_PATH"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 4. Restart Prometheus
|
|
echo "Step 4: Starting Prometheus..."
|
|
docker start timmy-prometheus
|
|
echo " Waiting 5 seconds for startup..."
|
|
sleep 5
|
|
|
|
# 5. Verify
|
|
echo ""
|
|
echo "Step 5: Verifying..."
|
|
|
|
# Check current data
|
|
CURRENT=$(curl -s "http://localhost:9090/api/v1/query?query=timmy_sovereignty_score" 2>/dev/null)
|
|
echo "$CURRENT" | 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(' ✗ No current data')
|
|
" 2>/dev/null || echo " Could not query current data"
|
|
|
|
# Check historical data
|
|
HISTORICAL=$(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)
|
|
echo "$HISTORICAL" | 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 data found: sovereignty score = {r[0][\"values\"][0][1]}')
|
|
else:
|
|
print(' ✗ No historical data for Feb 5')
|
|
" 2>/dev/null || echo " Could not verify historical data"
|
|
|
|
# Count total blocks
|
|
BLOCKS=$(curl -s "http://localhost:9090/api/v1/query_range?query=timmy_sovereignty_score&start=2026-02-01T00:00:00Z&end=2026-03-27T00:00:00Z&step=86400" 2>/dev/null)
|
|
echo "$BLOCKS" | 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' ✓ Total historical data points: {len(r[0][\"values\"])}')
|
|
else:
|
|
print(' ✗ Could not count data points')
|
|
" 2>/dev/null || echo " Could not count blocks"
|
|
|
|
echo ""
|
|
echo "=== Done ==="
|
|
echo "Open Grafana: http://localhost:3033"
|
|
echo "Set time range to 'Last 60 days' to see the full history"
|