Prometheus Metric类型

翻译 原文链接

Prometheus客户端库提供了四种核心metric类型。这些类型目前只在客户端库(客户端可以根据不同的数据类型调用不同的API借口)和在线协议中有区分,实际在Prometheus并没有充分利用这些数据类型,而是简单的把这些类型扁平为无类型的时间序列。不过,将来我们正在努力改变这一现状。

Counter类型

Counter类型代表一类单调递增的metrics。比如:服务的请求数、已完成的任务数,错误发生的次数等。Counter类型不应该用于非单调递增的数据,比如:当前运行的goroutines数目(应该用Gauge类型)。

Client library usage documentation for counters:

  • Go
  • Java
  • Python
  • Ruby

Gauge类型

Gauge类型代表一类数据可以任意变化的metrics。Gauge类型一般用于像温度或者内存使用率这种数据(任意上下变化),当然也用于表示可以上下变化的"总数",比如:当前运行的goroutines总数。

Client library usage documentation for gauges:

  • Go
  • Java
  • Python
  • Ruby

Histogram类型

A histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.

A histogram with a base metric name of exposes multiple time series during a scrape:

  • cumulative counters for the observation buckets, exposed as _bucket{le=""}
  • the total sum of all observed values, exposed as _sum
  • the count of events that have been observed, exposed as _count (identical to _bucket{le="+Inf"} above)

Use the histogram_quantile() function to calculate quantiles from histograms or even aggregations of histograms. A histogram is also suitable to calculate an Apdex score. When operating on buckets, remember that the histogram is cumulative. See histograms and summaries for details of histogram usage and differences to summaries.

Client library usage documentation for histograms:

  • Go
  • Java
  • Python
  • Ruby

Summary类型

Similar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.

A summary with a base metric name of exposes multiple time series during a scrape:

  • streaming φ-quantiles (0 ≤ φ ≤ 1) of observed events, exposed as {quantile="<φ>"}
  • the total sum of all observed values, exposed as _sum
  • the count of events that have been observed, exposed as _count

See histograms and summaries for detailed explanations of φ-quantiles, summary usage, and differences to histograms.

Client library usage documentation for summaries:

  • Go
  • Java
  • Python
  • Ruby

你可能感兴趣的:(Prometheus Metric类型)