官方文档地址: https://prometheus.io/docs/prometheus/latest/configuration/configuration/

访问地址: http://localhost:9090/graph

静态配置单个服务

- job_name: 'clever-notification-server'
  metrics_path: '/actuator/prometheus'
  scrape_interval: 15s
  scrape_timeout: 10s
  scheme: http
  static_configs:
  - targets:
    - '127.0.0.1:28080'
    labels:
      k1: v1
      k2: v2

集成consul服务自动发现

# 集成consul 动态监控服务
- job_name: 'consul-prometheus'
metrics_path: '/actuator/prometheus'
consul_sd_configs:
- server: '127.0.0.1:8500'
tag: 'group=svc'
refresh_interval: 30s
# relabel_configs:
#   - source_labels: [__meta_consul_tags]
#     regex: .*prometheus-target.*
#     action: keep

动态加载配置

- job_name: 'test'
  file_sd_configs:
    - files: ['/etc/prometheus/sd_config/*.yml']
      refresh_interval: 5s

重启prometheus服务后在路径/etc/prometheus/sd_config下新建test.yml如下:

- targets: [ "192.168.93.192:8080" ]
  labels:
    group: "my_test_group"

5s内就会自动读取 test.yml 并添加新的目标

参考

https://github.com/prometheus

文档更新时间: 2019-07-19 19:49   作者:lizw