【发布时间】:2020-01-27 12:52:36
【问题描述】:
我正在尝试使用 Prometheus 来监控我相对较新的 Celery 任务,并且在增加计数器时遇到问题。如果我试图在 Celery.task 内部进行,它只是不会增加
例如
from celery import Celery
from prometheus_client import Counter
app = Celery('tasks', broker='redis://localhost')
TASKS = Counter('tasks', 'Count of tasks')
@app.task
def add(x, y):
TASKS.inc(1)
return x + y
当我访问端点以查看公开了哪些指标时,我可以看到tasks_total,但无论add 执行了多少任务,它的值都不会改变。
但是,当我尝试从常规函数中增加相同的计数器时,它可以工作。
例如
def dummy_add(x, y):
TASKS.inc()
return x + y
你能解释一下我做错了什么吗?
【问题讨论】:
标签: python celery prometheus