使用 Monit 监控 Laravel Queue Worker [英] Monitor a Laravel Queue Worker with Monit

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

问题描述

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

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.

就我在过程监控方面的有限知识而言,Monit 更强大,更适合这项工作.

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

我能找到的关于 Laravel 和队列/作业监控的所有文档都提到了使用 Supervisor,当尝试手动设置它时,我无法为队列监听器设置 pid 文件(我不是系统管理员).

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).

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

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)

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

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

假设我在 /var/www/html/laravel 下有一个项目,我希望监控的进程是 /var/www/html/laravel/artisan queue:work --守护进程

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.

推荐答案

如果你还需要答案:

当然可以设置 Monit 来控制您的队列,但需要注意一点(如 他们的常见问题解答);您需要将命令包装在 shell 脚本中.

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.

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

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"

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

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我使用的目录适用于 Ubuntu 14.04,请检查其他发行版.

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

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

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