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
天天向上,空杯心态。