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.0Every 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.
# HELPis a human description. It's shown in the UI and in Grafana's metric browser.# TYPEsays how to interpret the value:counter,gauge,histogram,summary, oruntyped.- There's no timestamp. Prometheus stamps every sample with the time of the scrape.
- One histogram (
http_request_duration_seconds) produces several series: one_bucketperleboundary, plus_countand_sum. You'll see why in Metric Types. - The Python client also emits
_createdseries (the Unix time each counter was created). Prometheus can use them to detect resets more precisely; you can ignore them for now.
Prometheus also understands OpenMetrics, a standardised version of
this format that adds things like exemplars and # EOF, and a binary
protobuf format needed for native histograms. It negotiates which one
to use through the HTTP Accept header. For learning, the text format
is what you'll read.
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: thejob_namefrom the scrape config (demo-app).instance: thehost:portthat was scraped (demo-app:8080).- Any labels from service discovery or
labels:in the config. Here,env="local"andteam="checkout"come fromtargets/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 scrapeOpen 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
| Page | Use 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 discovery | Labels each target had before relabeling. Useful for debugging relabel rules. |
Status → Rule health (/rules) | Every rule, its last evaluation time and any error. |
| Status → Configuration | The config Prometheus is actually running, after reload. |
| Status → TSDB status | Series counts by metric and label. Your cardinality report. |
Lab: break a target
- Open
/targetsand finddemo-app. - Stop it:
docker stop demo-app. - Within 5 seconds (the job's
scrape_interval), the target goes red with an error likeconnection refused. - Run
up{job="demo-app"}and switch to the Graph tab. You'll see a step down to0. - Run
http_requests_total{job="demo-app"}. It returns nothing: the series went stale when the scrape failed. - After two minutes, the
TargetDownalert on/alertsturns from pending to firing. 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.
up == 0 tells you a scrape failed, not that the service is down. The
service might be fine and the network between Prometheus and it broken,
or the exporter crashed while the database is healthy. Pair up with
a black-box probe or a symptom metric before paging anyone about it.