Interview Prep/Monitoring & Observability/Prometheus and PromQL at Scale

Your EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?

IntermediateScenarioPrometheus and PromQL at Scale
Answer

Situation read → Static target lists go stale. Use service discovery plus relabeling to select and label targets.

What I'd do →

  1. Use ec2_sd_configs with an IAM role allowing ec2:DescribeInstances.
  2. Filter and label with relabeling:
scrape_configs:
  - job_name: node
    ec2_sd_configs:
      - region: ap-south-1
        port: 9100
        filters:
          - name: tag:Monitoring
            values: ["enabled"]
    relabel_configs:
      - source_labels: [__meta_ec2_tag_Name]
        target_label: instance_name
      - source_labels: [__meta_ec2_availability_zone]
        target_label: az
  1. Alert on up == 0 for 5 minutes, since instances that are terminated drop out of discovery and do not alert.

Why → Discovery reflects the real fleet and removes manual edits.

Interview tip → Mention file_sd for custom sources and kubernetes_sd for pods and services.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Prometheus and PromQL at Scale