BM: Baca dalam Bahasa Melayu
World O2: Counters
Add them up: sum by
You will learn: how to add many series into a few, keep the labels you want, and why rate comes first.
Checked with Prometheus 3 on 1 Nov 2026
The problem
rate() gives five lines: each stall at each outlet. The boss wants one line per stall. What now?
Pick one answer.
Try it
aggregation: Adding many series into fewer: sum, avg, max, count, with by (…) to keep some labels. adds series together. Start with one total for the whole shop.
Wrap it all in sum( ), then Run.
Predict
Now sum by (stall) (…). It keeps only the stall label. How many lines come back?
Pick one answer.
Try it
One line per stall, please.
Add by (stall) right after sum, then Run.
Try it
Build “errors per second, per status code” step by step. Put the steps in order.
First step at the top. Put these in order. Use the arrows, or drag.
- Wrap it in rate( )
- Pick the counter: http_requests_total
- Add a window: [5m]
- Add up with sum by (code)
Check
Good query? Swipe right for good.
Swipe right for good, left for needs work. Or use the buttons.
sum(rate(kedai_orders_total[5m]))You did it!
You can now add series up with sum by and keep the labels you need.
Go deeper (optional)
Other aggregations work the same way: avg, max, min, count, and topk(3, …) for the top three. promtool can run a query from the terminal too. This output is real:
Real mission
docker compose up -ddocker compose exec prometheus promtool query instant http://localhost:9090 'sum by (mode) (rate(node_cpu_seconds_total[1m]))'docker compose down
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
rate() beri lima baris: setiap gerai di setiap cawangan. Bos mahu satu baris untuk setiap gerai. Sekarang macam mana?
sum jumlahkan siri. Mula dengan satu jumlah untuk seluruh kedai.
Sekarang sum by (stall) (…). Ia simpan label stall sahaja. Berapa baris keluar?
Satu baris untuk setiap gerai, ya.
Bina “ralat sesaat, ikut kod status” langkah demi langkah. Susun langkahnya.
Query yang baik? Leret ke kanan untuk yang baik.
Kini anda boleh jumlahkan siri dengan sum by dan kekalkan label yang perlu.
You finished this before. Practice is always welcome!
Official docs: PromQL: aggregation operators · promtool
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?