Detailed Guide: Creating a Grafana Dashboard for Traefik Metrics in Pangolin Stack
I’ll guide you through setting up a Grafana dashboard to monitor your Traefik metrics in the Pangolin stack step by step.
Part 1: Enable Metrics in Traefik
Step 1: Edit Traefik Configuration
- Edit your Traefik configuration file:
nano config/traefik/traefik_config.yml
- Add the Prometheus metrics endpoint by adding this section:
metrics:
prometheus:
addEntryPointsLabels: true
addServicesLabels: true
addRoutersLabels: true
buckets:
- 0.1
- 0.3
- 1.2
- 5.0
- Your updated file should include this section (make sure it’s at the same indentation level as other main sections like
api:,providers:, etc.):
################################################################
# API and Dashboard
################################################################
api:
insecure: true
dashboard: true
################################################################
# Metrics
################################################################
metrics:
prometheus:
addEntryPointsLabels: true
addServicesLabels: true
addRoutersLabels: true
buckets:
- 0.1
- 0.3
- 1.2
- 5.0
################################################################
# Providers
################################################################
Part 2: Setting Up Prometheus
Step 1: Create a Prometheus Configuration File
- Create a directory for Prometheus:
mkdir -p config/prometheus
- Create a prometheus.yml file:
nano config/prometheus/prometheus.yml
- Add the following configuration:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'traefik'
static_configs:
- targets: ['gerbil:8080']
metrics_path: /metrics
- job_name: 'crowdsec'
static_configs:
- targets: ['crowdsec:6060']
Step 2: Add Prometheus to Your Docker Compose
- Edit your docker-compose.yml file:
nano docker-compose.yml
- Add the Prometheus service:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
networks:
- pangolin
volumes:
- ./config/prometheus:/etc/prometheus
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
ports:
- "9091:9090"
restart: unless-stopped
- Add a volumes section at the end of your docker-compose file if it doesn’t exist:
volumes:
prometheus-data:
Step 3: Modify Traefik Service to Expose Metrics
- In your docker-compose.yml, make sure your Traefik service exposes port 8080:
traefik:
image: traefik:v3.3.3
container_name: traefik
restart: unless-stopped
network_mode: service:gerbil
depends_on:
pangolin:
condition: service_healthy
command:
- --configFile=/etc/traefik/traefik_config.yml
# Add metrics endpoint
- --metrics.prometheus=true
- --metrics.prometheus.addServicesLabels=true
- --metrics.prometheus.addEntryPointsLabels=true
volumes:
- ./config/traefik:/etc/traefik:ro
- ./config/letsencrypt:/letsencrypt
- ./config/traefik/logs:/var/log/traefik
- ./config/traefik/conf/:/etc/traefik/conf/
- ./config/traefik/rules:/rules
- In the gerbil service, make sure port 8080 is exposed:
gerbil:
# your existing configuration
ports:
- 51820:51820/udp
- 443:443
- 80:80
- 8085:8080 # Add this for Traefik metrics
Part 3: Setting Up Grafana
Step 1: Add Grafana to Docker Compose
- Add the Grafana service to your docker-compose.yml:
grafana:
image: grafana/grafana:latest
container_name: grafana
networks:
- pangolin
volumes:
- grafana-data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=strongpassword
- GF_USERS_ALLOW_SIGN_UP=false
ports:
- "3035:3000"
restart: unless-stopped
- Add to the volumes section:
volumes:
prometheus-data:
grafana-data:
Step 2: Apply Changes
- Apply the changes to your Docker Compose stack:
docker compose down
docker compose up -d
- Verify all services are running:
docker ps
Step 3: Configure Grafana
-
Access Grafana in your browser:
-
Log in with:
- Username: admin
- Password: strongpassword (or whatever you set in docker-compose)
-
Add Prometheus as a data source:
- Click on “Configuration” (gear icon) in the left sidebar
- Select “Data sources”
- Click “Add data source”
- Select “Prometheus”
- Set URL to: http://prometheus:9090
- Click “Save & Test” to verify connection
Part 4: Creating the Traefik Dashboard
Method 1: Import a Pre-made Dashboard
- In Grafana, click the “+” icon in the left sidebar
- Select “Import”
- Enter one of these dashboard IDs:
- 17346 (Traefik Dashboard)
- 2870 (Traefik v3 Dashboard)
- Click “Load”
- Select your Prometheus data source
- Click “Import”
Method 2: Build a Custom Dashboard
If you prefer to build your own dashboard, follow these steps:
-
Click the “+” icon in the left sidebar
-
Select “Create Dashboard”
-
Click “Add new panel”
-
Create a panel for Request Rate:
- In the Query field enter:
sum(rate(traefik_service_requests_total[1m])) by (service) - Panel title: “Requests per minute by service”
- Visualization: “Time series”
- Click “Apply”
- In the Query field enter:
-
Create a panel for Response Status Codes:
- Click “Add panel”
- Query:
sum(traefik_service_requests_total) by (code) - Panel title: “Response Status Codes”
- Visualization: “Pie Chart”
- Click “Apply”
-
Create a panel for Request Duration:
- Click “Add panel”
- Query:
histogram_quantile(0.95, sum(rate(traefik_service_request_duration_seconds_bucket[5m])) by (le, service)) - Panel title: “Request Duration (95th percentile)”
- Visualization: “Time series”
- Click “Apply”
-
Create a panel for Connections:
- Click “Add panel”
- Query:
traefik_entrypoint_open_connections{entrypoint="websecure"} - Panel title: “Open Connections (HTTPS)”
- Visualization: “Stat”
- Click “Apply”
-
Save your dashboard:
- Click the save icon in the top right
- Name: “Traefik Monitoring”
- Click “Save”
Part 5: Advanced Traefik Metrics
Here are some additional panels you might want to add:
-
Add a panel for Error Rates:
- New panel
- Query:
sum(rate(traefik_service_requests_total{code=~"5.*"}[1m])) by (service) / sum(rate(traefik_service_requests_total[1m])) by (service) - Title: “Error Rate by Service”
- Visualization: “Time series”
-
Add a panel for Entrypoint Traffic:
- New panel
- Query:
sum(rate(traefik_entrypoint_requests_total[1m])) by (entrypoint) - Title: “Requests by Entrypoint”
- Visualization: “Time series”
-
Add a panel for Top Routes:
- New panel
- Query:
topk(10, sum(traefik_router_requests_total) by (router)) - Title: “Top 10 Routes”
- Visualization: “Bar gauge”
Part 6: Troubleshooting
If you don’t see metrics:
- Check if Traefik is exposing metrics:
curl http://localhost:8080/metrics
- Verify Prometheus can reach Traefik:
docker exec -it prometheus wget -O- gerbil:8080/metrics
- Check Prometheus logs:
docker logs prometheus
-
Check if Traefik metrics are in Prometheus:
- Go to http://your-server-ip:9090
- Try querying:
traefik_entrypoint_requests_total
-
Make sure ports are correctly exposed:
docker-compose ps
Part 7: Setting Up Alerts (Optional)
- In Grafana, go to Alerting in the left sidebar
- Click “New alert rule”
- Configure a rule, for example:
- Query:
sum(rate(traefik_service_requests_total{code=~"5.*"}[1m])) > 5 - Condition: When value is above 5
- For: 5m
- Set rule name: “High error rate”
- Query:
- Set notification channels
- Save the rule
That’s it! You now have a complete Grafana dashboard to monitor your Traefik metrics from your Pangolin stack.