ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# **Metric types** <br /> ## **Counter** `Counter` 是一个累积指标,他代表一个单调递增的计数器,其值只能增加或在重新启动时重置为零。例如,您可以使用 counter 来表示已服务的请求数量,已完成任务数量,或错误的数量。 不要使用 counter 来表达可以减小的值。例如,不要对当前正在运行的进程数使用 counter,而是要使用 gauge。 Counters 的客户端库使用文档: * [Go](https://godoc.org/github.com/prometheus/client_golang/prometheus#Counter) * [Java](https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/Counter.java) * [Python](https://github.com/prometheus/client_python#counter) * [Ruby](https://github.com/prometheus/client_ruby#counter) ## **Gauge** `Gauge` 是一个代表可以任意上下波动的单个数值的指标。 Gauge 通常用于测量值,例如温度、当前内存使用量,还用于可能上升和下降的计数,例如并发请求数。 Gauges 的客户端库使用文档: * [Go](https://godoc.org/github.com/prometheus/client_golang/prometheus#Gauge) * [Java](https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/Gauge.java) * [Python](https://github.com/prometheus/client_python#gauge) * [Ruby](https://github.com/prometheus/client_ruby#gauge) ## **Histogram** `Histogram 直方图`对观察值(通常是请求持续时间或响应大小)进行采样,并将其计数在可配置的 buckets 中。它还提供所有观察值的总和。 基本指标名称为`<basename>`的 histogram 会在一次抓取中暴露多个时间序列。 * 观察桶(observation buckets)的累积计数器,显示为`<basename>_bucket{le="包含作用域的上限>"}` * 所有观察值的总和,显示为 `<basename>_sum` * 观察到的事件计数,显示为 `<basename>_count(与上面相同,i.e. <basename>_bucket{le="+Inf"})` 使用 [histogram_quantile()](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile) 函数可以根据直方图甚至是直方图的聚合来计算分位数,histogram 也适用于计算 [Apdex score](https://en.wikipedia.org/wiki/Apdex)。当在 buckets 上操作时,记住 histogram 也是[累积](https://en.wikipedia.org/wiki/Histogram#Cumulative_histogram)的。有关 histograms 和 summaries 的详细信息,可以参考[histograms and summaries](https://prometheus.io/docs/practices/histograms)。 Histograms 客户端库使用文档: * [Go](https://godoc.org/github.com/prometheus/client_golang/prometheus#Histogram) * [Java](https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/Histogram.java) * [Python](https://github.com/prometheus/client_python#histogram) * [Ruby](https://github.com/prometheus/client_ruby#histogram) ## **Summary** 类似于 histogram,一个 summary 会采样观察值(通常是请求持续事件和响应大小)。尽管它还提供了观测值的总数和所有观测值的总和,但它可以计算滑动时间窗口内的可配置分位数。 基本指标名称为 `<basename>` 的 summary 会在一次抓取指标期间显示多个时间序列: * 观察到的事件 streaming φ 分位数(0≤φ≤1),显示为 `<basename> {quantile =“ <φ>”}` * 所有观察值的总和,显示为 `<basename> _sum` * 已观察到的事件计数,显示为 `<basename> _count` 有关 φ 分位数的详细说明,摘要用法以及与直方图的差异,请参见 [histograms and summaries](https://prometheus.io/docs/practices/histograms)。 Summaries 客户端库使用文档: * [Go](https://godoc.org/github.com/prometheus/client_golang/prometheus#Summary) * [Java](https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/Summary.java) * [Python](https://github.com/prometheus/client_python#summary) * [Ruby](https://github.com/prometheus/client_ruby#summary)