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 →
- Use
ec2_sd_configswith an IAM role allowingec2:DescribeInstances. - 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
- Alert on
up == 0for 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.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateA developer added `user_id` as a metric label. What is the problem and what do you advise?BeginnerYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYou run 3 Kubernetes clusters. Compare federation, remote_write and Thanos sidecar for a global view.Advanced