Gauge Metrics
You'll learn how to measure point-in-time values that fluctuate up and down, like memory usage or active connections.
What is a Gauge?
A gauge is a metric type that represents a single numerical value that can arbitrarily go up or down over time. Unlike counters (which only increase), gauges capture the current state of something at the moment you measure it.
Think of a gauge like a thermometer or speedometer—it shows you the reading right now, and that reading can rise or fall depending on conditions.
Common Use Cases
Gauges are perfect for measuring:
- Memory usage: RAM consumption can increase or decrease as your application allocates and frees memory
- Queue depth: The number of items waiting to be processed fluctuates constantly
- Active connections: Database or HTTP connections that open and close
- Thread pool size: Active threads that grow and shrink
- Disk space: Available storage that changes with writes and deletes
- Current temperature: CPU temperature that varies with load
How Gauges Differ from Counters
While you learned that counters monotonically increase (like request_total), gauges can move in both directions:
- Counter:
requests_total: 1500 → 1501 → 1502(always up) - Gauge:
memory_used_bytes: 1024 → 2048 → 1536(up and down)
Key Characteristics
Gauges represent instantaneous snapshots. When you query a gauge, you get the value at that specific moment. This makes them ideal for monitoring resource utilization and capacity planning.
Key Takeaway: Gauges measure values that can increase or decrease over time, capturing the current state of a resource rather than cumulative totals—use them for memory, connections, queue depth, and other fluctuating measurements.