使用Monit监视Laravel队列工作器 [英] Monitor a Laravel Queue Worker with Monit

查看:52
本文介绍了使用Monit监视Laravel队列工作器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在考虑从Supervisor转到Monit,以便监视Laravel队列工作者.主要原因是能够监视CPU,内存和设置电子邮件警报的能力(使用Supervisor的afaik,我必须安装另一个软件包),因为我想尽快监视其他事物,例如Redis,也许还监视Web服务器的整体稳定性和性能./p>

就我在过程监控方面的有限知识而言,Monit更加健壮并适合该工作.

我可以找到的有关Laravel和队列/作业监视的所有文档均参考使用Supervisor,并且在尝试手动设置它时,我陷入了为队列侦听器设置pid文件的困扰(我不是sysadmin)

Laravel是否有理由只认可主管,而根本不提及Monit?( https://laravel.com/docs/5.3/queues#queue-工人和部署)

如果没有-有人可以帮助每个Laravel队列工作者如何设置Monit配置吗?

假设我在/var/www/html/laravel 下有一个项目,并且我希望监视的过程为/var/www/html/laravel/artisan queue:work--守护程序

我尝试遵循这个问题,但没有成功./p>

解决方案

如果您仍然需要答案:

当然可以设置Monit进行一些警告,以控制您的队列(如常见问题解答);您需要将命令包装在Shell脚本中.

在Monit配置文件中(在Ubuntu 14.04/etc/monit/monitrc上),您可以添加:

 #beantalk使用pidfile/var/run/beanstalkd.pid检查进程beantalkd启动程序="/etc/init.d/beanstalkd启动"停止程序="/etc/init.d/beanstalkd stop"如果主机127.0.0.1端口11300发生故障,则重新启动如果15在15个周期内重新启动,则超时#beantalk-queue使用pidfile/var/run/beanstalk-queue.pid检查进程beantalk队列开始="YOUR_CHOSEN_PATH/beanstalk-queue.sh开始"停止="YOUR_CHOSEN_PATH/beanstalk-queue.sh停止" 

然后在YOUR_CHOSEN_PATH中创建脚本beantalk-queue.sh:

 #!/bin/bash案例$ 1开始)回声$$>/var/run/beanstalk-queue.pid;exec 2>& 1 php/PATH_TO_YOUR_LARAVEL_INSTALLATION/artisan queue:work --daemon 1>/tmp/beanstalk-queue.out;;停止)杀死`cat/var/run/beanstalk-queue.pid` ;;*)回声用法:beanstalk-queue.sh {开始|停止}" ;;埃萨克出口0 

赋予它可执行权限,就是这样!

PS我使用的目录用于Ubuntu 14.04,请检查其他发行版.

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.

解决方案

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.

这篇关于使用Monit监视Laravel队列工作器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆