Course contentsShow
← System Design
Lesson 1187 of 1,91930. Observability: MetricsFree lesson

Rate Calculations from Counters

Computing per-second rates from monotonic counters to understand throughput and velocity of change.

Rate Calculations from Counters

What you'll learn: How to transform monotonic counter values into meaningful per-second rates that reveal system throughput and activity velocity.

The Core Problem

Counter metrics only show cumulative totals—like an odometer on a car. To understand how fast something is happening right now (requests per second, bytes transferred per second), you need to calculate the rate of change between two counter readings.

How Rate Calculation Works

A counter might report:

  • At time T₀ (10:00:00): http_requests_total = 1000
  • At time T₁ (10:00:15): http_requests_total = 1450

The rate calculation is:

rate = (counter_value_T1 - counter_value_T0) / (T1 - T0)
rate = (1450 - 1000) / 15 seconds = 30 requests/second

The Analogy

Think of your car's odometer (counter) versus speedometer (rate). The odometer shows total miles driven—constantly increasing. The speedometer shows how fast you're currently going by calculating how quickly the odometer is changing.

Important Considerations

Scrape Interval Matters: Most monitoring systems (like Prometheus) scrape metrics periodically. A 15-second scrape interval means you calculate rates over 15-second windows. Shorter intervals give more granular rates but increase overhead.

Counter Resets: When a service restarts, counters reset to zero. Rate calculations must detect this and ignore the apparent "negative" change, treating the new value as a fresh starting point.

Smoothing: Single-interval rates can be noisy. Systems often calculate rates over multiple intervals (e.g., 5-minute average) for stability.

Key Takeaway:
Rate calculations convert monotonic counters into actionable throughput metrics by measuring the change in counter values over time, giving you the velocity of system activity rather than just cumulative totals.