Last active
December 14, 2024 17:56
-
-
Save arsalanses/eef499ecc0a71cb256159005dd2bfe4b to your computer and use it in GitHub Desktop.
queue exporter
This file contains hidden or 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
| FROM python:3.8-slim-buster | |
| WORKDIR /app | |
| COPY requirements.txt requirements.txt | |
| RUN pip install -r requirements.txt | |
| COPY exporter.py . | |
| CMD ["python", "exporter.py"] |
This file contains hidden or 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
| from prometheus_client import start_http_server, Gauge | |
| import subprocess | |
| import json | |
| import docker | |
| import time | |
| def get_queue_size(): | |
| client = docker.from_env() | |
| container = client.containers.get('your-laravel-container-name') | |
| result = container.exec_run(['php', 'artisan', 'queue:size']) | |
| return json.loads(result.output.decode('utf-8')) | |
| def main(): | |
| g = Gauge('laravel_queue_size', 'Size of the Laravel queue') | |
| start_http_server(8000) | |
| while True: | |
| queue_size = get_queue_size() | |
| for queue, size in queue_size.items(): | |
| g.labels(queue=queue).set(size) | |
| time.sleep(60) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment