• centos环境下使用zabbix配合python脚本对supervisor中的进程运行状态进行监控


    centos环境下使用zabbix配合python脚本对supervisor中的进程运行状态进行监控

    # 需要监控的supervisor相关的进程如下
    # supervisorctl status

    maxapi-laravel-convert:maxapi-laravel-convert_01       RUNNING   pid 24584, uptime 0:46:18
    maxapi-laravel-convert:maxapi-laravel-convert_02       RUNNING   pid 24695, uptime 0:45:23
    maxapi-laravel-listeners:maxapi-laravel-listeners_01   RUNNING   pid 4538, uptime 2 days, 6:38:05
    maxapi-laravel-listeners:maxapi-laravel-listeners_02   RUNNING   pid 4536, uptime 2 days, 6:38:05
    maxapi-laravel-listeners:maxapi-laravel-listeners_03   RUNNING   pid 4537, uptime 2 days, 6:38:05
    maxapi-laravel-listeners:maxapi-laravel-listeners_04   RUNNING   pid 4539, uptime 2 days, 6:38:05
    maxapi-laravel-worker:maxapi-laravel-worker_01         RUNNING   pid 4532, uptime 2 days, 6:38:05
    maxapi-laravel-worker:maxapi-laravel-worker_02         RUNNING   pid 4533, uptime 2 days, 6:38:05
    maxapi-laravel-worker:maxapi-laravel-worker_03         RUNNING   pid 4534, uptime 2 days, 6:38:05
    maxapi-laravel-worker:maxapi-laravel-worker_04         RUNNING   pid 4535, uptime 2 days, 6:38:05

    # 直接监控进程名可能会有误差,如下,监控 queue:work 进程如果报警可能不知道是哪个程序宕机引发的
    apache    4532  4530  0 Jun10 ?        00:00:40 /usr/local/bin/php /data/www/vhosts/maxapi.chinasoft.cn/artisan queue:work --daemon
    apache    4536  4530  0 Jun10 ?        00:00:40 /usr/local/bin/php /data/www/vhosts/maxapi.chinasoft.cn/artisan queue:work --queue=listeners --daemon

    # 使用python对 supervisorctl status 的输出结果进行判断比较合适
    # cat supervisor_status_monitor.py

    #_*_ coding:utf-8 _*_
    
    import sys
    import os
    res = {}
    
    file1 =os.popen('sudo /usr/bin/supervisorctl status')
    for line in file1.readlines():
            #获取服务名&服务状态
            #print 'line = %s' % line
            ser_name = line.split()[0].strip().split(":")[0]
            #print 'ser_name = %s' % ser_name
            ser_res = line.split()[1].strip()
    
            #判断服务运行状态,1为成功,0为失败
            if ser_res == 'RUNNING':
                    ser_res = '1'
            else:
                    ser_res = '0'
            res[ser_name] = ser_res
    
    #print res
    user_input = str(sys.argv[1].strip())
    print res[user_input]

    # 监控的配置
    UserParameter=supervisorctl.status[*],/usr/bin/python /usr/local/zabbix_agents_3.2.0/scripts/supervisor_status_monitor.py $1

    # 具体的监控项目
    supervisorctl.status[maxapi-laravel-convert]
    supervisorctl.status[maxapi-laravel-worker]
    supervisorctl.status[maxapi-laravel-listeners]

    # shell版监控


    #!/bin/bash
    supervisorctl status > /usr/local/zabbix/etc/zabbix_agentd.conf.d/supervisorctl.txt
    file=/usr/local/zabbix/etc/zabbix_agentd.conf.d/supervisorctl.txt
    case $1 in
            redis)
                    REDIS=grep "redis" $file |awk '{print $2}'
                    if [ "$REDIS" == "RUNNING" ];then
                            echo "2"
                    else
                            echo "1"
                    fi
                    ;;
            *)
    echo "USAGE: $0 [ redis | motorroom ]"
    esac

  • 相关阅读:
    200斤的甄子丹还是这么灵活能打欢乐,拯救无聊就靠他了
    redis 发布与订阅
    洛谷P2294 [HNOI2005]狡猾的商人
    洛谷P2294 [HNOI2005]狡猾的商人
    崛起于Springboot2.X之开发拦截器(21)
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    Openssh
  • 原文地址:https://www.cnblogs.com/reblue520/p/13100249.html
Copyright © 2020-2023  润新知