乐闻世界logo
搜索文章和话题

What are the four metric types in Prometheus and how to choose between them?

2月21日 15:37

Four metric types in Prometheus:

  1. Counter:

    • Cumulative value that only increases
    • Used for recording request counts, error counts
    • Example: http_requests_total
    • Common functions: rate() for calculating growth rate
  2. Gauge:

    • Instantaneous value that can increase or decrease
    • Used for recording temperature, memory usage
    • Example: memory_usage_bytes
    • Common functions: avg(), max(), min()
  3. Histogram:

    • Samples observations and groups them into buckets
    • Provides _count, _sum, _bucket metrics
    • Used for recording request latency, response size
    • Example: http_request_duration_seconds
    • Can calculate quantiles
  4. Summary:

    • Similar to Histogram but calculates quantiles on the client side
    • Provides _count, _sum, and quantile metrics
    • Suitable for scenarios with smaller data volumes
    • Example: rpc_duration_seconds

Selection Guidelines:

  • Use Histogram for aggregated statistics
  • Use Summary for precise quantiles
  • Use Counter for cumulative values
  • Use Gauge for instantaneous values
标签:Prometheus