Prometheus基于EC2的服务发现
创建AWS用户获取AK/SK
此用户可以通过AK/SK访问AWS, 且具有ec2:DescribeInstances
权限
配置基于EC2服务发现
- 因为AWS跨区内网调用会收流量费用,为节省费用,我在每个区部署了一个Prometheus实例,所以比如B区的机器,我会加上
service_type:node_exporter_b_zone
的tag,这样的话就会自动拉取拥有service_type:node_exporter_b_zone
这个tag的机器数据,当然前提是机器上安装了node_exporter这个组件
- job_name: 'ec2-b-zone'
ec2_sd_configs:
- access_key: 创建的id
secret_key: 创建的key
region: us-west-1 # ec2运行的region
relabel_configs:
- source_labels: [__meta_ec2_private_ip]
regex: '(.*)'
replacement: '${1}:9100'
target_label: __address__
- source_labels: [__meta_ec2_tag_service_type]
regex: node_exporter_b_zone
action: keep
官网文档
EC2 SD configurations allow retrieving scrape targets from AWS EC2 instances. The private IP address is used by default, but may be changed to the public IP address with relabeling.
The IAM credentials used must have the ec2:DescribeInstances
permission to discover scrape targets, and may optionally have the ec2:DescribeAvailabilityZones
permission if you want the availability zone ID available as a label (see below).
The following meta labels are available on targets during relabeling:
__meta_ec2_ami
: the EC2 Amazon Machine Image__meta_ec2_architecture
: the architecture of the instance__meta_ec2_availability_zone
: the availability zone in which the instance is running__meta_ec2_availability_zone_id
: the availability zone ID in which the instance is running (requiresec2:DescribeAvailabilityZones
)__meta_ec2_instance_id
: the EC2 instance ID__meta_ec2_instance_lifecycle
: the lifecycle of the EC2 instance, set only for 'spot' or 'scheduled' instances, absent otherwise__meta_ec2_instance_state
: the state of the EC2 instance__meta_ec2_instance_type
: the type of the EC2 instance__meta_ec2_ipv6_addresses
: comma separated list of IPv6 addresses assigned to the instance's network interfaces, if present__meta_ec2_owner_id
: the ID of the AWS account that owns the EC2 instance__meta_ec2_platform
: the Operating System platform, set to 'windows' on Windows servers, absent otherwise__meta_ec2_primary_subnet_id
: the subnet ID of the primary network interface, if available__meta_ec2_private_dns_name
: the private DNS name of the instance, if available__meta_ec2_private_ip
: the private IP address of the instance, if present__meta_ec2_public_dns_name
: the public DNS name of the instance, if available__meta_ec2_public_ip
: the public IP address of the instance, if available__meta_ec2_region
: the region of the instance__meta_ec2_subnet_id
: comma separated list of subnets IDs in which the instance is running, if available__meta_ec2_tag_<tagkey>
: each tag value of the instance__meta_ec2_vpc_id
: the ID of the VPC in which the instance is running, if available
天天向上,空杯心态。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架