feat: add Prometheus configuration and enable metrics scraping for Traefik

This commit is contained in:
2026-07-12 09:27:40 +08:00
parent 2c040bc1de
commit dae6e62e30
3 changed files with 31 additions and 1 deletions
+5
View File
@@ -162,6 +162,11 @@ services:
- --log.level=INFO
# Enable the Dashboard and API
- --api=true
# Enable Prometheus metrics for scraping by Prometheus
- --metrics.prometheus=true
- --metrics.prometheus.buckets=0.1,0.3,1.2,5.0
- --metrics.prometheus.addEntryPointsLabels=true
- --metrics.prometheus.addServicesLabels=true
networks:
# Use the public network created to be shared between Traefik and
# any other service that needs to be publicly available with HTTPS
+7 -1
View File
@@ -1,6 +1,10 @@
volumes:
prometheus_data: {}
configs:
prometheus_config:
file: ./prometheus/prometheus.yml
networks:
traefik-public:
external: true
@@ -17,8 +21,10 @@ services:
- '--web.enable-lifecycle'
volumes:
- prometheus_data:/prometheus
- /var/data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- /var/data/prometheus/rules:/etc/prometheus/rules:ro
configs:
- source: prometheus_config
target: /etc/prometheus/prometheus.yml
networks:
- traefik-public
deploy:
+19
View File
@@ -0,0 +1,19 @@
# Prometheus configuration for the Swarm stack.
# Mounted into the Prometheus container as a Docker config.
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
# Scrape Prometheus itself
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# Scrape Traefik Prometheus metrics
# Both services are on the traefik-public overlay network,
# so 'traefik' resolves via Swarm DNS.
- job_name: 'traefik'
static_configs:
- targets: ['traefik:8080']
metrics_path: /metrics