Prometheus Remote Write Connection Refused Fix
In this tutorial, you'll learn about Prometheus Remote Write Connection Refused Fix. We cover key concepts, practical examples, and best practices.
Your Prometheus logs remote write: remote server returned HTTP status 401 Unauthorized — the remote write endpoint requires authentication, the URL is wrong, or the remote storage is not reachable. Remote write sends Prometheus data to long-term storage systems.
The Problem
remote_write:
- url: http://mimir:9009/api/v1/push
WARN[0000] remote write: remote server returned HTTP status 400 Bad Request
The Mimir endpoint requires authentication and uses a specific URL path. The url is missing the required tenant ID or auth header.
Step-by-Step Fix
1. Configure basic authentication
remote_write:
- url: https://mimir.example.com/api/v1/push
basic_auth:
username: 'your-tenant-id'
password: 'your-api-key'
2. Configure bearer token authentication
remote_write:
- url: https://grafana.com/api/prom/push
authorization:
type: Bearer
credentials: 'your-grafana-cloud-token'
3. Configure remote write for specific storage backends
# Cortex / Mimir
remote_write:
- url: https://mimir.example.com/api/v1/push
headers:
X-Scope-OrgID: 'my-tenant'
# Thanos
remote_write:
- url: https://thanos.example.com/api/v1/receive
basic_auth:
username: 'admin'
password_file: /etc/prometheus/thanos-passwd
# Grafana Cloud
remote_write:
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push
basic_auth:
username: 'instance-id'
password: 'cloud-api-key'
4. Tune remote write performance
remote_write:
- url: https://mimir.example.com/api/v1/push
remote_timeout: 30s
queue_config:
max_samples_per_send: 500
capacity: 10000
max_shards: 10
min_shards: 2
write_relabel_configs:
- source_labels: [__name__]
regex: 'go_.*'
action: drop
5. Monitor remote write health
// Remote write success rate
rate(prometheus_remote_storage_succeeded_total[5m])
// Remote write failures
rate(prometheus_remote_storage_failed_total[5m])
// Queue length
prometheus_remote_storage_shards
prometheus_remote_storage_samples_pending
Expected output:
Remote write: OK
Samples sent: 15000/sec
Shards: 5 (min=2, max=10)
Queue: 0 pending
Prevention Tips
- Configure authentication for remote write immediately
- Use
remote_timeout: 30sfor reliable connections - Use
write_relabel_configsto filter out unnecessary metrics - Monitor remote write metrics for queue buildup
- Test remote write endpoint with
curlbefore configuring Prometheus
Common Mistakes with remote write
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro