blob: d70aa952747a3f5657d98ee273bfd08049e40754 (
plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/bin/bash
# Cleanup benchmark metrics from Prometheus
# This allows running benchmarks from a clean state
set -e
echo "=== Prometheus Benchmark Metrics Cleanup ==="
echo ""
# Port-forward to Prometheus
echo "Setting up port-forward to Prometheus..."
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090 > /tmp/cleanup-pf.log 2>&1 &
PF_PID=$!
echo "Port-forward started (PID: $PF_PID)"
sleep 5
# Check if Admin API is enabled
echo ""
echo "Checking if Prometheus Admin API is enabled..."
ADMIN_CHECK=$(curl -s -o /dev/null -w "%{http_code}" -X POST "http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]=epimetheus_benchmark_cpu_usage")
if [ "$ADMIN_CHECK" = "204" ] || [ "$ADMIN_CHECK" = "200" ]; then
echo "✅ Admin API is enabled"
echo ""
echo "Deleting benchmark metrics..."
# Delete all benchmark metrics
METRICS=(
"epimetheus_benchmark_cpu_usage"
"epimetheus_benchmark_memory_bytes"
"epimetheus_benchmark_disk_io_bytes"
"epimetheus_benchmark_network_rx_bytes"
"epimetheus_benchmark_network_tx_bytes"
"epimetheus_benchmark_requests_total"
"epimetheus_benchmark_errors_total"
"epimetheus_benchmark_response_time_ms"
"epimetheus_benchmark_active_connections"
"epimetheus_benchmark_queue_depth"
)
for METRIC in "${METRICS[@]}"; do
echo " Deleting: $METRIC"
curl -s -X POST "http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]=$METRIC" > /dev/null
done
echo ""
echo "Triggering tombstone cleanup (this removes deleted data from disk)..."
curl -s -X POST "http://localhost:9090/api/v1/admin/tsdb/clean_tombstones" > /dev/null
echo ""
echo "✅ Cleanup complete!"
elif [ "$ADMIN_CHECK" = "405" ]; then
echo "❌ Admin API is NOT enabled"
echo ""
echo "To enable the Admin API, update your Prometheus configuration:"
echo ""
echo "In f3s/prometheus/persistence-values.yaml, add:"
echo ""
echo "prometheus:"
echo " prometheusSpec:"
echo " additionalArgs:"
echo " - name: web.enable-admin-api"
echo " value: \"\""
echo ""
echo "Then upgrade Prometheus:"
echo " cd /home/paul/git/conf/f3s/prometheus"
echo " just upgrade"
echo ""
echo "WARNING: Admin API should only be enabled in development/test environments!"
echo ""
echo "Alternative: Delete benchmark data files manually:"
echo " kubectl exec -n monitoring prometheus-prometheus-kube-prometheus-prometheus-0 -- sh -c 'rm -rf /prometheus/data/wal/*'"
echo " kubectl delete pod -n monitoring prometheus-prometheus-kube-prometheus-prometheus-0"
else
echo "⚠️ Unexpected response: HTTP $ADMIN_CHECK"
fi
echo ""
echo "Cleaning up port-forward..."
kill $PF_PID 2>/dev/null || true
echo ""
echo "Done!"
|