-
Notifications
You must be signed in to change notification settings - Fork 21
feat: start Grafana and Prometheus when --metrics is passed
#109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/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="" | ||
| 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 | ||
|
|
||
| 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 $node_count scrape targets" | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||
| services: | ||||||||||
| prometheus: | ||||||||||
| image: prom/prometheus:latest | ||||||||||
| container_name: lean-prometheus | ||||||||||
MegaRedHand marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| command: | ||||||||||
| - "--config.file=/etc/prometheus/prometheus.yml" | ||||||||||
| - "--storage.tsdb.path=/prometheus" | ||||||||||
| - "--web.console.libraries=/etc/prometheus/console_libraries" | ||||||||||
| - "--web.console.templates=/etc/prometheus/consoles" | ||||||||||
| - "--storage.tsdb.retention.time=30d" | ||||||||||
| - "--web.enable-lifecycle" | ||||||||||
| ports: | ||||||||||
| - "9090:9090" | ||||||||||
| volumes: | ||||||||||
| - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro | ||||||||||
| - prometheus-data:/prometheus | ||||||||||
| networks: | ||||||||||
| - metrics-network | ||||||||||
MegaRedHand marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| restart: unless-stopped | ||||||||||
|
|
||||||||||
| grafana: | ||||||||||
| image: grafana/grafana:latest | ||||||||||
| container_name: lean-grafana | ||||||||||
| ports: | ||||||||||
| - "3000:3000" | ||||||||||
| environment: | ||||||||||
| - GF_SECURITY_ADMIN_USER=admin | ||||||||||
| - GF_SECURITY_ADMIN_PASSWORD=admin | ||||||||||
| - GF_USERS_ALLOW_SIGN_UP=false | ||||||||||
| - GF_AUTH_ANONYMOUS_ENABLED=true | ||||||||||
| - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin | ||||||||||
| - GF_AUTH_DISABLE_LOGIN_FORM=true | ||||||||||
|
Comment on lines
+33
to
+34
|
||||||||||
| - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin | |
| - GF_AUTH_DISABLE_LOGIN_FORM=true | |
| - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer | |
| - GF_AUTH_DISABLE_LOGIN_FORM=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think admin access without login is not a problem for a local devnet
Uh oh!
There was an error while loading. Please reload this page.