Fix Prometheus 'context deadline exceeded' Scrape Errors
The Error: "context deadline exceeded"
You open the Prometheus Targets page and see targets stuck in DOWN state with this error:
Get "http://your-target:9090/metrics": context deadline exceeded
This means Prometheus sent a scrape request but the target didn't respond before the configured timeout. Your metrics have gaps, and your alerts are probably firing on stale data.
Root Cause
Prometheus has a default scrape timeout of 10 seconds. When a target takes longer than that to respond, Prometheus cancels the request and logs the error. Common reasons include:
- Target is overloaded and generating metrics too slowly
- Network latency between Prometheus and the target (especially cross-region)
- Too many metrics being exposed on a single endpoint (hundreds of thousands of time series)
- DNS resolution delays adding seconds to each scrape
- Firewall or security group intermittently blocking traffic
Step-by-Step Fix
1. Check the Actual Scrape Duration
Query Prometheus itself to see how long scrapes are taking:
scrape_duration_seconds{job="your-job-name"}
If scrapes regularly take 8-9 seconds on a 10-second timeout, you've found the bottleneck.
2. Increase the Scrape Timeout
Edit your prometheus.yml to give slow targets more time:
scrape_configs:
- job_name: 'slow-target'
scrape_interval: 30s
scrape_timeout: 25s
static_configs:
- targets: ['your-target:9090']
The scrape_timeout must always be less than or equal to scrape_interval. If your scrape takes 20 seconds, set the interval to at least 30 seconds.
3. Verify Network Connectivity
From the Prometheus server, test that you can reach the target:
# Test basic connectivity
curl -w "Time: %{time_total}s\n" -o /dev/null -s http://your-target:9090/metrics
# Check DNS resolution time
dig your-target | grep "Query time"
# Test with a specific timeout
curl --max-time 15 http://your-target:9090/metrics | wc -l
If curl takes more than a few seconds, the problem is network-level, not Prometheus configuration.
4. Reduce Metrics Cardinality on the Target
If the target exposes too many metrics, reduce them at the source or filter in Prometheus:
scrape_configs:
- job_name: 'high-cardinality-target'
scrape_timeout: 20s
metric_relabel_configs:
- source_labels: [__name__]
regex: 'go_.*'
action: drop
This drops all Go runtime metrics, which can significantly reduce scrape payload size.
5. Reload Prometheus
After editing the config, reload without restarting:
# Send SIGHUP
kill -HUP $(pidof prometheus)
# Or use the lifecycle API if enabled
curl -X POST http://localhost:9090/-/reload
6. Confirm the Fix
Check the Targets page again at http://localhost:9090/targets. The target should show UP and the Last Scrape column should show a duration well under your timeout.
Prevention Tips
- Set realistic timeouts from the start. If you know a target is slow, configure
scrape_timeoutwhen you add it. - Monitor scrape durations. Alert when
scrape_duration_secondsexceeds 80% of the timeout:scrape_duration_seconds > 0.8 * 10. - Use Prometheus federation for remote targets instead of scraping across high-latency links.
- Keep metrics endpoints lean. Avoid exposing high-cardinality labels that inflate response size.
- Use service discovery with relabeling to drop targets that are known to be flaky or retired.
Was this article helpful?
Senior Kubernetes Architect
10+ years orchestrating containers in production. Battle-tested opinions on everything from pod scheduling to service mesh. I've seen clusters burn and helped rebuild them better.
Related Articles
Prometheus Federation: Scraping Metrics Across Multiple Data Centers With A Global View
If you're running Kubernetes clusters across multiple data centers or cloud regions, you've probably felt the pain of fragmented observability. Each cluste...
Prometheus Target Down Error: Debugging Failed Scrapes And Network Connectivity Issues
You've deployed Prometheus, configured your targets, and everything looks perfect in your YAML files. Then you check the Prometheus UI and see those dreade...
Fix Prometheus High Memory Usage and OOM Kills
Diagnose and fix Prometheus out-of-memory crashes caused by high cardinality, excessive retention, or misconfigured storage with practical steps and commands.
Prometheus Remote Write Tuning For High-Throughput Long-Term Storage With Thanos
If you're running Prometheus at scale with Thanos for long-term storage, misconfigured remote write settings are silently killing your performance — and yo...
Prometheus Recording Rules For High-Cardinality Metric Aggregation
If you've been running Prometheus in production for more than a few months, you've probably hit the wall. Dashboards that take 30 seconds to load. Alerts t...
Prometheus Alerting Rules: From Noisy to Actionable
Write Prometheus alerting rules that page on real problems, not noise — with practical PromQL, severity levels, and runbook patterns.
More in Prometheus
View all →Prometheus Service Discovery in Kubernetes: Auto-Scrape Everything
Configure Prometheus Kubernetes service discovery to automatically scrape pods, services, and nodes — no manual target management.
PromQL Queries You'll Actually Use in Production
A practical PromQL reference covering request rates, latency percentiles, resource usage, and Kubernetes workload queries for real production dashboards.