繁体   English   中英

Prometheus Metrics 中究竟做了什么(例如直方图)

[英]What exactly is being done in Prometheus Metrics (Histogram for example)

我很难理解 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 值。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM