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
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: dropPrometheus scales the shard count automatically between min_shards
and max_shards, based on how far behind it is.
Watching remote write
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_secondsAlert if lag stays above a few minutes. Past ~2 hours, data starts being lost.
Remote write roughly doubles Prometheus's network egress and adds
memory for the queues. Use write_relabel_configs to send only what
the central system needs. Shipping every Go runtime metric from every
pod to a paid managed service is a common way to get a surprising
bill.
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: keepThe 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.
Alerting moves with the data. An agent can't evaluate rules, so alerts
for edge clusters must run centrally, and a network partition between
edge and center means those alerts go quiet. Keep a Watchdog-style
heartbeat per edge cluster, and alert centrally on
absent_over_time(up{cluster="edge-1"}[10m]).
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- On the main Prometheus, query
count by (cluster) (node_load1). One series hascluster="edge-1": it came from the agent through remote write. - Query
count by (__name__) ({cluster="edge-1"})to confirm only the allow-listed metrics arrived. docker exec prometheus-agent wget -qO- localhost:9090/metrics | grep remote_storage_samples_pending.- 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.