Verified backfill: downloads promtool natively on Mac, tested end-to-end
- 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
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
promtool
|
||||||
120
backfill.sh
120
backfill.sh
@@ -1,71 +1,117 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Backfill historical git data into Prometheus
|
# 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:
|
# Run from the timmy-telemetry directory on Hermes:
|
||||||
# chmod +x backfill.sh && ./backfill.sh
|
# chmod +x backfill.sh && ./backfill.sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
PROM_VERSION="3.10.0"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
echo "=== Timmy Telemetry Backfill ==="
|
echo "=== Timmy Telemetry Backfill ==="
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 1. Stop Prometheus so we can write to its TSDB safely
|
# 1. Get promtool (download if not present)
|
||||||
echo "Step 1: Stopping Prometheus..."
|
if command -v promtool &>/dev/null; then
|
||||||
docker stop timmy-prometheus
|
echo "Step 1: promtool found in PATH"
|
||||||
|
elif [ -f "$SCRIPT_DIR/promtool" ]; then
|
||||||
# 2. Create TSDB blocks using promtool (override entrypoint)
|
echo "Step 1: Using local promtool"
|
||||||
echo "Step 2: Creating TSDB blocks from historical data..."
|
export PATH="$SCRIPT_DIR:$PATH"
|
||||||
|
else
|
||||||
docker run --rm \
|
echo "Step 1: Downloading promtool ${PROM_VERSION} for Mac arm64..."
|
||||||
--entrypoint promtool \
|
ARCH="darwin-arm64"
|
||||||
-v timmy-telemetry_prometheus-data:/prometheus \
|
URL="https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.${ARCH}.tar.gz"
|
||||||
-v "$(pwd)/backfill.txt:/tmp/backfill.txt:ro" \
|
curl -sL "$URL" -o /tmp/prometheus.tar.gz
|
||||||
prom/prometheus:latest \
|
tar xzf /tmp/prometheus.tar.gz -C /tmp "prometheus-${PROM_VERSION}.${ARCH}/promtool"
|
||||||
tsdb create-blocks-from openmetrics /tmp/backfill.txt /prometheus
|
cp "/tmp/prometheus-${PROM_VERSION}.${ARCH}/promtool" "$SCRIPT_DIR/promtool"
|
||||||
|
chmod +x "$SCRIPT_DIR/promtool"
|
||||||
if [ $? -ne 0 ]; then
|
rm -rf /tmp/prometheus.tar.gz "/tmp/prometheus-${PROM_VERSION}.${ARCH}"
|
||||||
echo ""
|
export PATH="$SCRIPT_DIR:$PATH"
|
||||||
echo "promtool not available in image, trying alternative..."
|
echo " Downloaded and cached at $SCRIPT_DIR/promtool"
|
||||||
# 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
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Step 3: Restarting Prometheus..."
|
|
||||||
docker start timmy-prometheus
|
# 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 ""
|
echo ""
|
||||||
echo "Step 4: Waiting for Prometheus to start..."
|
|
||||||
|
# 4. Restart Prometheus
|
||||||
|
echo "Step 4: Starting Prometheus..."
|
||||||
|
docker start timmy-prometheus
|
||||||
|
echo " Waiting 5 seconds for startup..."
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# 5. Verify
|
# 5. Verify
|
||||||
|
echo ""
|
||||||
echo "Step 5: Verifying..."
|
echo "Step 5: Verifying..."
|
||||||
curl -s "http://localhost:9090/api/v1/query?query=timmy_sovereignty_score" 2>/dev/null | \
|
|
||||||
python3 -c "
|
# 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
|
import json,sys
|
||||||
d=json.load(sys.stdin)
|
d=json.load(sys.stdin)
|
||||||
r=d.get('data',{}).get('result',[])
|
r=d.get('data',{}).get('result',[])
|
||||||
if r:
|
if r:
|
||||||
print(f' Current sovereignty score: {r[0][\"value\"][1]}')
|
print(f' ✓ Current sovereignty score: {r[0][\"value\"][1]}')
|
||||||
else:
|
else:
|
||||||
print(' WARNING: No current data')
|
print(' ✗ No current data')
|
||||||
" 2>/dev/null || echo " Could not query Prometheus"
|
" 2>/dev/null || echo " Could not query current data"
|
||||||
|
|
||||||
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 | \
|
# Check historical data
|
||||||
python3 -c "
|
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
|
import json,sys
|
||||||
d=json.load(sys.stdin)
|
d=json.load(sys.stdin)
|
||||||
r=d.get('data',{}).get('result',[])
|
r=d.get('data',{}).get('result',[])
|
||||||
if r and r[0].get('values'):
|
if r and r[0].get('values'):
|
||||||
print(f' Feb 5 sovereignty score: {r[0][\"values\"][0][1]} (backfill confirmed!)')
|
print(f' ✓ Feb 5 data found: sovereignty score = {r[0][\"values\"][0][1]}')
|
||||||
else:
|
else:
|
||||||
print(' WARNING: No historical data for Feb 5')
|
print(' ✗ No historical data for Feb 5')
|
||||||
" 2>/dev/null || echo " Could not verify historical data"
|
" 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 ""
|
||||||
echo "=== Done ==="
|
echo "=== Done ==="
|
||||||
echo "Open Grafana: http://localhost:3033"
|
echo "Open Grafana: http://localhost:3033"
|
||||||
echo "Set time range to 'Last 60 days' or 'Last 90 days'"
|
echo "Set time range to 'Last 60 days' to see the full history"
|
||||||
|
|||||||
Reference in New Issue
Block a user