Lesson  in  Observability 101: Metrics

Push

Collecting from producers that cannot be scraped, and what a pushed sample does and does not prove

Overview

Once a week, someone counts the beans on the shelf.

It takes two minutes with a scale, and the number matters: it decides the next order, which is the very first question this course asked about the shop. So it should be a metric. Say cafe_stocktake_beans_grams, one series per roast.

Now try to collect it the way you collected everything else.

The count isn't kept by a running process with a /metrics endpoint. It's produced by a batch job: a program that starts, does one thing, and exits. (Nothing to do with the job label from the scraping lesson; it's the everyday meaning of the word.) In the playground it's a script that runs for a second. In a real shop it's a person with a clipboard, or a scheduled command. By the time the collector comes around for its scrape, there's nothing there to scrape.

Pull depends on the target being reachable when the collector calls. The stocktake is reachable for about a second, once a week. That's the gap this lesson fills.

Objectives:

  • Explain push as a delivery direction, and name the sender and receiver of each hop in the pipeline
  • Send one text-format sample to vmagent and read it back from storage
  • Explain why a pushed value proves delivery but not liveness, and why pushed series have no up
  • Choose pull, direct push, or a local collector with remote write for a workload from its shape, not from tool preference

Push vs Pull

"Push" gets used for everything that isn't a scrape, and that hides a distinction you'll need in a minute.

Every hop in a metrics pipeline has three parts:

  • a sender, which has the samples
  • a receiver, which wants them
  • an initiator, which opens the connection

In pull, the receiver initiates: vmagent opens a connection to the cafe and the cafe answers. In push, the sender initiates: the stocktake opens a connection to vmagent and hands over its lines.

That's all "direction" means. It says who starts. It says nothing about what travels over the connection.

🏛️ Before pull, everything pushed

Pull may look like the natural default after the last two lessons, but for a long time it wasn't.

The monitoring systems that came before Prometheus mostly worked the other way round. Graphite received plain-text lines that applications and agents sent to it over TCP. StatsD took UDP packets fired from inside the application. collectd shipped readings from each host to a central server. In every case, the producer knew the address of the monitoring system and was responsible for delivering to it.

Prometheus chose pull instead, for operational reasons: a collector that knows every target can tell "down" from "silent" (that's up), and anyone can curl a target to see exactly what the collector sees.

The piece that made this the cloud-native default was Kubernetes. In a cluster, containers come and go by the minute, and nobody can maintain a list of addresses by hand. Prometheus asks the cluster for the list instead: service discovery, from the scraping lesson. That's why "expose /metrics and let something scrape it" is the shape almost every cloud-native application takes.

Push never went away, though. The rest of this lesson is about the cases where it's still the right shape.

Three hops, two directions

Here is the whole pipeline you've built so far, plus the one you're about to add. The arrows in the table show where samples travel:

Sample pathWho starts the connection?Pull or push?Format and method
cafe → vmagentvmagentPullPrometheus exposition format, HTTP GET
stocktake → vmagentstocktakePushPrometheus exposition format, HTTP POST
vmagent → VictoriaMetricsvmagentPushRemote write, HTTP POST
Arrows start at the side that opens the connection: vmagent pulls from the cafe and pushes to VictoriaMetrics, and the stocktake pushes to vmagent

Samples always travel toward storage; who opens the connection differs per hop

Two of the three hops push, and they have almost nothing else in common. One is a producer handing a collector two lines of text. The other is a collector streaming every sample it has to storage in a compact binary batch.

Keep the two questions apart:

  1. Who starts? Pull or push.
  2. What format? The exposition format, remote write, or one of a dozen others.

You've already seen one push: remote write, from vmagent to storage. The next unit does the other kind, a producer pushing its own samples, in a format you already read fluently.

Direct Push

vmagent has an ingestion endpoint for exactly this: a URL that accepts the Prometheus exposition format in the body of a POST.

http://localhost:8429/api/v1/import/prometheus

Post a line there, and vmagent treats it the same way it treats a line it scraped.

The stocktake script does that. Here is the shelf it counts:

cat /etc/cafe/shelf
light 1800
dark 2200

And here is the script doing its job:

cafe-stocktake
Counted the shelf:
cafe_stocktake_beans_grams{roast="light"} 1800
cafe_stocktake_beans_grams{roast="dark"} 2200

Sending to http://localhost:8429/api/v1/import/prometheus
Done.

Two sample lines, in the exposition format from the first lesson, sent with one HTTP request. Underneath, the script's push is a single curl, with the two lines as the body of a POST:

curl --data-binary 'cafe_stocktake_beans_grams{roast="light"} 1800
cafe_stocktake_beans_grams{roast="dark"} 2200' \
  http://localhost:8429/api/v1/import/prometheus

No need to run it yourself: every push adds a sample, so a second one would show up in everything you read next.

vmagent answers 204 No Content: accepted, nothing to add. Then the script exits, and the producer is gone.

Read it back

vmagent passes the lines on to storage within a few seconds. Give it a moment, then ask storage for the series:

curl -sG http://localhost:8428/api/v1/export \
  --data-urlencode 'match[]=cafe_stocktake_beans_grams' | jq
{
  "metric": {
    "__name__": "cafe_stocktake_beans_grams",
    "roast": "dark"
  },
  "values": [
    2200
  ],
  "timestamps": [
    1791293315922
  ]
}
{
  "metric": {
    "__name__": "cafe_stocktake_beans_grams",
    "roast": "light"
  },
  "values": [
    1800
  ],
  "timestamps": [
    1791293315922
  ]
}

Two series, one sample each. Compare them with a scraped series and two things stand out.

The timestamp is the moment of arrival. The line carried no timestamp, so the receiver stamped it, exactly as the collector stamps a scrape. The same rule applies in both directions: whoever turns a line into a sample supplies the time, unless the line brought its own.

There is no job and no instance. Nobody added them. vmagent labels what it scrapes with the target it scraped from; a pushed line has no target, so it gets exactly the labels the sender wrote and nothing else. If the stocktake wanted a shop="central" label, it would have to put one on the line itself.

Who owns delivery

In pull, the collector owns the schedule and the retries. If a scrape fails, vmagent tries again in ten seconds, and up records the gap.

In push, that responsibility moves to the sender. Had vmagent been unreachable when the script ran, the curl would have failed, the script would have exited with an error, and the count would exist nowhere. Nobody retries on the producer's behalf. The producer decides whether to try again, how many times, and what to do if it gives up.

That's the trade you make for not needing an endpoint: nobody has to reach the producer anymore, and in exchange it owns the retries and the decision to give up.

Scraped and Pushed

A scraped sample and a pushed sample enter vmagent through different doors.

Read the latte series from storage. Compare its labels with the beans the stocktake pushed in the last unit:

curl -sG http://localhost:8428/api/v1/export \
  --data-urlencode 'match[]=cafe_coffees_sold_total{drink="latte",instance="localhost:8080"}' \
  --data-urlencode 'start=-20s' | jq
Example export response
{
  "metric": {
    "__name__": "cafe_coffees_sold_total",
    "job": "cafe",
    "instance": "localhost:8080",
    "drink": "latte"
  },
  "values": [
    5,
    5
  ],
  "timestamps": [
    1791293306034,
    1791293316034
  ]
}

The scraped series has job="cafe" and instance="localhost:8080"; the pushed beans series has neither. Both responses have the familiar shape: a series identity, values, timestamps. The labels reflect how these samples arrived; the stored sample format has no separate field for scraped versus pushed.

The life of a sample

Inside vmagent, both go through the same stages. In order:

  1. Parse. The text line becomes a metric name, a label set, and a value. A scrape parses a whole response; a push parses the POST body.
  2. Stamp the time. If the line had no timestamp, it gets the current one: scrape time for a scrape, arrival time for a push.
  3. Add the collector's labels. Scraped samples get the target's job and instance. Pushed samples get nothing here; there is no target.
  4. Apply policy. Rules that rewrite labels, drop samples, or cap how many series a target may produce. This lab has none, so every sample passes unchanged.
  5. Queue and send. The sample joins a block bound for the remote-write URL.
Scraped and pushed samples enter vmagent and pass through parse, stamp, label, policy, and send on their way to VictoriaMetrics

Two doors in, one way out. Only scraped samples get job and instance

From step 4 on, a scraped sample and a pushed sample are handled exactly the same way. That's the point of having one collection layer: producers can arrive by whatever path suits them, and storage sees one stream.

The pipeline reliability module will add rules at step 4 to rewrite labels, drop unwanted samples, and limit cardinality.

As with scraping, vmagent doesn't enforce the declared metric type.

Stale Values

A delivery arrives: two kilos of light roast. Open the shelf file:

sudoedit /etc/cafe/shelf

Change the light roast to 3800:

/etc/cafe/shelf
light 3800
dark 2200

Don't run the stocktake yet. Predict what storage will show after twenty seconds: the new count, another sample of the old count, or the original sample unchanged?

Wait twenty seconds, two scrape intervals, then read the series again:

curl -sG http://localhost:8428/api/v1/export \
  --data-urlencode 'match[]=cafe_stocktake_beans_grams{roast="light"}' | jq
Example export response before rerunning the stocktake
{
  "metric": {
    "__name__": "cafe_stocktake_beans_grams",
    "roast": "light"
  },
  "values": [
    1800
  ],
  "timestamps": [
    1791293315922
  ]
}

Still 1800. Same sample, same timestamp.

The shelf changed; nothing told storage. Unlike a scrape, waiting for another interval doesn't trigger a new observation here.

Nothing says the producer is alive

That's the smaller problem. The bigger one is what you can't see.

Suppose the stocktake never sends another sample. What evidence would distinguish a failed job from one that simply hasn't run yet?

When you stopped the Riverside cafe, up dropped to 0 within ten seconds, the targets API said connection refused, and its series stopped. The collector knew what it expected to hear from, so it could report what went quiet.

The stocktake has no target. No up, no scrape_duration_seconds, no entry in the targets API, nothing. If the weekly cron entry breaks, or the script starts failing, the last value sits in storage looking perfectly healthy. Nobody is expecting anything, so nobody notices the silence.

A pushed sample proves that a push happened. It says nothing about whether another one ever will.

Freshness is the producer's job

The only clue you have is the timestamp. 1791293315922 is a moment; if it's a week and a day old, something is wrong. "How old is the newest sample?" is a question you'll learn to ask storage in the next module, and to alert on later in the course.

Producers that push and care about being missed help in one of two ways:

  • Push on a schedule and check the schedule. A stocktake every Monday means a sample every Monday; a missing Monday is the alarm.
  • Push a heartbeat. A separate series that says "I ran at this time," even when the real measurement hasn't changed.

Either way, the evidence has to be designed in. Pull gives you liveness for free; push makes you build it.

Rerun

Now run the stocktake again:

cafe-stocktake
Counted the shelf:
cafe_stocktake_beans_grams{roast="light"} 3800
cafe_stocktake_beans_grams{roast="dark"} 2200

Sending to http://localhost:8429/api/v1/import/prometheus
Done.
curl -sG http://localhost:8428/api/v1/export \
  --data-urlencode 'match[]=cafe_stocktake_beans_grams{roast="light"}' | jq
Example export response after rerunning the stocktake
{
  "metric": {
    "__name__": "cafe_stocktake_beans_grams",
    "roast": "light"
  },
  "values": [
    1800,
    3800
  ],
  "timestamps": [
    1791293315922,
    1791293342096
  ]
}

Two samples now: 1800 at the original timestamp and 3800 at a new one. The delivery is on the record.

The first stocktake pushes a light-roast sample of 1800 grams. A delivery raises the shelf to 3800 grams, but twenty seconds of waiting creates no sample: storage still holds 1800 at its original timestamp. Rerunning the stocktake pushes 3800 with a new timestamp. Only the two push events create samples.

The shelf changes on delivery. The stored series gains a sample only when the stocktake pushes again

Choosing a Path

Three hops, three sets of trade-offs. Side by side:

Pull (scrape)Direct pushRemote write
Examplevmagent → cafestocktake → vmagentvmagent → VictoriaMetrics
InitiatorCollectorProducerCollector
Who must reach whomCollector reaches the producerProducer reaches the collectorCollector reaches storage
Producer lifetimeLong-runningAny, including secondsLong-running
Liveness evidenceup, target status, for freeNone unless the producer builds itCollector-side queue and error metrics
Who retriesCollector, next intervalProducerCollector, from its queue

The choice is rarely about preference. It falls out of four questions about the workload:

  1. Can the collector reach it? If not, something on the producer's side has to push: the producer itself, or a collector running next to it.
  2. Is it there long enough to be scraped? A batch job that lives for seconds has to push.
  3. Do you need to know when it goes quiet? Pull answers this for free. Push makes you design for it.
  4. Who should own the schedule and the retries? Pull keeps both in one place, the collector's config. Push spreads them across every producer.

Three workloads

Apply the questions:

WorkloadReachable?Long-lived?Path
The cafe, or any long-running API serviceYesYesPull. Expose /metrics, add it as a target, get up for free.
The stocktake, or a nightly report jobNot when it mattersSecondsDirect push. Send the result on exit; design a freshness check.
Services in a branch office the central collector can't dial intoNoYesPush, from a local collector. Run vmagent there: it scrapes locally (pull, with up) and forwards by remote write (push, across the boundary).

The third row is the shape to remember. Reachability rarely runs the same way everywhere, so the usual answer isn't pull or push. It's pull where the collector can reach, and push across the boundaries where it can't.

🏛️ Is push coming back?

The history box at the start of this lesson ended with pull winning. Two honest observations about where things stand now.

Between tiers, push already won. Remote write is a push, and it's how Prometheus-compatible collectors reach storage. The moment your setup has more than one box, the collector-to-storage hop is a push, and nobody argues about it.

At the edge, it's a choice again. OpenTelemetry, the instrumentation standard most new code uses, sends metrics with OTLP (the OpenTelemetry Protocol), which is push by design: the SDK, the OpenTelemetry library inside the application, exports to a collector on a schedule. Serverless functions and batch jobs never fit pull. Neither does anything behind a network boundary the collector can't cross.

VictoriaMetrics' answer is to accept both. vmagent and VictoriaMetrics scrape /metrics, and they also receive pushed lines in the exposition format, remote write, OTLP, and the older push formats from Influx, Graphite, OpenTSDB, and DataDog. The choice of direction stops being a choice of vendor.

Prometheus' own tool for batch jobs like the stocktake is the Pushgateway, a small service that holds pushed samples so Prometheus can scrape them. It works, and it comes with its own set of staleness problems. vmagent accepting the push directly is the simpler shape, which is why this lab doesn't use one.

From Shop to Service

The stocktake has plenty of relatives in a software system.

Coffee shopSoftware system
The short-lived producerThe weekly stocktakeA nightly report job, a database backup, a CI pipeline, a serverless function
What it measuresBeans on the shelfRows exported, backup size, build duration, records processed
When it can be reachedFor a second, once a weekFor seconds or minutes, on a schedule or on demand
The delivery pathcafe-stocktake posts two lines to vmagentThe batch job posts its result to a collector on exit
The freshness questionDid Monday's count happen?Did last night's backup run?

The last row is where push bites in production. A backup job that stopped running looks, in storage, exactly like a backup job that's fine: the last sample is there, the number is plausible. "Last successful run was three days ago" is the alert that catches it, and it only exists if the job also pushes a heartbeat: the time it last succeeded.

Two more relatives, at the edges of the table:

  • Applications using OpenTelemetry SDKs (OpenTelemetry's instrumentation libraries) push OTLP, the OpenTelemetry Protocol, to a collector on an interval. They're long-lived, so they could be scraped, and their instrumentation library chose push anyway. The collector they push to is typically scraped or remote-writes onward, so the rest of the pipeline looks the same.
  • A collector in a restricted network is the branch-office case: pull locally, remote write outward. Every managed Kubernetes cluster shipping metrics to a central backend is this shape.

Whatever the workload, the table from the previous unit still decides the path.

Summary

In this lesson, you collected from a producer that isn't there to be scraped, and found out what that costs.

Key takeaways:

  • Push means the sender initiates. It says who starts, not what travels: the stocktake pushes two lines of the same exposition format vmagent scrapes.
  • vmagent's /api/v1/import/prometheus endpoint accepts pushed text. The receiver stamps the time, and the sample carries exactly the labels the sender wrote: no job, no instance.
  • The producer owns delivery. If the push fails, nobody retries for it.
  • A stored value is not a live producer. Pushed series have no up. Freshness has to be designed in: a schedule to check, or a heartbeat.
  • Once the collector has added its labels, scraped and pushed samples go through the same stages. Storage can't tell which door a sample came through, except by the labels it carries.
  • Choose the path from the workload: reachability, lifetime, liveness evidence, and who should own retries. The usual answer is pull where the collector can reach, push across the boundaries where it can't.

Here is the whole module, in one table:

ComponentOwns
Central and Riverside cafesMeasure; serve the exposition format at /metrics
cafe-stocktakeMeasure once; push the exposition format to vmagent; exit
vmagentKnow the targets; scrape and accept pushes; stamp time; add job and instance; queue; forward by remote write
VictoriaMetricsPersist; retain; read back (and, in a small setup, scrape on its own)

Every sample in storage is now a name, a label set, a value, and a time, sitting in an index that can find it fast. What you can't do yet is ask a question of it: how many lattes per minute, which cafe is warmer, what fraction of scrapes failed.

That's the next module.

References

💡 To learn more about the concepts covered in this lesson, check out the resources below.

Previous lesson
vmagent