首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我得到了ValueError:在CollectorRegistry错误中复制的时间序列,当我试图导入存储孩子的Dict时

我得到了ValueError:在CollectorRegistry错误中复制的时间序列,当我试图导入存储孩子的Dict时
EN

Stack Overflow用户
提问于 2022-02-22 14:51:17
回答 1查看 699关注 0票数 1

我创建了一个Python项目,用于使用prometheus进行监视。但是,当我试图将字典放到CollectorRegistry服务器运行的文件中时,就会在CollectorRegistry: error中得到一个重复的timeseries。我不知道它是从哪里来的。

我是这样进口字典的:

代码语言:javascript
复制
import actions.actions as a

我需要重新加载导入,以便在两个文件之间同步数据:

代码语言:javascript
复制
from imp import reload

远程the服务器文件如下所示:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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')
EN

回答 1

Stack Overflow用户

发布于 2022-06-04 07:40:27

按照这个链接,https://github.com/prometheus/client_python/issues/626您尝试过创建一个单独的注册表而不是默认的注册表吗?

代码语言:javascript
复制
 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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71223419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档