python - 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 值。
解决方案
localhost:8000
我建议您暂时放弃 Prometheus 服务器,只需查看每次调用该observe()
方法后查询时返回的数据。这样,您将更好地理解直方图指标如何以及为什么由多个时间序列组成。
推荐阅读
- gradle - 未找到 ID 为“id”的插件(gradle 自定义插件)
- google-cloud-platform - agones和spatial OS有什么区别
- c# - C# - 我可以重复 SetSocketOption 吗?
- php - 记住 Token 在 Laravel Lumen 中不起作用
- android - 应用程序在启动后立即关闭,没有错误,在 VS 调试器中没有单步执行
- python - Matplotlib 没有安装在我使用 Python3 设置的 virtualenv 上
- python - 尝试获取 FTP 地址并使用输入传递给 python 中的下一个函数
- angularjs - 如何使用 ng-pattern 在函数中设置正则表达式模式
- python - 熊猫中具有特定总和长度的动态索引
- dart - Flutter:iOS 风格的导航/过渡