How to config prometheus to discovery ec2 instance.

211 views
Skip to first unread message

辛二

unread,
Jan 5, 2021, 12:08:44 AM1/5/21
to Prometheus Users
Our prometheus instance has`t public ip, can not discovery ec2 instance directly, how to config prometheus to discovery ec2 instance

辛二

unread,
Jan 5, 2021, 12:11:03 AM1/5/21
to Prometheus Users
config now:

- job_name: 'ec2-sd'

  proxy_url: '172.31.2.224:3001'

  scrape_interval: 5s

  ec2_sd_configs:

      - region: cn-north-1

        access_key: xxxxxxxxx

        secret_key: xxxxxxxxx

        port: 9100

  relabel_configs:

      - source_labels: ["__meta_ec2_tag_Usage"]

        target_label: "usage"

error log:

level=error ts=2021-01-05T05:05:37.883Z caller=refresh.go:95 component="discovery manager scrape" discovery=ec2 msg="Unable to refresh target groups" err="could not describe instances: RequestError: send request failed\ncaused by: Post https://ec2.cn-north-1.amazonaws.com.cn/: dial tcp 54.222.5.106:443: connect: connection timed out"

Stuart Clark

unread,
Jan 5, 2021, 4:15:47 AM1/5/21
to 辛二, Prometheus Users

If you don't have access to the Internet from your Prometheus server you probably need to add a VPC endpoint for the EC2 API (https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html), possibly also setting the endpoint in the EC2 SD configuration (https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config).

辛二

unread,
Jan 5, 2021, 8:53:02 AM1/5/21
to Prometheus Users
Thank you very much, vpc endpoint solved my problem.
Reply all
Reply to author
Forward
0 new messages