使用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
01-03 21:51