-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathgenerate-prometheus-config.sh
More file actions
executable file
·76 lines (60 loc) · 2.06 KB
/
generate-prometheus-config.sh
File metadata and controls
executable file
·76 lines (60 loc) · 2.06 KB
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
#!/bin/bash
# Generate prometheus.yml from validator-config.yaml
# Reads all validators and creates scrape targets using host.docker.internal
#
# Usage: ./generate-prometheus-config.sh <validator-config.yaml> <output-dir>
# Example: ./generate-prometheus-config.sh local-devnet/genesis/validator-config.yaml metrics/prometheus
set -e
validator_config="$1"
output_dir="$2"
if [ -z "$validator_config" ] || [ -z "$output_dir" ]; then
echo "Usage: $0 <validator-config.yaml> <output-dir>"
exit 1
fi
if [ ! -f "$validator_config" ]; then
echo "Error: Validator config not found at $validator_config"
exit 1
fi
if ! command -v yq &> /dev/null; then
echo "Error: yq is required but not installed."
exit 1
fi
mkdir -p "$output_dir"
# Extract node names and metrics ports
node_count=$(yq eval '.validators | length' "$validator_config")
# Build scrape configs
scrape_configs=""
emitted_count=0
for ((i=0; i<node_count; i++)); do
name=$(yq eval ".validators[$i].name" "$validator_config")
port=$(yq eval ".validators[$i].metricsPort" "$validator_config")
if [ -z "$name" ] || [ "$name" == "null" ] || [ -z "$port" ] || [ "$port" == "null" ]; then
echo "Warning: Skipping validator $i (missing name or metricsPort)"
continue
fi
emitted_count=$((emitted_count + 1))
scrape_configs="${scrape_configs}
- job_name: \"${name}\"
static_configs:
- targets: [\"host.docker.internal:${port}\"]
labels:
client: \"${name}\"
instance: \"local\""
done
# Write prometheus.yml
cat > "$output_dir/prometheus.yml" << EOF
# Auto-generated by generate-prometheus-config.sh from validator-config.yaml
# Do not edit manually — changes will be overwritten on next devnet start.
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: "lean-devnet-metrics"
scrape_configs:
${scrape_configs}
# Prometheus self-monitoring
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
EOF
echo "Generated $output_dir/prometheus.yml with $emitted_count scrape targets"