In simple words
- Metric: a named number measured over time, such as http_requests_total.
- Label: a key=value tag on a metric, such as status="500", so you can slice the data.
- Counter / gauge: a counter only goes up (total requests). A gauge goes up and down (memory in use).
- Histogram: counts values in buckets, so you can work out percentiles like p99 latency.
- Cardinality: how many different label combinations exist. Too many makes monitoring slow and expensive.
Big picture
A metric is a number with a name that you measure again and again. Prometheus stores each reading with a timestamp, so you can draw graphs and spot changes.
Think of a thermometer reading written down every 15 seconds. The list of readings is a time series.
Anatomy of a metric
http_requests_total{method="GET", code="200"} 10482| Part | Meaning |
|---|---|
http_requests_total | the metric name |
{method="GET", code="200"} | labels: extra details that split the metric into separate series |
10482 | the value right now |
Every unique set of labels is its own time series. code="200" and code="500" are two different series.
The four metric types
| Type | Behaviour | Analogy | Example |
|---|---|---|---|
| Counter | Only goes up (resets on restart) | Car odometer | http_requests_total |
| Gauge | Goes up and down | Fuel gauge | memory_used_bytes, queue_length |
| Histogram | Counts values into buckets | A tally of "how many were under 100 ms, 300 ms, 1 s" | request_duration_seconds |
| Summary | Like a histogram, but works out percentiles inside the app | A pre-made report | rarely needed |
Rule of thumb: you almost never use a counter's raw value. You use its rate (how fast it grows), which you learn in the PromQL lesson.
Naming rules
- Use lowercase words with underscores:
http_requests_total. - Put the unit in the name:
_seconds,_bytes. - Counters end in
_total. - Do not put values in the name. Use a label instead.
Labels: powerful, but dangerous
Labels let you slice data: "errors by route", "latency by region".
But each new label value creates a new series, which costs memory.
| Label | Safe? | Why |
|---|---|---|
method="GET" | yes | a handful of values |
route="/orders" | yes | tens of values |
user_id="48213" | no | millions of values |
request_id | no | a new value every request |
Too many series is called high cardinality, and it is the most common way to break a Prometheus server.
curl -s localhost:9090/api/v1/status/tsdb | head -c 200{"status":"success","data":{"headStats":{"numSeries":84213,"numLabelPairs":1530,"chunkCount":84213}}}numSeries shows how many series you are storing.
A histogram in detail
A histogram is really three kinds of series. Here is one request-duration histogram on a metrics page:
http_request_duration_seconds_bucket{le="0.1"} 8200http_request_duration_seconds_bucket{le="0.3"} 9750http_request_duration_seconds_bucket{le="1"} 9990http_request_duration_seconds_bucket{le="+Inf"} 10000http_request_duration_seconds_sum 1843.2http_request_duration_seconds_count 10000| Series | Meaning |
|---|---|
_bucket{le="0.3"} | how many requests took less than or equal to 0.3 seconds (le means "less or equal") |
_sum | the total time of all requests added together |
_count | how many requests there were |
So 9,750 of 10,000 requests (97.5%) finished within 0.3 s. The buckets are cumulative: each one includes the ones before it.
Average duration is _sum / _count = 0.18 s. But the average hides the slow ones, which is why percentiles from buckets are better.
Choose buckets near the numbers you care about. If your goal is "under 300 ms", make sure there is a bucket at 0.3.
Reading a metrics page
# HELP node_memory_MemAvailable_bytes Memory available# TYPE node_memory_MemAvailable_bytes gaugenode_memory_MemAvailable_bytes 3.4e+09# HELPexplains the metric.# TYPEsays counter, gauge or histogram.- Numbers like
3.4e+09mean 3.4 billion.
A quick look at the same metric types in other tools
| Idea | Prometheus word | Other tools may say |
|---|---|---|
| Number that only grows | counter | cumulative sum, count |
| Number that moves | gauge | gauge, last value |
| Spread of values | histogram | distribution |
Common mistakes
- Putting user ids, emails or URLs with ids in labels.
- Forgetting units in names.
- Using a gauge for something that only grows.
- Graphing a counter directly instead of its rate.
Summary
- A metric is a named number over time, split by labels.
- Counter goes up, gauge goes up and down, histogram counts into buckets.
- Keep label values few. High cardinality is the big danger.
CHECK YOUR UNDERSTANDING
3 quick questions
1. Which metric type only goes up (until a restart)?
2. Which label is a bad idea?
3. What should a counter name end with by convention?
You've finished the free preview of Monitoring with Prometheus, Grafana & Datadog
Upgrade to Pro to unlock the remaining 16 lessons, every practice lab and a certificate when you finish.
See plans