我正在尝试使用 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
你能解释一下我做错了什么吗?
最佳答案
我尝试了现有的 Celery 导出器 (OvalMoney/celery-exporter),发现一些指标缺失或无效。
我在这里编写了一个用于监视任务状态的导出器 - https://github.com/danihodovic/celery-exporter .
关于python - 如何使用 Prometheus 监控 Celery 任务完成情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59931566/