配置 Prometheus 以监控多个微服务

Configure Prometheus for monitoring multiple microservices

我想在 Docker-Compose 上监控一个 Spring Boot 微服务应用程序 运行,其中包含 PrometheusGrafana 的大约 20 个微服务。

最好的方法是什么:
1- 每个微服务都有一个包含多个目标的作业?

scrape_configs:
  - job_name: 'services-job'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['service-one:8080']
        labels:
          group: 'service-one' 
      - targets: ['service-two:8081']
        labels:
          group: 'service-two' 

2- 有多个作业,每个服务都有一个目标?

scrape_configs:
  - job_name: 'service-one-job'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['service-one:8080']
        labels:
          group: 'service-one'
  - job_name: 'service-two-job'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['service-two:8081']
        labels:
          group: 'service-two'  
 

您按工作对目标进行分组的方式与要抓取的端点数量无关。

您需要将具有相同目的的所有目标分组到同一作业中。这正是 documentation 所说的:

A collection of instances with the same purpose, a process replicated for scalability or reliability for example, is called a job.