When should production telemetry use a counter, gauge or histogram?
Answer
A counter represents a total that accumulates, such as completed requests or failures; queries usually calculate its rate over time. A gauge represents a value that can rise or fall, such as queue depth or current concurrency. A histogram groups observations such as request duration into a distribution that supports counts, thresholds and percentile estimates. Test resets, missing intervals, bucket boundaries, units and labels before trusting any dashboard or alert derived from them.
Strong answer includes
- matches each metric shape to its behaviour
- recognizes rates and process resets
- checks units, buckets and labels
Practical example
A service exposes http_requests_total as a counter, active_connections as a gauge, and http_request_duration_seconds as a histogram with buckets at 0.1s, 0.5s, 1s and 5s. After a pod restart, http_requests_total resets to zero, and a naive dashboard that plots the raw counter value shows a misleading drop instead of using rate(); a QA engineer catches this by restarting the service during a test and verifying the dashboard still shows a sensible trend rather than a false cliff.