Full answer
RED (for each service or endpoint)
- Rate: rate(http_requests_total[5m]).
- Errors: the share of 5xx (and failed business operations) in the total.
- Duration: a histogram of latency, read as p50, p95 and p99.
USE (for each resource)
- Utilization: the percentage of time the resource is busy (CPU use, connection pool in use).
- Saturation: extra work waiting (run queue, pending pool requests, event loop delay).
- Errors: error counts of the resource (disk errors, dropped packets, connection errors).
Metric types
- Counter: monotonic total. Rates are computed from differences, and resets are handled by the query layer.
- Gauge: current value (in-flight requests, memory).
- Histogram: bucket counters (le="0.1") plus sum and count. Percentiles are estimated by interpolating inside the bucket that contains the rank. Buckets must fit your latency range. Summaries compute percentiles in the client but cannot be aggregated across instances.
Cautions: keep labels low cardinality (route template, method, status class). Do not average percentiles of different instances. Use histograms with the same buckets everywhere.
// A tiny histogram with Prometheus style cumulative buckets.
const buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 2.5];
const hist = { counts: new Array(buckets.length + 1).fill(0), sum: 0, count: 0 };
const observe = (seconds) => { hist.sum += seconds; hist.count++; hist.counts[buckets.findIndex((b) => seconds <= b) === -1 ? buckets.length : buckets.findIndex((b) => seconds <= b)]++; };
// Deterministic fake traffic: mostly fast, a slow tail, some errors.
let seed = 42; const rand = () => (seed = (seed * 1664525 + 1013904223) % 4294967296) / 4294967296;
const samples = Array.from({ length: 2000 }, () => ({ seconds: rand() < 0.95 ? 0.01 + rand() * 0.04 : 0.4 + rand() * 1.2, status: rand() < 0.02 ? 500 : 200 }));
let requests = 0, errors = 0;
for (const s of samples) { requests++; if (s.status >= 500) errors++; observe(s.seconds); }
// Percentile estimate from the buckets (linear interpolation inside the bucket).
function quantile(q) {
const rank = q * hist.count; let cumulative = 0;
for (let i = 0; i < buckets.length; i++) {
const next = cumulative + hist.counts[i];
if (next >= rank) { const lower = i === 0 ? 0 : buckets[i - 1]; return lower + ((rank - cumulative) / hist.counts[i]) * (buckets[i] - lower); }
cumulative = next;
}
return Infinity;
}
const exact = (q) => samples.map((s) => s.seconds).sort((a, b) => a - b)[Math.floor(q * (samples.length - 1))];
console.log('RED rate :', requests, 'requests in the window');
console.log('RED errors :', (errors / requests * 100).toFixed(1) + '% of requests failed');
console.log('RED duration : mean', (hist.sum / hist.count * 1000).toFixed(0), 'ms | p50', (quantile(0.5) * 1000).toFixed(0), 'ms | p95', (quantile(0.95) * 1000).toFixed(0), 'ms | p99', (quantile(0.99) * 1000).toFixed(0), 'ms');
console.log('exact p99 :', (exact(0.99) * 1000).toFixed(0), 'ms (the bucket estimate is close, and the mean hides the tail)');
console.log('\n# exposition format (cumulative buckets)');
let cumulative = 0;
buckets.forEach((b, i) => { cumulative += hist.counts[i]; console.log(`http_request_duration_seconds_bucket{le="${b}"} ${cumulative}`); });
console.log(`http_request_duration_seconds_bucket{le="+Inf"} ${hist.count}`);
console.log(`http_requests_total{status_class="5xx"} ${errors}`);
// USE for one resource: a connection pool.
const pool = { size: 10, inUse: 9, waiting: 4, errors: 0 };
console.log('\nUSE pool : utilization', pool.inUse / pool.size * 100 + '%', '| saturation', pool.waiting, 'waiting | errors', pool.errors);Synthetic traffic from a fixed random seed, so the numbers repeat. The percentile estimate uses the same interpolation idea as Prometheus histogram_quantile. Save it as app.js and run it with node app.js. Output (Node.js v24.22.1, run once): RED rate : 2000 requests in the window RED errors : 1.8% of requests failed RED duration : mean 84 ms | p50 32 ms | p95 529 ms | p99 1386 ms exact p99 : 1337 ms (the bucket estimate is close, and the mean hides the tail) # exposition format (cumulative buckets) http_request_duration_seconds_bucket{le="0.005"} 0 http_request_duration_seconds_bucket{le="0.01"} 0 http_request_duration_seconds_bucket{le="0.025"} 660 http_request_duration_seconds_bucket{le="0.05"} 1888 http_request_duration_seconds_bucket{le="0.1"} 1888 http_request_duration_seconds_bucket{le="0.25"} 1888 http_request_duration_seconds_bucket{le="0.5"} 1897 http_request_duration_seconds_bucket{le="0.75"} 1923 http_request_duration_seconds_bucket{le="1"} 1941 http_request_duration_seconds_bucket{le="1.25"} 1968 http_request_duration_seconds_bucket{le="1.5"} 1990 http_request_duration_seconds_bucket{le="2"} 2000 http_request_duration_seconds_bucket{le="2.5"} 2000 http_request_duration_seconds_bucket{le="+Inf"} 2000 http_requests_total{status_class="5xx"} 36 USE pool : utilization 90% | saturation 4 waiting | errors 0
Key points
- RED: rate, errors, duration for services.
- USE: utilization, saturation, errors for resources.
- Counters go up, gauges go both ways, histograms bucket observations.
- Estimate percentiles from histogram buckets.
- Averages hide slow requests.
Common mistakes
- Alerting on average latency.
- Averaging percentiles from several instances.
- Labels such as user id or full URL path on metrics.
- Histogram buckets that do not cover the real latency range.
- Monitoring only the service and not its resources.
Follow-ups
- How does histogram_quantile work?
- What is the difference between a histogram and a summary?
- Which saturation signals matter for a Node.js service?
Tips
- Define RED and USE in one line each.
- Name the three metric types.
- Say why percentiles beat averages.