Prometheus的自动发现


image-20240927143821265

作业(Job)和实例(Instance)

  • Instance: 能够接收Prometheus Server数据Scrape操作的每个网络网络端点(endpoint) 即为一个Instance(实例)
  • 通常 具有类似功能的Instance的集合称为一个Job 如: 一个MySQL主从复制集群中的所有MySQL进程

image-20240927145837692

编辑Prometheus的配置文件

### 编辑prometheus配置文件
[root@master ~]# cat /app/prometheus/prometheus.yml 
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["10.0.0.200:9090"]
  ## 在下方添加自动发现的对应的文件
  - job_name: "prome_file_sd"   ##在prometheus网页中组名
    file_sd_configs:
    - files:
      - /app/prometheus/file_sd/agent.yml    ## 指定自动发现的文件
      refresh_interval: 5s				    ##  更新自动发现的时间
### 编辑自动发现文件
[root@master ~]# cat /app/prometheus/file_sd/agent.yml 
[
  {
    "targets":  ["10.0.0.200:9100","10.0.0.201:9100","10.0.0.202:9100","10.0.0.203:9100"],
    "labels": {
      "agent": "node_exporter"
    }
  },
  {
    "targets": ["10.0.0.200:8080","10.0.0.201:8080","10.0.0.202:8080","10.0.0.203:8080"],
    "labels": {
      "agent": "cAdVisor"
    }
   }
] 
#### 安装容器监控软件
docker run --name cadvisor -p 8080:8080 -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro  -v /var/lib/docker:/var/lib/docker:ro  -d  google/cadvisor:latest

image-20240927143237471

image-20240927143354396