【问题标题】:Is there a way to use the aws_ec2 ansible inventory plugin to define a prometheus target group dynamicly?有没有办法使用 aws_ec2 ansible inventory 插件来动态定义 prometheus 目标组?
【发布时间】:2019-12-14 15:43:22
【问题描述】:
我正在尝试配置一个使用 ansible 的 prometheus 服务器。我想监视一些 aws 实例(ec2),但我坚持使用 prometheus 的目标。我可能应该使用 json 文件来定义我的目标,但是当我使用 ansible 创建一个新实例时,我不知道如何更新该文件。我还在 ansible 上使用 aws_ec2 插件来动态库存。
所以我的问题是:如何使用库存插件来不断更新普罗米修斯的目标文件而不需要手动执行?
【问题讨论】:
标签:
amazon-ec2
ansible
prometheus
【解决方案1】:
您可以将 prometheus 服务发现与用于 aws_ec2 库存的相同/相似过滤器一起使用。我也花时间在这个问题上,但对结果非常满意。基本示例:
scrape_configs:
- ec2_sd_configs:
- filters:
- name: tag:Environment
values:
- PROD
job_name: ec2
relabel_configs:
- replacement: ${1}.prod.yourdomain.com:9100
source_labels:
- __meta_ec2_tag_dnsname
target_label: __address__
- source_labels:
- __meta_ec2_tag_Name
target_label: instance
- ec2_sd_configs:
- filters:
- name: tag:Environment
values:
- PROD
job_name: application_actuators
relabel_configs:
- replacement: ${1}.prod.yourdomain.com:9001
source_labels:
- __meta_ec2_tag_dnsname
target_label: __address__
- source_labels:
- __meta_ec2_tag_Name
target_label: instance
- action: drop
regex: ^$
source_labels:
- __meta_ec2_tag_application
- regex: (.+)
replacement: /$1/api/actuator/prometheus
source_labels:
- __meta_ec2_tag_application
target_label: __metrics_path__
ec2_sd_config documentation
此配置由ansible 生成。