首页 > 解决方案 > Prometheus Metrics 中究竟做了什么(例如直方图)

问题描述

我很难理解 Prometheus 指标及其含义。

我写了这个非常简单的python文件

from prometheus_client import start_http_server, Histogram
import random
import time


SOME_MEASURE= Histogram('some_measure_seconds', 'Some measure I am trying to graph')

list=[1,2,3,4,5,6,7,8,9,10]


def register_histo(i):
    SOME_MEASURE.observe(i)
    time.sleep(5)


if __name__ == '__main__':
    # Start up the server to expose the metrics.
    start_http_server(8000)
    while True:
        for i in list:
            #print(i)
            register_histo(i)

如您所见,我有一个非常清晰的数字列表,1、2、3 等。我把它们放在直方图中(或者至少这是我所期望的)

然后我启动普罗米修斯并查询

some_measure_seconds_count

我得到

some_measure_seconds_count{instance="localhost:8000",job="example"}             9

酷,我想那是9,对吧?但后来我再次执行,我得到 20 !

这20是从哪里来的。我应该把 1,2,3....10 作为指标,而不是 20

所以总而言之,我不知道这个直方图指标是什么,我不知道如何清楚地看到我的 1,2,3....10 值。

标签: pythonprometheus

解决方案


localhost:8000我建议您暂时放弃 Prometheus 服务器,只需查看每次调用该observe()方法后查询时返回的数据。这样,您将更好地理解直方图指标如何以及为什么由多个时间序列组成。


推荐阅读