Prometheus自动发现配置

Prometheus支持基于Consul自动发现

prometheus.yml:

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
global:
scrape_interval: 1s
scrape_timeout: 1s
evaluation_interval: 5s

alerting:
alertmanagers:
- static_configs:
- targets: ['10.1.7.211:9093']

rule_files:
- 'rules/*.yml'

scrape_configs:
- job_name: prometheus
metrics_path: /metrics
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus


- job_name: consul_sd
consul_sd_configs:
- server: '192.168.100.140:8500'
datacenter: dc01
services: []

relabel_configs:
- source_labels: [__meta_consul_tags]
regex: '.*,prometheus-target,.*'
action: keep

- source_labels: [__meta_consul_service]
target_label: sn

- job_name: consul_sd_dev
consul_sd_configs:
- server: '10.1.7.211:8500'
datacenter: dc1
services: []

relabel_configs:
- source_labels: [__meta_consul_tags]
regex: '.*prometheus-target.*'
action: keep

- source_labels: ['__address__']
# regex: '.*:(.*)'
regex: '127.0.0.1:(.*)'
target_label: '__address__'
replacement: '10.1.7.211:$1'