-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add celery_queue_length, celery_active_consumer_count gauge metrics for exporter #118
Add celery_queue_length, celery_active_consumer_count gauge metrics for exporter #118
Conversation
Looking good. Are there any other metrics we can get from .queue_declare() ? |
According to kombu API Refrence,
We can add |
Could you add the active consumer count? That would be awesome :) |
|
Would it be possible to get the queue length and consumer count for all queues, without having to specify them as options in the exporter cli? I've managed to get the queue length metric in a production environment by deploying this branch, however the active consumer count shows 0, despite tasks being consumed from the queue (and the queue shrinking in size).
Could you have a second look that it works? I believe the test should also show a consumer count of 1. Instead of scheduling scrapes on a internal timer, we could pull metrics on demand when the /metrics endpoint is hit. This is what the Prometheus community recommends when writing scrapers. https://prometheus.io/docs/instrumenting/writing_exporters/#scheduling
Perhaps we could scrape queue length before building the output: celery-exporter/src/http_server.py Line 33 in 1534d70
|
Q1
The reasons for doing this are as follows:
So, I think the specify from developer is more reasonable and explicit. What do you think? Q2
Sure. I have checked the source code of kombu and the documentation of rabbitmq, this metric does reflect the number of consumers. And I also check it on my host. It's really works. Could you check the broker's consumer data and consumer process state when you read the metrics? Q3
Yep. But after that, the pull request will become a non-constant complexity operation. It will affect by the length of queues which is |
I managed to run a breakpoint() in the test suite to inspect the celery app. Listing queues seems to work for Redis, but you can try it for RabbitMQ to see if it shows the same data. I set the breakpoint() here https://github.com/danihodovic/celery-exporter/blob/master/src/exporter.py#L201
This should give us a list of queues for each worker. We can flatten the list and then get the length for each.
If so, shouldn't the unit test you added show 1 consumer instead of 0? https://github.com/danihodovic/celery-exporter/pull/118/files#diff-fb60222581054c3ac15e1981679b0a596c22dfeb483873337979183826f559ffR76. In any case this is not a deal breaker. We can merge the changes without the active consumers working for Redis.
That's fine. Given that there is a finite set of queues (usually less than 10) I don't think reading queued data for all queues will have an outsized performance impact. If it does, we can cache the values:
https://prometheus.io/docs/instrumenting/writing_exporters/#scheduling |
Thanks for your advice. According to the previous discussion, I will make the following modifications:
Those modifications will be committed ASAP. |
Awesome! |
Something unexpected happened while I was adding non-zero It seems the So I also verified it with Redis as broker and can not get the correct Should we keep the |
I dig into the
Redis keys returnwhen queue is not empty
when queue is empty
So the |
If the queue is empty there is no active consumer, have I understood this right? In that case we could set it to zero. |
Yep, but I also test with non-empty Redis queue and alive worker. The So, I guess only broker that support amqp protocol will return consumer count. |
What is your preference? Keep if for RabbitMQ or remove it so that it's uniform for all brokers? |
Root cause found, the base class return And Redis Only |
I think we can keep the metric as long as we explain the limitation of broker type in the documentation. |
Sounds good, maybe we can make a PR to Kombu to add the functionality for Redis. |
We can mark as a future work. 😄 Need more learning on the pattern of Celery interact with Redis broker. |
Is the PR ready for review? |
Yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit, rest looks good :)
Nice work @homholueng 👏 伟大的工程工作 |
Released as danihodovic/celery-exporter:0.5.0 Can you update README.md to add the new metrics? https://github.com/danihodovic/celery-exporter#metrics |
close #100
Hi Dani, as promised I am making a PR to add queue_length metric for exporter.
The implementation is simple. A daemon thread will start with main thread and it will scrape length of queues which declare by developer.
Developer can add concerned queues to exporter by
--track-queue
option. e.g.celery-exporter --broker-url=amqp://guest:guest@host.docker.internal:5672/ --track-queue celery --track-queue my_queue
Default queue length scrape interval is 30s and it can be customized by
--queue-track-interval
option. e.g.celery-exporter --broker-url=amqp://guest:guest@host.docker.internal:5672/ --track-queue celery --queue-track-interval 60
Then the exporter will export broker queue length metrics like this
Looking forward to your opinions.
Thx.