RabbitMQ提供了完善的管理和监控工具,分management plugin 和 rabbitmqctl 两种类型的工具。
一. management plugin
rabbitmq-management plugin提供HTTP API来管理和监控RabbitMQ Server,具体包含如下功能:
Declare,list and delete exchanges,queues,bindings,users,virtual hosts and permissions。
Monitor queue length,message rates globally and per channel,data rates per connection,etc。
Send and receive messages。
Monitor Erlang processes,file descriptors,memory use。
Export / inport object definitions to JSON。
Force close connections,purge queues。
management plugin默认就在RabbitMQ的发布版本中,只需要enable就可以了,执行以下命令:
$ sudo rabbitmq-plugins enable rabbitmq_management
看到这一幕后,重启RabbitMQ就可以了。需要注意的是,mochiweb 必须得有,mochiweb是一个用来构建Web应用的轻便,高效的HTTP应用框架的Erlang库。
下面可以通过以下两种方式来访问管理和监控界面:
1. Web UI
打开浏览器,输入 http://[server-name]:15672/ 如 http://localhost:15672/ ,会要求输入用户名和密码,用默认的guest/guest即可,确认后会出现下面界面:
接下来你就可以尽情掌控RabbitMQ了。management UI是static HTML页面,其通过Javascript查询HTTP API得到实时数据。实质上Web UI最终也是调用的Management command line tool。
2. 命令行工具
Management command line tool(rabbitmqadmin)拥有跟Web UI同样的功能,可能还更便于脚本使用。rabbitmqadmin仅仅是一个定制的HTTP客户端,如果想在自己的程序中引入rabbitmqadmin的话,可以直接使用HTTP API。rabbitmqadmin可以在http://server-name:15672/cli页面下载。
下载rabbitmqadmin.txt后,将其重命名为rabbitmqadmin,拷贝到 /usr/local/bin 或者你想要的路径,并增加可执行权限。使用:
$ sudo rabbitmqadmin --help
可以查看使用指南。
二. rabbitmqctl
rabbitmqctl是一个简单的命令行工具用于管理RabbitMQ Server,在shell中执行如下命令,能看到各种命令简价:
Usage:
rabbitmqctl [-n <node>] [-q] <command> [<command options>]
Options:
-n node
-q
Default node is "rabbit@server", where server is the local host. On a host named "server.example.com", the node name of the RabbitMQ Erlang node will usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some non-default value at broker startup time). The output of hostname -s is usually the correct suffix to use after the "@" sign. See rabbitmq-server(1) for
details of configuring the RabbitMQ broker.
Quiet output mode is selected with the "-q" flag. Informational messages are
suppressed when quiet mode is in effect.
Commands:
stop [<pid_file>]
stop_app
start_app
wait <pid_file>
reset
force_reset
rotate_logs <suffix>
join_cluster <clusternode>[<--ram>]
cluster_status
change_cluster_node_type disc | ram
forget_cluster_node [--offline]
update_cluster_nodes clusternode
add_user <username> <password>
delete_user <username>
change_password <username> <newpassword>
clear_password <username>
set_user_tags <username> <tag> ...
list_users
add_vhost <vhostpath>
delete_vhost <vhostpath>
list_vhosts [<vhostinfoitem> ...]
set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
clear_permissions [-p <vhostpath>] <username>
list_permissions [-p <vhostpath>]
list_user_permissions <username>
set_parameter [-p <vhostpath>] <component_name> <name> <value>
clear_parameter [-p <vhostpath>] <component_name> <key>
list_parameters [-p <vhostpath>]
set_policy [-p <vhostpath>] <name> <pattern> <definition> [<priority>]
clear_policy [-p <vhostpath>] <name>
list_policies [-p <vhostpath>]
list_queues [-p <vhostpath>] [<queueinfoitem> ...]
list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]
list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]
list_connections [<connectioninfoitem> ...]
list_channels [<channelinfoitem> ...]
list_consumers [-p <vhostpath>]
status
environment
report
eval <expr>
close_connection <connectionpid> <explanation>
trace_on [-p <vhost>]
trace_off [-p <vhost>]
set_vm_memory_high_watermark <fraction>
<vhostinfoitem> must be a member of the list [name, tracing].
The list_queues, list_exchanges and list_bindings commands accept an optional virtual host parameter for which to display results. The default value is "/".
<queueinfoitem> must be a member of the list [name, durable, auto_delete, arguments, policy, pid, owner_pid, exclusive_consumer_pid, exclusive_consumer_tag, messages_ready, messages_unacknowledged, messages, consumers, active_consumers, memory, slave_pids, synchronised_slave_pids].
<exchangeinfoitem> must be a member of the list [name, type, durable, auto_delete, internal, arguments, policy].
<bindinginfoitem> must be a member of the list [source_name, source_kind, destination_name, destination_kind, routing_key, arguments].
<connectioninfoitem> must be a member of the list [pid, name, port, host, peer_port, peer_host, ssl, ssl_protocol, ssl_key_exchange, ssl_cipher, ssl_hash, peer_cert_subject, peer_cert_issuer, peer_cert_validity, last_blocked_by, last_blocked_age, state, channels, protocol, auth_mechanism, user, vhost, timeout, frame_max, client_properties, recv_oct, recv_cnt, send_oct, send_cnt, send_pend].
<channelinfoitem> must be a member of the list [pid, connection, name, number, user, vhost, transactional, confirm, consumer_count, messages_unacknowledged, messages_uncommitted, acks_uncommitted, messages_unconfirmed, prefetch_count, client_flow_blocked].
原文:http://my.oschina.net/fhd/blog/375620