Learn Labs
Foundations

Your First Scrape

The exposition format, the up metric, and the Prometheus UI

Before writing any PromQL, look at what Prometheus actually receives. It's plain text, and reading it directly removes most of the mystery.

The exposition format

With the full stack running, fetch the demo app's metrics page yourself:

curl -s localhost:8080/metrics | grep -A12 'http_request_duration_seconds'
# HELP http_requests_total HTTP requests handled, by route and status code.
# TYPE http_requests_total counter
http_requests_total{method="GET",route="/api/orders",status="200"} 18233.0
http_requests_total{method="GET",route="/api/orders",status="500"} 190.0
http_requests_total{method="GET",route="/api/search",status="200"} 9104.0

# HELP http_request_duration_seconds HTTP request latency.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{method="GET",route="/api/orders",le="0.005"} 0.0
http_request_duration_seconds_bucket{method="GET",route="/api/orders",le="0.01"} 2741.0
http_request_duration_seconds_bucket{method="GET",route="/api/orders",le="0.025"} 13012.0
http_request_duration_seconds_bucket{method="GET",route="/api/orders",le="+Inf"} 18423.0
http_request_duration_seconds_count{method="GET",route="/api/orders"} 18423.0
http_request_duration_seconds_sum{method="GET",route="/api/orders"} 387.21

# HELP http_requests_in_flight Requests currently being served.
# TYPE http_requests_in_flight gauge
http_requests_in_flight 3.0

Every non-comment line is one sample: a metric name, an optional set of labels in braces, and a float value. That's the whole format.

  • # HELP is a human description. It's shown in the UI and in Grafana's metric browser.
  • # TYPE says how to interpret the value: counter, gauge, histogram, summary, or untyped.
  • There's no timestamp. Prometheus stamps every sample with the time of the scrape.
  • One histogram (http_request_duration_seconds) produces several series: one _bucket per le boundary, plus _count and _sum. You'll see why in Metric Types.
  • The Python client also emits _created series (the Unix time each counter was created). Prometheus can use them to detect resets more precisely; you can ignore them for now.

What Prometheus adds

The demo app doesn't know it's called demo-app or that it runs on demo-app:8080. Prometheus adds that from the scrape config:

  • job: the job_name from the scrape config (demo-app).
  • instance: the host:port that was scraped (demo-app:8080).
  • Any labels from service discovery or labels: in the config. Here, env="local" and team="checkout" come from targets/demo-app.json.

So the series that ends up stored is:

http_requests_total{env="local", host="demo-app", instance="demo-app:8080", job="demo-app",
                  method="GET", route="/api/orders", status="200", team="checkout"}

The up metric

For each target, on every scrape, Prometheus writes a few series of its own. The most important is up:

up                         # 1 = last scrape succeeded, 0 = failed
scrape_duration_seconds    # how long the scrape took
scrape_samples_scraped     # samples in the response
scrape_samples_post_metric_relabeling   # samples kept after metric_relabel_configs
scrape_series_added        # new series created by this scrape

Open http://localhost:9090, type up in the query box, and press Execute. You'll get one row per target, including one with value 0: the clickhouse job, whose metrics endpoint isn't enabled yet. That's the pull model doing its job. Prometheus knows that target exists and can't reach it.

# which targets are down?
up == 0

# how many targets per job are up?
sum by (job) (up)

Tour of the UI

PageUse it for
Query (/query)Run PromQL. The Table tab shows the current value; Graph shows history.
Alerts (/alerts)Every alerting rule and whether it's inactive, pending, or firing.
Status → Target health (/targets)Every target, its labels, last scrape time and duration, and the last error. The first page to check when data is missing.
Status → Service discoveryLabels each target had before relabeling. Useful for debugging relabel rules.
Status → Rule health (/rules)Every rule, its last evaluation time and any error.
Status → ConfigurationThe config Prometheus is actually running, after reload.
Status → TSDB statusSeries counts by metric and label. Your cardinality report.

Lab: break a target

  1. Open /targets and find demo-app.
  2. Stop it: docker stop demo-app.
  3. Within 5 seconds (the job's scrape_interval), the target goes red with an error like connection refused.
  4. Run up{job="demo-app"} and switch to the Graph tab. You'll see a step down to 0.
  5. Run http_requests_total{job="demo-app"}. It returns nothing: the series went stale when the scrape failed.
  6. After two minutes, the TargetDown alert on /alerts turns from pending to firing.
  7. docker start demo-app, and watch everything recover.

Note what happened to http_requests_total after the restart: it started again from 0. Counters reset when a process restarts, which is why you almost never look at a raw counter value. You look at its rate, which handles resets for you. That's the subject of Rates & Counters.

On this page