What Is a Metric? Time Series Explained Simply
At 2 a.m. your phone buzzes: customers say checkout feels slow. You open a dashboard and see a line that has been climbing since 1:40, from 20 orders waiting in a queue to 2,000. Nobody had to read a single log line to spot the problem or when it started. That line is drawn from a metric, so before you learn metric types and their traps, it helps to answer a plain question: what is a metric, and what is it made of?
A metric is a named number, recorded over time
A metric is a numeric measurement that a program records about itself, repeatedly, so you can see how it changes. Typical examples are requests served, memory in use and orders waiting in a queue. In the lesson on the four signals, metrics were the pulse and temperature: quick numbers that tell you something is wrong and how badly.
What gets stored is a time series: a list of values, each tagged with the moment it was taken. Two things identify a time series. The metric name says what is measured, for example http_requests_total. Labels are optional key-value pairs that pick out a slice of it, for example method="GET". Every distinct combination of name and label values is its own separate series.
Each entry in a series is called a sample: one timestamp plus one value. In Prometheus, a widely used open-source metrics system, the timestamp has millisecond precision and the value is a 64-bit floating-point number. A series therefore reads like (10:00:00, 1027), (10:00:15, 1031), (10:00:30, 1040), and so on, for as long as you keep it.
How a number becomes a graph
The program itself does very little work. Each time a request finishes, a line of code adds one to a number held in memory. A small library inside your app, called a client library, publishes the current values on a plain web page, by convention at the path /metrics. For software you cannot change, such as the operating system or a database, a separate helper program called an exporter does the same job.
A collector such as Prometheus then scrapes that page: it fetches it over HTTP on a fixed timer, called the scrape interval, and saves every value it finds with the time of the fetch. A common choice is every 15 seconds, which is what the example configuration shipped with Prometheus uses. If you set nothing at all, the built-in default is one minute.
The scrape interval decides how many samples you get. At 15 seconds that is 4 per minute, or 5,760 per day, for each series, whether the app served ten requests or ten million. It also decides what you can see. A value that rises and falls, such as queue length, can spike and recover between two scrapes and leave no trace. A running total loses nothing, because the next scrape still includes every request.
Reading the Prometheus text format
You can read a /metrics page yourself, because Prometheus uses a plain text format. Each metric starts with two comment lines. # HELP gives a one-line description for humans. # TYPE says which kind of metric it is: counter, gauge, histogram or summary, which the next lesson explains. After those, every line is one series: the name, the labels in curly braces, a space, then the current value.
# HELP http_requests_total Total HTTP requests served.
# TYPE http_requests_total counter
http_requests_total{method="POST",status="500"} 3
http_requests_total{method="GET",status="200"} 1027
Read this as: since it started, the app has served 1,027 successful GET requests and 3 POST requests that failed with status 500. The two lines share one name but have different labels, so they are two series. Notice there is no timestamp. The format allows an optional one after the value, but it is rarely used; Prometheus stamps each sample with the time of the scrape. A metric with no labels, such as node_load1 0.42, is just a name and a value.
Why metrics are cheap, and what they cannot tell you
Metrics are cheap because the app aggregates before anything leaves it. A thousand requests a second become one number that goes up, and the collector stores one sample per series per scrape no matter how busy the app is. The Prometheus storage documentation puts the average cost at only about 1 to 2 bytes per sample after compression.
Compare that with writing a log line for every request. At 1,000 requests per second you write 86.4 million lines a day; at 200 bytes each, that is about 17 GB. The request counter, scraped every 15 seconds, stores 5,760 samples a day, roughly 6 to 12 KB. That difference is why teams keep metrics for months and can still query them in seconds.
The price is detail. A metric tells you that 3 requests failed, not which customer sent them, what they contained or why they failed. It also smooths over anything that happens between scrapes. When a graph spikes, the metric points you to the right time and the right service. The logs and traces for that window, covered in later sections of this course, tell you what actually happened.
Check yourself
Are http_requests_total{status="200"} and http_requests_total{status="500"} one time series or two?
Two. The name is the same, but a series is identified by its name plus its labels, so each label value gets its own stream of samples.
With a 30-second scrape interval, how many samples does one series collect in an hour?
120: two scrapes a minute for 60 minutes. The scrape interval sets the sample count, not the amount of traffic.
A graph shows errors rising at 14:05. Why can't the metric tell you which customer was affected?
The app only kept a running count, so per-request details such as the customer were never recorded; you look for them in the logs or traces from 14:05.