Monitor a Laravel Queue Worker with Monit

余生颓废 提交于 2020-06-25 06:36:10

问题


I am currently considering moving from Supervisor to Monit in order to monitor a Laravel queue worker. Main reason is the ability to monitor CPU, Memory, and set email alerts (afaik with Supervisor I must install another package) since I will want to monitor other things soon such as Redis and perhaps the overall stability and performance of the web server.

To my limited knowledge in process monitoring, Monit is more robust and suitable for the job.

All the documentation that I could find about Laravel and Queue/Job monitoring refer to using Supervisor and, when trying to set it up manually I got stuck with setting up the pid file for the queue listener (I am not a sysadmin).

Is there a reason for Laravel to endorse only Supervisor and not mention Monit at all? (https://laravel.com/docs/5.3/queues#queue-workers-and-deployment)

If not - can someone help with how the setup of the Monit configuration will be per a Laravel queue worker?

Assuming I have a project under /var/www/html/laravel and I would want the process monitored to be /var/www/html/laravel/artisan queue:work --daemon

I tried following this question but without much success.


回答1:


In case you still need an answer:

Is certainly possible to setup Monit to control your queue with a little caveat (as mentioned in their FAQ); you need to wrap your command in a shell script.

In Monit config file (on Ubuntu 14.04 /etc/monit/monitrc) you can add:

    # beanstalk
    check process beanstalkd with pidfile /var/run/beanstalkd.pid
    start program = "/etc/init.d/beanstalkd start"
    stop program = "/etc/init.d/beanstalkd stop"
    if failed host 127.0.0.1 port 11300 then restart
    if 15 restarts within 15 cycles then timeout
    # beanstalk-queue
    check process beanstalk-queue with pidfile /var/run/beanstalk-queue.pid
    start = "YOUR_CHOSEN_PATH/beanstalk-queue.sh start"
    stop = "YOUR_CHOSEN_PATH/beanstalk-queue.sh stop"

Then create the script beanstalk-queue.sh in YOUR_CHOSEN_PATH:

    #!/bin/bash
    case $1 in
            start)
                    echo $$ > /var/run/beanstalk-queue.pid;
                    exec 2>&1 php /PATH_TO_YOUR_LARAVEL_INSTALLATION/artisan queue:work --daemon 1>/tmp/beanstalk-queue.out
                    ;;
            stop)  
                    kill `cat /var/run/beanstalk-queue.pid` ;;
            *)  
                    echo "usage: beanstalk-queue.sh {start|stop}" ;;
    esac
    exit 0

give it executable permissions and that's it!

PS Directories I used are for Ubuntu 14.04, check for other distros.



来源:https://stackoverflow.com/questions/39971787/monitor-a-laravel-queue-worker-with-monit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!