Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Last active December 14, 2024 17:56
Show Gist options
  • Select an option

  • Save arsalanses/eef499ecc0a71cb256159005dd2bfe4b to your computer and use it in GitHub Desktop.

Select an option

Save arsalanses/eef499ecc0a71cb256159005dd2bfe4b to your computer and use it in GitHub Desktop.
queue exporter
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"]
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