Metrics to track: RED, USE and business metrics with Prometheus

Backend Live Coding November 13, 2026 python

For services, RED: Rate, Errors, Duration (p50/p95/p99, not the average).

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# ======================================================================
# Q: Which metrics do you measure? Write an example.
#
# For services, RED: Rate, Errors, Duration (p50/p95/p99, not the average). For
# resources, USE: Utilization, Saturation, Errors. And business metrics: imports
# per hour, rejected rows, queue length, delay from event to alert.
# Watch out for cardinality: never user_id or tenant_id as a label in Prometheus
# (millions of time series). Those go to logs/traces.
# ======================================================================

from prometheus_client import Counter, Histogram

IMPORT_ROWS = Counter('import_rows_total', 'Rows processed',
                      ['source', 'result'])          # result: ok|rejected
EXTERNAL_LATENCY = Histogram('external_api_seconds', 'External API latency',
                             ['provider'])

with EXTERNAL_LATENCY.labels(provider='geoip').time():
    data = client.lookup(ip)
IMPORT_ROWS.labels(source='edr', result='ok').inc(len(good))