Skip to content

Prometheus Remote Write Connection Refused Fix

DodaTech Updated 2026-06-24 2 min read

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: 30s for reliable connections
  • Use write_relabel_configs to filter out unnecessary metrics
  • Monitor remote write metrics for queue buildup
  • Test remote write endpoint with curl before configuring Prometheus

Common Mistakes with remote write

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead 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

### What remote write backends are supported?

Supported backends: Mimir, Cortex, Thanos Receive, Grafana Cloud, VictoriaMetrics, InfluxDB, and any system implementing the Prometheus remote write protocol. Each has specific URL paths and authentication requirements documented in their setup guides.

How do I handle remote write failures?

Prometheus queues failed writes and retries with exponential backoff. Configure queue_config.max_shards to increase parallelism, and queue_config.capacity to buffer more samples. If failures persist, check network connectivity, auth credentials, and backend capacity.

Can I send data to multiple remote write endpoints?

Yes, configure multiple remote_write entries. Each endpoint receives all metrics independently. This is useful for sending to both a primary storage (Mimir) and a backup (S3-compatible object storage via Thanos).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro