Senior
What are the main types of metrics in Prometheus?
sobes.tech AI
Answer from AI
In Prometheus, the main metric types are:
- Counter: monotonically increasing, used for counting events (e.g., number of requests).
- Gauge: can increase and decrease, reflects the current value (e.g., CPU load).
- Histogram: collects the distribution of values over intervals, useful for measuring response times.
- Summary: similar to histogram but provides quantile estimates, such as the 95th percentile of latency.
Example of creating a counter in Go using the Prometheus library:
var requestCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Total number of HTTP requests",
},
)
func handler(w http.ResponseWriter, r *http.Request) {
requestCounter.Inc()
// handle request
}