Monitoring & Management
Tutorials
Web UI
Overview
- Ready: 已經發佈到 Queue 的訊息量
- Unacked: 消費端已接收但尚未 Ack 的訊息量
- Total: Ready + Unacked
CLI
rabbitmq-diagnostics
Online Resource Utilization
rabbitmq-diagnostics observer
RabbitMQ Version
[root@tpeeaprmq98 ~]# rabbitmq-diagnostics server_version
Asking node rabbit@tpeeaprmq98 for its RabbitMQ version...
3.10.7
rabbitmqctl
List the queues
rabbitmqctl -p <vhost-name> list_queues name state durable arguments policy
rabbitmqctl -qs -p <vhost-name> list_queues name > queue_names.lst
User Management
# List all users
rabbitmqctl list_users
# Create a new user
rabbitmqctl add_user "eapuser"
rabbitmqctl add_vhost "eap_server"
rabbitmqctl set_permissions -p "eap_server" "eapuser" ".*" ".*" ".*"
# Tag the user with "administrator" for full management UI and HTTP API access
rabbitmqctl set_user_tags username administrator
## Verifying the permission
# => Listing permissions for vhost "/" ...
# => user configure write read
# => user2 .* .* .*
# => guest .* .* .*
# => temp-user .* .* .*
rabbitmqctl list_permissions --vhost /
rabbitmqctl list_permissions --vhost gw1
Connections
rabbitmqctl list_connections
rabbitmqctl list_connections user,peer_host,peer_port,channels,state
Recreate the virtual host
rabbitmqctl delete_vhost <my-vhost-name>
rabbltmqctl add_vhost <my-vhost-name>
Reset the RabbitMQ Node
The broker drops all virtual hosts, queues, exchanges, and non-administrative users.
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
Force Reset the RabbitMQ Node
如果 Cluster 損壞且無法恢復運作時,可以嘗試強制重設 Node。
rabbitmqctl stop_app
rabbitmqctl force_reset
rabbitmqctl start_app
Suspend all listeners and prevent new client connections
暫停 listener 後,可以使用指令
ss -ltpn
檢查所有的 listener port 是否關閉。既有的連線不會受到影響,不過新的連線將無法建立。
# For current node
rabbitmqctl suspend_listeners
# suspends listeners on node rabbit@node2.cluster.rabbitmq.svc: it won't accept any new client connections
rabbitmqctl suspend_listeners -n rabbit@node2.cluster.rabbitmq.svc
# For current node, to resume all listeners on a node and make it accept new client connections again
rabbitmqctl resume_listeners
# resumes listeners on node rabbit@node2.cluster.rabbitmq.svc: it will accept new client connections again
rabbitmqctl resume_listeners -n rabbit@node2.cluster.rabbitmq.svc
rabbitmqadmin
Basic Operation
# List queus
rabbitmqadmin list queues
rabbitmqadmin -H <RabbitMQ-Server-IP> -u <username> -p <password> -V <vhost-name> list queues
# Add a queue with optional parameters
rabbitmqadmin declare queue name=<my-new-queu> durable=true auto_delete=true
Remove multiple queues
rabbitmqadmin -f tsv -q list queues name > q.txt
while read -r name; do rabbitmqadmin -q delete queue name="${name}"; done < q.txt
Connections
rabbitmqadmin -H <RabbitMQ-Server-IP> -u <username> -p <password> -V <vhost-name> list connections name
# Close multiple connections without any channels
rabbitmqadmin -f tsv -q connections name channels | awk -F "\t" '($2 < 1) {print $1}' | tee conn_noChannels.lst
while read -r conn;do rabbitmqadmin close connection name="${conn}"; done < conn_noChannels.lst
Monitoring
- Queue State:
rabbitmqctl list_queues name state
- Health-Check:
rabbitmq-diagnostics check_running
,rabbitmq-diagnostics ping
- Cluster Status:
rabbitmqctl cluster_status