Prometheus-自动发现监控 AWS EC2

  1. 右上角 -> 安全凭证 -> 创建策略 -> JSON 编辑(如下JSON格式) -> 下一步 -> 输入创建名字 Prometheus-ec2-sd-config -> 创建

  2. 右上角 -> 安全凭证 -> 用户 -> 创建用户(Prometheus-ec2-sd-config) -> 选择直接附加策略(Prometheus-ec2-sd-config) -> 创建

  3. 用户-> 创建访问秘钥 -> 复制你的秘钥

  4. 添加到 Prometheus 配置文件 (如下Yaml 格式)

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeRegions"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
scrape_configs:
  - job_name: aws-dplwer-pro
    honor_timestamps: true
    scrape_interval: 30s
    scrape_timeout: 10s
    metrics_path: /metrics
    scheme: http
    ec2_sd_configs:
      - port:  9100
        refresh_interval: 30s
        region: ap-northeast-1               # EC2实例区域
        access_key: 'access_key'             # access_key
        secret_key: 'secret_key'             # secret_key
    relabel_configs:
      - source_labels: [__meta_ec2_tag_Name] # 把 __meta_ec2_tag_Name 值赋予 label
        separator: ':'
        regex: '(.*)'
        replacement: '${1}'
        target_label: label
      - source_labels: [__meta_ec2_public_ip] # 把 __meta_ec2_public_ip 公网IP赋值给 __address__, 默认展示内网
        regex: '(.*)'
        replacement: '${1}:9100'
        target_label: __address__
        action: replace
      - source_labels: [__meta_ec2_public_ip] # 把 __meta_ec2_public_ip 公网IP赋值给 intance
        regex: '(.*)'
        replacement: '${1}:9100'
        target_label: instance
        action: replace

Last updated