BM: Baca dalam Bahasa Melayu
World O2: Counters
Recording rules
You will learn: how to save a busy query as a new series, name it well and check the rule file.
Checked with Prometheus 3 on 1 Nov 2026
The problem
50 people open the same dashboard. Every 15 s, each one runs the same heavy query. How do you help Prometheus?
Pick one answer.
Try it
A recording rule: A saved question: Prometheus runs it on a timer and keeps the answer as a new series. saves a query’s answer as a new series. Give this rule its query.
Add an expr line under record, with the per-stall orders query.
How a computer reads it
- groupslist · 1 items
- item 1map · 2 keys
- namekedaitext
- ruleslist · 1 items
- item 1map · 1 keys
- recordstall:kedai_orders:rate5mtext
- item 1map · 1 keys
- item 1map · 2 keys
Try it
The rule has run. Ask for its saved series, like any other metric.
Show the saved rate for cendol only. Tap the chip, then add a filter.
Watch
Rule names follow level:metric:operations. Good name? Swipe right for good.
Swipe right for good, left for needs work. Or use the buttons.
stall:kedai_orders:rate5mCheck
Check rule files before you load them. Real error first: tap the line that says what is wrong.
Tap the line that names the problem.
0 of 1 found
Hint
It names the line, the rule, then the parse error.Predict
promtool says SUCCESS: 1 rules found. When does the new series appear?
Pick one answer.
You did it!
You can now save a busy query as a recording rule and check it.
Go deeper (optional)
Where the story breaks: a clerk writes a counter down once. Prometheus copies every number every 15 s, changed or not. It keeps them 15 days by default, then throws them away. And a real counter never resets; an app’s does.
Real rep: save rules.yml, then add the lines below to your other two files.
# rules.yml
groups:
- name: kedai
rules:
- record: instance:node_cpu_busy:ratio_rate1m
expr: 1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[1m]))# prometheus.yml: add at the top level, after global
rule_files:
- rules.yml# compose.yaml: add under the prometheus volumes
- ./rules.yml:/etc/prometheus/rules.yml:roReal mission
docker compose up -ddocker compose exec prometheus promtool check rules /etc/prometheus/rules.ymldocker compose down
0 of 5 steps done · Your ticks are saved.
Bahasa Melayu
50 orang buka dashboard yang sama. Setiap 15 s, setiap seorang jalankan query berat yang sama. Macam mana nak bantu Prometheus?
Recording rule simpan jawapan query sebagai siri baru. Beri rule ini query-nya.
Rule itu dah berjalan. Minta siri yang disimpan, sama macam metrik lain.
Nama rule ikut level:metric:operations. Nama yang baik? Leret ke kanan untuk yang baik.
Semak fail rule sebelum memuatkannya. Ralat sebenar dulu: tekan baris yang kata apa yang salah.
promtool kata SUCCESS: 1 rules found. Bila siri baru itu muncul?
Kini anda boleh simpan query berat sebagai recording rule dan menyemaknya.
You finished this before. Practice is always welcome!
Official docs: Prometheus: recording rules · Prometheus: rule naming · promtool
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?