Course contentsShow
← Cloud and Infrastructure
Lesson 1949 of 2,98942. Observability - MetricsFree lesson

Metric Types: Counter

Understanding counters as monotonically increasing values, used for tracking requests, errors, or cumulative totals.

Metric Types: Counter

What You'll Learn

You'll learn what Prometheus counters are and why they're essential for tracking cumulative metrics like request counts and error rates.

Understanding Counters

A counter is a metric type that only goes up (or resets to zero). Think of it like the odometer in your car—it continuously increases as you drive more miles, never decreasing unless the car is reset. Counters represent cumulative totals over time.

In Prometheus, counters are monotonically increasing values used to track events that accumulate: HTTP requests served, errors encountered, bytes transmitted, or tasks completed. When a service restarts, the counter resets to zero and begins counting again.

When to Use Counters

Use counters for metrics where you care about:

  • Total requests handled by your API
  • Error counts across your application
  • Bytes transferred through a network interface
  • Jobs completed by a background worker

You typically don't use the raw counter value directly. Instead, you calculate the rate of change using functions like rate() or increase() to answer questions like "How many requests per second?" or "What's our error rate over the last 5 minutes?"

Counter Behavior

Counters have two key characteristics:

  1. Always increasing: Values only go up (except on reset)
  2. Reset tolerance: Prometheus can detect and handle counter resets automatically when calculating rates

For example, a counter named http_requests_total might show values like: 100, 250, 450, 3 (reset), 50, 120...

Key Takeaway: Counters are monotonically increasing metrics perfect for tracking cumulative totals like requests and errors; use rate functions to extract meaningful insights about change over time.