【问题标题】:Monitor a Laravel Queue Worker with Monit使用 Monit 监控 Laravel Queue Worker
【发布时间】:2017-02-19 16:08:42
【问题描述】:

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

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

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

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

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

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

我尝试关注this question,但没有成功。

【问题讨论】:

    标签: laravel queue supervisord monit


    【解决方案1】:

    如果您仍然需要答案:

    当然可以设置 Monit 来控制您的队列,但需要一点警告(如 their FAQ 中所述);您需要将命令包装在 shell 脚本中。

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

        # 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:

        #!/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
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多