如果从ipython控制台或celery任务调用增量,则Prometheus无法捕获计数器的数据。计数器适用于API请求,但API请求之外的计数器不像我从Ipython控制台尝试时那样工作,从celery任务到递增计数器。
普罗米修斯也没有抛出任何异常。
# Using Sanic python framework (async) and python 3.6.
Here are the library Details:
sanic==0.7.0
ipython
prometheus-client==0.5.0
python 3.6.5下面是我在Sanic Python应用程序中用来配置Prometheus的配置:
class MetricsHandler(HTTPMethodView):
"""prometheus metrics exporter"""
async def get(self, request, *args, **kwargs):
registry = None
if 'prometheus_multiproc_dir' in os.environ:
registry = core.REGISTRY
else:
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
return raw(data, content_type=CONTENT_TYPE_LATEST)
# ipython console example:
In [1]: Prom_Count = Counter('Prom_Counter', 'prom counter', ['func', 'count'])
In [2]: Prom_Count.labels("test", "count").inc()
prometheus_multiproc_dir enviroment varibale is also set.之前我们使用的是sanic-prometheus库:
prometheus-client==0.2.0
sanic-prometheus==0.1.4
wrapt==1.10.11提前谢谢。
发布于 2018-12-21 22:54:14
考虑这样做:
def get_registry():
if 'prometheus_multiproc_dir' in os.environ:
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
else:
registry = REGISTRY
return registry然后将注册表传递给Counter构造函数:
Prom_Count = Counter('Prom_Counter', 'prom counter', ['func', 'count'], registry=get_registry())有一次我遇到过这样的问题,它对我很有效。
https://stackoverflow.com/questions/53886739
复制相似问题