Prometheus Metric类型

翻译 原文链接

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

Counter类型

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

Client library usage documentation for counters:

Gauge类型

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

Client library usage documentation for gauges:

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 <basename> exposes multiple time series during a scrape:

  • cumulative counters for the observation buckets, exposed as <basename>_bucket{le="<upper inclusive bound>"}
  • the total sum of all observed values, exposed as <basename>_sum
  • the count of events that have been observed, exposed as <basename>_count (identical to <basename>_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:

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 <basename> exposes multiple time series during a scrape:

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

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

Client library usage documentation for summaries:

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容