Prometheus
medium 28 minPrometheus is an open source monitoring server.
See it run
A scrape, a rate, a label explosion, an alert, and the way of a sample to disk.
Operations
One scrape
Find the targets, read their pages, write down whether they answered.
Step 1 of 5
Who is there?
Discovery lists two copies of the app.
Step 1: Who is there?
def scrape_round(): for t in discovery.targets(): try: page = http_get(t + "/metrics", timeout=10) store(parse(page), labels=t.labels) store("up", 1, labels=t.labels) except Timeout: store("up", 0, labels=t.labels)- How often
- Every 15 s
- What it costs
- 1 to 2 B a sample
A failed scrape is a measurement too: alert on it.
In the real world
The same prometheus doing real jobs. Pick one and step through it.
Two identical servers that do not know each other.
Step 1 of 3
Both work
1 message
Both scrape everything and both send the same alert. One message arrives.
Step 1: Both work
Common mistakes
The bugs interviewers watch for, with the fix beside each.
A label without a limit
criticalEach value is a new series in memory. Users, ids and full URLs never stop growing.
WrongREQUESTS.labels(user=user_id).inc()RightREQUESTS.labels(tier=user.tier).inc()log.info("request", user=user_id)Sum before rate
majorA restart of one copy is hidden in the sum and breaks the result.
Wrongrate(sum_of_requests[5m])Rightsum(rate(http_requests_total[5m]))Averaged percentiles
majorThe mean of 20 p95 values is not the p95 of all requests.
Wrongavg(latency{quantile="0.95"})Righthistogram_quantile(0.95, sum by (le) (rate(latency_bucket[5m])))Everything through the Pushgateway
majorOld series stay for ever, up says nothing about your servers, and the gateway is one more single point.
Wrong# 50 servers push every 10 sRight# 50 servers are scraped# one nightly job pushes its resultWindow as long as the interval
minorWith fewer than two samples there is no rate, so charts have holes.
Wrong# scrape every 60srate(x_total[1m])Right# scrape every 60srate(x_total[5m])
Interview tips
How to explain it
- Targets show numbers.
- Prometheus fetches and stores them.
- Rules decide, Alertmanager tells people.
Where state lives
- Newest samples: memory and the log.
- Older ones: blocks on one disk.
- Silences: Alertmanager.
Reach for it when
- You need rates, errors and durations.
- Targets come and go.
- You can run one small server.
Before production
- Two servers.
- A sample_limit on every job.
- Something outside that notices silence.