Metric Types: Counters and Gauges
You'll learn the two fundamental metric primitives used to measure system behavior.
When monitoring cloud infrastructure, you need to track different kinds of values. Not all metrics behave the same way—some only go up, while others fluctuate. Understanding the difference between counters and gauges helps you choose the right metric type and interpret your data correctly.
Counters: Ever-Increasing Values
A counter is a metric that only increases over time (or resets to zero). Think of it like a car's odometer—it tracks cumulative distance and never goes backward. Counters measure how many times something has happened since monitoring started.
Common examples:
- Total HTTP requests received
- Number of errors encountered
- Bytes transferred over the network
- Database queries executed
Counters answer questions like "How many requests have we served?" To find the rate of change (requests per second), you calculate the difference between two counter readings over time.
Gauges: Point-in-Time Values
A gauge is a metric that represents a value at a specific moment—it can go up or down freely. Think of it like a thermometer or speedometer showing the current state. Gauges measure what the value is right now.
Common examples:
- Current CPU usage percentage
- Active database connections
- Memory consumption
- Queue depth
- Number of running containers
Gauges answer questions like "What's our current memory usage?" They're snapshots that reflect the present state of your system.
Choosing the Right Type
Use a counter when tracking cumulative events. Use a gauge when measuring current levels or capacity. Mixing them up leads to confusing dashboards and incorrect alerts.
Key Takeaway: Counters measure cumulative totals that only increase (like request counts), while gauges measure fluctuating values at a point in time (like CPU usage)—choosing the correct type is essential for accurate monitoring.