使用rabbitmqctl 管理 mq
-n 指定節點 [root@logging-master zabbix]# rabbitmqctl -n rabbit@localhost list_queues Timeout: 60.0 seconds ... Listing queues for vhost / ... name messages q_game_bilog 6822 q_withdraw_record 0 q_commission_hourly_text 0 q_user_login 0 q_pcenter_payment 0 q_commission_hourly 0 # 監控腳本 [root@logging-master zabbix]# cat monitor_rabbitmq.sh #!/bin/bash sudo -u root rabbitmqctl -n rabbit@localhost list_queues|grep q_game_bilog|awk '{print $2}' 執行結果: [root@logging-master zabbix]# sh monitor_rabbitmq.sh 6763
加入zabbix監控項
[root@logging-master zabbix_agentd.d]# cat userparameter_rabbitmq.conf
UserParameter=q_game_bilog,sh /opt/zabbix/monitor_rabbitmq.sh
zabbix-server 測試
[root@game-tishen ~]# zabbix_get -s 192.168.224.2 -p 10050 -k 'q_game_bilog' erlexec: HOME must be set Only root or rabbitmq can run rabbitmqctl
# 有坑,說是只能是rabbitmq 用戶和 root 用戶才能執行rabbitmqctl
解決:
# 使用sudo 指定 root 用戶執行命令 sudo -u root rabbitmqctl -n rabbit@localhost list_queues|grep q_game_bilog|awk '{print $2}' # 再次測試,返回結果是沒有sudo權限 [root@game-tishen ~]# zabbix_get -s 192.168.224.2 -p 10050 -k 'q_game_bilog' We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. sudo: no tty present and no askpass program specified # 在zabbix-agent端,添加zabbix sudo權限 visudo zabbix ALL=(ALL) NOPASSWD: ALL # 再次測試,結果正常。 [root@game-tishen ~]# zabbix_get -s 192.168.224.2 -p 10050 -k 'q_game_bilog' 8566