Out of the box, Prometheus can be configured to leverage the native APIs offered by cloud providers such as AWS, GCE, Azure, and OpenStack to detect provisioned compute node instances and make them available as targets for scraping.
Each node discovered by Prometheus is automatically annotated with a series of provider-specific meta labels. These labels can then be referenced by operator-defined match rules to filter out any nodes that the operator is not interested in scraping.
As an example, let's say that we only want to scrape the EC2 instances that contain a tag with the name scrape and the value true. We can use a configuration block such as the following one to achieve this:
ec2_sd_configs: # omitted: EC2 access keys (see prometheus documentation) relabel_configs: - source_labels: ["__meta_ec2_tag_scrape"] regex: "true" action: "keep"
When Prometheus discovers a new EC2 instance, it will automatically iterate its set of tags and generate labels whose names follow the pattern __meta_ec2_tag_<tagkey> and set their value to the observed tag value. The filtering rule in the preceding snippet will discard any nodes where the value of the __meta_ec2_tag_scrape label does not match the provided regular expression.