World map

 

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.

Metrics in this data (tap to add):

Time 0 is when the data starts. The query looks back from the eval time.

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.

Metrics in this data (tap to add):

Time 0 is when the data starts. The query looks back from the eval time.

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.

1 / 5sum(rate(kedai_orders_total[5m]))
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:

bash
docker compose exec prometheus promtool query instant http://localhost:9090 'up'
up{instance="localhost:9090", job="prometheus"} => 1 @[1793538329.647]
up{instance="node-exporter:9100", job="node"} => 1 @[1793538329.647]
up{instance="http://prometheus:9090/-/ready", job="blackbox"} => 1 @[1793538329.647]
promtool query instant prints up for three targets, each with 1 and a timestamp.

Real mission

  1. docker compose up -d
  2. docker compose exec prometheus promtool query instant http://localhost:9090 'sum by (mode) (rate(node_cpu_seconds_total[1m]))'
  3. docker compose down

0 of 3 steps done · Your ticks are saved.