-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
export RQ statistics as prometheus metrics #666
Open
terencehonles
wants to merge
1
commit into
rq:master
Choose a base branch
from
terencehonles:export-prometheus-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from rq.job import JobStatus | ||
|
||
from .queues import filter_connection_params, get_connection, get_queue, get_unique_connection_configs | ||
from .workers import get_worker_class | ||
|
||
try: | ||
from prometheus_client import Summary | ||
from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily | ||
|
||
class RQCollector: | ||
"""RQ stats collector""" | ||
|
||
summary = Summary('rq_request_processing_seconds', 'Time spent collecting RQ data') | ||
|
||
def collect(self): | ||
from .settings import QUEUES | ||
|
||
with self.summary.time(): | ||
rq_workers = GaugeMetricFamily('rq_workers', 'RQ workers', labels=['name', 'state', 'queues']) | ||
rq_workers_success = CounterMetricFamily('rq_workers_success', 'RQ workers success count', labels=['name', 'queues']) | ||
rq_workers_failed = CounterMetricFamily('rq_workers_failed', 'RQ workers fail count', labels=['name', 'queues']) | ||
rq_workers_working_time = CounterMetricFamily('rq_workers_working_time', 'RQ workers spent seconds', labels=['name', 'queues']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
rq_jobs = GaugeMetricFamily('rq_jobs', 'RQ jobs by state', labels=['queue', 'status']) | ||
|
||
worker_class = get_worker_class() | ||
unique_configs = get_unique_connection_configs() | ||
connections = {} | ||
for queue_name, config in QUEUES.items(): | ||
index = unique_configs.index(filter_connection_params(config)) | ||
if index not in connections: | ||
connections[index] = connection = get_connection(queue_name) | ||
|
||
for worker in worker_class.all(connection): | ||
name = worker.name | ||
label_queues = ','.join(worker.queue_names()) | ||
rq_workers.add_metric([name, worker.get_state(), label_queues], 1) | ||
rq_workers_success.add_metric([name, label_queues], worker.successful_job_count) | ||
rq_workers_failed.add_metric([name, label_queues], worker.failed_job_count) | ||
rq_workers_working_time.add_metric([name, label_queues], worker.total_working_time) | ||
else: | ||
connection = connections[index] | ||
|
||
queue = get_queue(queue_name, connection=connection) | ||
rq_jobs.add_metric([queue_name, JobStatus.QUEUED], queue.count) | ||
rq_jobs.add_metric([queue_name, JobStatus.STARTED], queue.started_job_registry.count) | ||
rq_jobs.add_metric([queue_name, JobStatus.FINISHED], queue.finished_job_registry.count) | ||
rq_jobs.add_metric([queue_name, JobStatus.FAILED], queue.failed_job_registry.count) | ||
rq_jobs.add_metric([queue_name, JobStatus.DEFERRED], queue.deferred_job_registry.count) | ||
rq_jobs.add_metric([queue_name, JobStatus.SCHEDULED], queue.scheduled_job_registry.count) | ||
|
||
yield rq_workers | ||
yield rq_workers_success | ||
yield rq_workers_failed | ||
yield rq_workers_working_time | ||
yield rq_jobs | ||
|
||
except ImportError: | ||
RQCollector = None # type: ignore[assignment, misc] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you rename
rq_workers_success
tosuccessful_job_count
?