autoscript/templates/monitoring/prometheus.yml
2025-08-03 13:22:49 +02:00

47 lines
1.5 KiB
YAML

global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "/etc/prometheus/rules/*.yml"
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'docker-services'
docker_sd_configs:
- host: unix:///var/run/docker.sock
relabel_configs:
# Scrape only containers that have a prometheus.scrape=true label
- source_labels: [__meta_docker_container_label_prometheus_scrape]
action: keep
regex: true
# Use the container name as the instance label
- source_labels: [__meta_docker_container_name]
action: replace
target_label: instance
regex: '/(.+)'
# Allow overriding the port
- source_labels: [__meta_docker_container_label_prometheus_port]
action: replace
target_label: __address__
regex: '(.+)'
replacement: '${1}'
# Use the custom port if specified, otherwise use the first exposed port
- source_labels: [__meta_docker_container_label_prometheus_port, __meta_docker_port_private]
action: replace
target_label: __address__
regex: '([^;]+);.*'
replacement: '${1}'
- source_labels: [__address__, __meta_docker_container_label_prometheus_port]
action: replace
target_label: __address__
regex: '([^:]+)(?::\d+)?;(\d+)'
replacement: '${1}:${2}'