Static File Service Discovery
How Prometheus discovery monitoring targets with static files
When prometheus_sd_method == ‘static’, Prometheus will use static conf files to manage monitoring targets.
Prometheus FHS
Monitoring Targets are placed @ /etc/prometheus/targets/, And divided by modules into several sub directories: infra, nodes, pgsql, redis, ….
#------------------------------------------------------------------------------# Config FHS#------------------------------------------------------------------------------# /etc/prometheus/# ^-----prometheus.yml # prometheus main config file# ^-----alertmanager.yml # alertmanger main config file# ^-----@bin # util scripts: check,reload,status,new# ^-----@rules # record & alerting rules definition# ^-----@infra # infrastructure rules & alert# ^-----@nodes # nodes rules & alert# ^-----@pgsql # pgsql rules & alert# ^-----@redis # redis rules & alert# ^-----@.......... # etc...# ^-----@targets # file based service discovery targets definition# ^-----@infra # infra static targets definition# ^-----@nodes # nodes static targets definition# ^-----@pgsql # pgsql static targets definition# ^-----@redis # redis static targets definition# ^-----@..... # other targets#------------------------------------------------------------------------------
Targets
/etc/prometheus/targets├── nodes│ ├── 10.10.10.13.yml│ ├── 10.10.10.10.yml│ ├── 10.10.10.11.yml│ ├── 10.10.10.12.yml├── pgsql│ ├── pg-meta-1.yml│ ├── pg-test-2.yml│ ├── pg-test-3.yml│ ├── pg-test-1.yml├── infra│ ├── 10.10.10.10.yml├── redis│ ├── redis-common-1.yml│ ├── redis-test-2.yml│ ├── redis-meta-1.yml│ ├── redis-test-1.yml
INFRA Targets
INFRA监控对象以元节点的IP地址作为文件名,内容如下:
---#------------------------------------------------------------------------------# Prometheus (9090)#------------------------------------------------------------------------------- labels: { ip: 10.10.10.10, type: prometheus }targets:- 10.10.10.10:9090#------------------------------------------------------------------------------# AlertManager (9093)#------------------------------------------------------------------------------- labels: { ip: 10.10.10.10, type: alertmanager }targets:- 10.10.10.10:9093#------------------------------------------------------------------------------# Grafana (3000)#------------------------------------------------------------------------------- labels: { ip: 10.10.10.10, type: grafana }targets:- 10.10.10.10:3000#------------------------------------------------------------------------------# Loki (3100)#------------------------------------------------------------------------------- labels: { ip: 10.10.10.10, type: loki }targets:- 10.10.10.10:3100#------------------------------------------------------------------------------# Nginx (Exporter @ 9113)#------------------------------------------------------------------------------- labels: { ip: 10.10.10.10, type: nginx }targets:- 10.10.10.10:9113
DCS Targets
DCS监控对象直接定于 /etc/prometheus/prometheus.yml 主配置文件中:
- job_name: consulmetrics_path: /v1/agent/metricsparams:format: ['prometheus']static_configs: [ { targets: [ 127.0.0.1:8500 ] , labels: { ip: 10.10.10.10, type: consul , job: infra } } ]- job_name: etcdmetrics_path: /metricsstatic_configs:- { targets: [ 10.10.10.11:2379 ] , labels: { ip: 10.10.10.11, ins: meta-2, type: etcd , job: infra } }- { targets: [ 10.10.10.12:2379 ] , labels: { ip: 10.10.10.12, ins: meta-3, type: etcd , job: infra } }- { targets: [ 10.10.10.10:2379 ] , labels: { ip: 10.10.10.10, ins: meta-1, type: etcd , job: infra } }
NODES Targets
NODES监控对象以IP地址作为监控对象文件名,内容如下所示:
$ cat nodes/10.10.10.10.yml
# 10.10.10.10- labels: { ip: 10.10.10.10 , ins: pg-meta-1 , cls: pg-meta }targets:- 10.10.10.10:9100 # node_exporter- 10.10.10.10:9323 # docker- 10.10.10.10:9080 # promtail
PGSQL Targets
PGSQL监控对象以实例名作为监控对象文件名,内容如下所示:
$ cat pgsql/pg-meta-1.yml
# pg-meta-1 [primary] @ 10.10.10.10- labels: { cls: pg-meta, ins: pg-meta-1, ip: 10.10.10.10 }targets:- 10.10.10.10:9630 # postgres- 10.10.10.10:9631 # pgbouncer- 10.10.10.10:8008 # patroni- 10.10.10.10:9101 # haproxy
REDIS Targets
REDIS监控对象以Redis节点名作为监控对象文件名,内容如下所示:
$ cat pgsql/redis-common-1.yml
# redis-common-1 @ 10.10.10.13- labels: { cls: redis-common, ins: redis-common-1-6501, instance: 10.10.10.13:6501 }targets: [ redis://10.10.10.13:6501 ]- labels: { cls: redis-common, ins: redis-common-1-6502, instance: 10.10.10.13:6502 }targets: [ redis://10.10.10.13:6502 ]- labels: { cls: redis-common, ins: redis-common-1-6503, instance: 10.10.10.13:6503 }targets: [ redis://10.10.10.13:6503 ]
Last modified 2022-06-04: fill en docs (5a858d3)