静态文件服务发现

    当使用 prometheus_sd_method == ‘static’ 的静态文件服务发现模式时,Prometheus会使用静态文件进行服务发现。

    配置文件地址默认为 目录,根据所属模块又分为几个子目录:infra, nodes, pgsql, redis, ….

    监控对象文件

    1. /etc/prometheus/targets
    2. ├── nodes
    3. ├── 10.10.10.13.yml
    4. ├── 10.10.10.10.yml
    5. ├── 10.10.10.11.yml
    6. ├── 10.10.10.12.yml
    7. ├── pgsql
    8. ├── pg-meta-1.yml
    9. ├── pg-test-2.yml
    10. ├── pg-test-3.yml
    11. ├── pg-test-1.yml
    12. ├── infra
    13. ├── 10.10.10.10.yml
    14. ├── redis
    15. ├── redis-common-1.yml
    16. ├── redis-test-2.yml
    17. ├── redis-meta-1.yml
    1. ---
    2. # Prometheus (9090)
    3. #------------------------------------------------------------------------------
    4. - labels: { ip: 10.10.10.10, type: prometheus }
    5. targets:
    6. - 10.10.10.10:9090
    7. #------------------------------------------------------------------------------
    8. # AlertManager (9093)
    9. #------------------------------------------------------------------------------
    10. - labels: { ip: 10.10.10.10, type: alertmanager }
    11. targets:
    12. - 10.10.10.10:9093
    13. #------------------------------------------------------------------------------
    14. # Grafana (3000)
    15. #------------------------------------------------------------------------------
    16. - labels: { ip: 10.10.10.10, type: grafana }
    17. targets:
    18. - 10.10.10.10:3000
    19. #------------------------------------------------------------------------------
    20. # Loki (3100)
    21. targets:
    22. - 10.10.10.10:3100
    23. #------------------------------------------------------------------------------
    24. # Nginx (Exporter @ 9113)
    25. #------------------------------------------------------------------------------
    26. - labels: { ip: 10.10.10.10, type: nginx }
    27. targets:
    28. - 10.10.10.10:9113

    DCS监控对象

    DCS监控对象直接定于 /etc/prometheus/prometheus.yml 主配置文件中:

    NODES监控对象以IP地址作为监控对象文件名,内容如下所示:

    1. $ cat nodes/10.10.10.10.yml
    1. # 10.10.10.10
    2. - labels: { ip: 10.10.10.10 , ins: pg-meta-1 , cls: pg-meta }
    3. targets:
    4. - 10.10.10.10:9100 # node_exporter
    5. - 10.10.10.10:9323 # docker
    6. - 10.10.10.10:9080 # promtail

    PGSQL监控对象

    1. # pg-meta-1 [primary] @ 10.10.10.10
    2. - labels: { cls: pg-meta, ins: pg-meta-1, ip: 10.10.10.10 }
    3. targets:
    4. - 10.10.10.10:9630 # postgres
    5. - 10.10.10.10:9631 # pgbouncer
    6. - 10.10.10.10:8008 # patroni

    REDIS监控对象以Redis节点名作为监控对象文件名,内容如下所示: