Counter Metrics
You'll learn what counter metrics are and why they're essential for tracking cumulative system events.
What is a Counter?
A counter is a monotonically increasing metric that only goes up (or resets to zero). Think of it like your car's odometer—it tracks the total distance traveled since manufacturing and never decreases unless reset. Counters are perfect for tracking cumulative events: total HTTP requests received, total errors encountered, or total bytes processed.
Unlike gauges that can go up or down, counters represent a running total. They answer questions like "How many times has X happened since the service started?"
How Counters Work
When you track an event with a counter, you increment it:
- A request arrives → increment
http_requests_total - An error occurs → increment
errors_total - A message is processed → increment
messages_processed_total
The counter value itself (e.g., "10,453 total requests") is less useful than its rate of change. Monitoring systems typically calculate the per-second rate: "How many requests per second in the last 5 minutes?" This rate tells you about current system activity.
Why Counters Matter
Counters are fundamental because:
- They're accurate even if your monitoring system misses a scrape
- They enable rate calculations to see throughput trends
- They can be aggregated across multiple instances (just sum them)
- They survive temporary monitoring gaps—the total keeps accumulating
When a service restarts, counters reset to zero. Monitoring systems detect this and handle it appropriately when calculating rates.
Key Takeaway: Counters are monotonically increasing metrics ideal for tracking cumulative events like requests or errors, enabling accurate rate calculations and throughput analysis across distributed systems.