我创建了一个Python项目,用于使用prometheus进行监视。但是,当我试图将字典放到CollectorRegistry服务器运行的文件中时,就会在CollectorRegistry: error中得到一个重复的timeseries。我不知道它是从哪里来的。
我是这样进口字典的:
import actions.actions as a我需要重新加载导入,以便在两个文件之间同步数据:
from imp import reload远程the服务器文件如下所示:
import sys
from flask import Flask, Response
import prometheus_client
from prometheus_client import Summary, Counter, Histogram, Gauge
import actions.actions as a
from imp import reload
#################### Monitoring ####################
app = Flask(__name__)
@app.route("/metrics")
def requests_count():
data = a.graphs
reload(a)
res = []
for k,v in data.items():
res.append(prometheus_client.generate_latest(v))
return Response(res, mimetype="text/plain")
if __name__ == '__main__':
app.run(host='0.0.0.0', port='5000', debug=True)在另一个文件中,我像这样使用prometheus:
graphs = {}
graphs['helpful'] = Counter('python_request_helpful_total', 'the total of helpful interactions')
graphs['nothelpful'] = Counter('python_request_nothelpful_total', 'the total of not helpful interactions')
graphs['othersasked'] = Counter('python_request_othersasked_total', 'The total of fallbacks in others Asked')
graphs['fallback'] = Counter('python_request_fallback_total', 'The total number of total fallbacks')发布于 2022-06-04 07:40:27
按照这个链接,https://github.com/prometheus/client_python/issues/626您尝试过创建一个单独的注册表而不是默认的注册表吗?
registry = CollectorRegistry()
graphs = {}
graphs['helpful'] = Counter('python_request_helpful_total', 'the total of helpful interactions', registry=registry)
graphs['nothelpful'] = Counter('python_request_nothelpful_total', 'the total of not helpful interactions', registry=registry)
graphs['othersasked'] = Counter('python_request_othersasked_total', 'The total of fallbacks in others Asked', registry=registry)
graphs['fallback'] = Counter('python_request_fallback_total', 'The total number of total fallbacks', registry=registry)https://stackoverflow.com/questions/71223419
复制相似问题