Learn Labs
Scaling & High Availability

Remote Write & Agent Mode

Shipping samples elsewhere, and Prometheus as a forwarder

Federation pulls a few series. Remote write pushes every sample, as it's ingested, to another system over HTTP. It's how Prometheus feeds long-term storage (Mimir, Thanos Receive, VictoriaMetrics, managed services like Grafana Cloud, Amazon Managed Prometheus) and how edge clusters send data to a central place.

How it works

scraperemote_writenode-exporteragentcluster=edge-1WALbuffer while behindqueue shardskeep-list filtercentral Prometheus/api/v1/write

Remote write reads the WAL. A sample is appended locally first, then a background process tails the WAL, batches samples into snappy-compressed protobuf requests, and sends them through a number of parallel shards. If the remote end is slow or down, the queue backs up and Prometheus retries. Since data comes from the WAL, nothing is lost for roughly the WAL's lifetime (about 2 hours). Beyond that, the oldest unsent data is dropped.

remote_write:
- url: https://mimir.example.com/api/v1/push
  basic_auth:
    username: tenant-1
    password_file: /etc/prometheus/secrets/remote-write
  queue_config:
    capacity: 10000              # samples buffered per shard
    max_shards: 50               # upper bound on parallel senders
    max_samples_per_send: 2000
  write_relabel_configs:         # filter or rewrite before sending
    - source_labels: [__name__]
      regex: "go_.*|python_gc_.*"
      action: drop

Prometheus scales the shard count automatically between min_shards and max_shards, based on how far behind it is.

Watching remote write

prometheus_remote_storage_samples_pendingsamples queued, not yet sentprometheus_remote_storage_shardscurrent parallelismrate(prometheus_remote_storage_samples_failed_total[5m])rejected by the remoterate(prometheus_remote_storage_samples_retried_total[5m])transient failuresprometheus_remote_storage_queue_highest_sent_timestamp_secondsnewest sample delivered

The key health signal is lag: how far behind the remote is.

# seconds between the newest sample in the WAL and the newest one delivered
prometheus_remote_storage_highest_timestamp_in_seconds
- ignoring(remote_name, url) group_right
prometheus_remote_storage_queue_highest_sent_timestamp_seconds

Alert if lag stays above a few minutes. Past ~2 hours, data starts being lost.

Agent mode

If a Prometheus only exists to scrape and forward, it doesn't need local querying, rules, or long-term storage. Agent mode (--agent) turns all of that off:

  • No TSDB blocks, only a WAL that's truncated once data is sent.
  • No PromQL queries, no recording or alerting rules.
  • Much less memory and disk.

It's the right shape for edge clusters, many small Kubernetes clusters, or anywhere you want central storage and querying.

global:
scrape_interval: 15s
external_labels:
  cluster: edge-1                # which edge this came from

scrape_configs:
- job_name: node
  static_configs:
    - targets: ["node-exporter:9100"]

remote_write:
- url: http://prometheus:9090/api/v1/write
  write_relabel_configs:
    - source_labels: [__name__]
      regex: "node_(cpu_seconds_total|memory_.*|filesystem_.*|load.*)"
      action: keep

The receiving side here is the main Prometheus, started with --web.enable-remote-write-receiver. In production the receiver would usually be Mimir or similar, but a plain Prometheus works for a lab.

OpenTelemetry and OTLP

Prometheus 3 can also receive metrics over OTLP (the OpenTelemetry protocol) with --web.enable-otlp-receiver, and the OpenTelemetry Collector can scrape Prometheus targets and remote-write. That makes Prometheus a reasonable backend for OTel-instrumented code. Watch out for naming: OTel metric names contain dots and units, which Prometheus translates (http.server.duration in ms becomes http_server_duration_milliseconds, or keeps UTF-8 names if configured).

Lab

docker compose -f compose_prod.yaml --profile scaling up -d prometheus-agent
  1. On the main Prometheus, query count by (cluster) (node_load1). One series has cluster="edge-1": it came from the agent through remote write.
  2. Query count by (__name__) ({cluster="edge-1"}) to confirm only the allow-listed metrics arrived.
  3. docker exec prometheus-agent wget -qO- localhost:9090/metrics | grep remote_storage_samples_pending.
  4. Stop the main Prometheus for two minutes (docker stop prometheus), watch the agent's pending samples climb, start it again, and confirm the gap was back-filled from the agent's WAL.

On this page