RabbitMQ 消息队列监控 API

本贴最后更新于 1802 天前,其中的信息可能已经水流花落

最近有一个项目,需要编写一个监听 rabbitMQ 集群状态的项目,需要通过 rabbit 提供的 API 来获取相应数据并组装,所以需要学习一下 rabbit 的 API

u39851251753778099895fm26gp0.jpg

HTTP API URL HTTP 请求类型 接口含义
/api/connections GET 获取当前 RabbitMQ 集群下所有打开的连接
/api/nodes GET 获取当前 RabbitMQ 集群下所有节点实例的状态信息
/api/vhosts/{vhost}/connections GET 获取某一个虚拟机主机下的所有打开的 connection 连接
/api/connections/{name}/channels GET 获取某一个连接下所有的管道信息
/api/consumers/{vhost} GET 获取某一个虚拟机主机下的所有消费者信息
/api/exchanges/{vhost} GET 获取某一个虚拟机主机下面的所有交换器信息
/api/queues/{vhost} GET 获取某一个虚拟机主机下的所有队列信息
/api/users GET 获取集群中所有的用户信息
/api/users/{name} get/put/delete 获取/更新/删除指定用户信息
/api/users/{user}/permissions GET 获取当前指定用户的所有权限信息
/api/permissions/{vhost}/{user} get/put/delete 获取/更新/删除指定虚拟主机下特定用户的权限
/api/exchanges/{vhost}/{name}/publish POST 在指定的虚拟机主机和交换器上发布一个消息
/api/queues/{vhost}/{name}/get POST 测在指定虚拟机主机和队列名中获取消息,同时该动作会修改队列状态试
/api/healthchecks/node/{node} GET 获取指定节点的健康检查状态
/api/nodes/{node}/memory GET 获取指定节点的内存使用信息

部分 API 实例

/api/overview 返回集群度量标准

字段名称 意义
cluster_name 集群名称
management_version 版本
message_stats 消息速率
object_totals.connections 连接总数
object_totals.channels 频道总数
object_totals.queues 队列总数
object_totals.consumers 消费者总数
queue_totals.messages 准备好与未确认的消息总数
queue_totals.messages_ready 准备发送的消息数
queue_totals.messages_unacknowledged 未确认消息的数量
message_stats.publish 最近发布的消息
message_stats.publish_details.rate 消息发布率
message_stats.deliver_get 最近发送给消费者的消息
message_stats.deliver_get.rate 邮件传递率
message_stats 其他消息统计
{ "management_version": "3.7.14", "rates_mode": "basic", "sample_retention_policies": { "global": [ 600, 3600, 28800, 86400 ], "basic": [ 600, 3600 ], "detailed": [ 600 ] }, "exchange_types": [ { "name": "fanout", "description": "AMQP fanout exchange, as per the AMQP specification", "enabled": true }, { "name": "headers", "description": "AMQP headers exchange, as per the AMQP specification", "enabled": true }, { "name": "x-delayed-message", "description": "Delayed Message Exchange.", "enabled": true }, { "name": "direct", "description": "AMQP direct exchange, as per the AMQP specification", "enabled": true }, { "name": "topic", "description": "AMQP topic exchange, as per the AMQP specification", "enabled": true } ], "rabbitmq_version": "3.7.14", "cluster_name": "rabbit@wangtaodeMacBook-Pro", "erlang_version": "21.3.2", "erlang_full_version": "Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:192] [hipe] [dtrace]", "message_stats": { "disk_reads": 2, "disk_reads_details": { "rate": 0 }, "disk_writes": 0, "disk_writes_details": { "rate": 0 } }, "churn_rates": { "channel_closed": 0, "channel_closed_details": { "rate": 0 }, "channel_created": 0, "channel_created_details": { "rate": 0 }, "connection_closed": 0, "connection_closed_details": { "rate": 0 }, "connection_created": 0, "connection_created_details": { "rate": 0 }, "queue_created": 0, "queue_created_details": { "rate": 0 }, "queue_declared": 0, "queue_declared_details": { "rate": 0 }, "queue_deleted": 0, "queue_deleted_details": { "rate": 0 } }, "queue_totals": { "messages": 2, "messages_details": { "rate": 0 }, "messages_ready": 2, "messages_ready_details": { "rate": 0 }, "messages_unacknowledged": 0, "messages_unacknowledged_details": { "rate": 0 } }, "object_totals": { "channels": 0, "connections": 0, "consumers": 0, "exchanges": 16, "queues": 10 }, "statistics_db_event_queue": 0, "node": "rabbit@localhost", "listeners": [ { "node": "rabbit@localhost", "protocol": "amqp", "ip_address": "127.0.0.1", "port": 5672, "socket_opts": { "backlog": 128, "nodelay": true, "linger": [ true, 0 ], "exit_on_close": false } }, { "node": "rabbit@localhost", "protocol": "clustering", "ip_address": "::", "port": 25672, "socket_opts": [] }, { "node": "rabbit@localhost", "protocol": "http", "ip_address": "::", "port": 15672, "socket_opts": { "port": 15672 } }, { "node": "rabbit@localhost", "protocol": "mqtt", "ip_address": "::", "port": 1883, "socket_opts": { "backlog": 128, "nodelay": true } }, { "node": "rabbit@localhost", "protocol": "stomp", "ip_address": "::", "port": 61613, "socket_opts": { "backlog": 128, "nodelay": true } } ], "contexts": [ { "ssl_opts": [], "node": "rabbit@localhost", "description": "RabbitMQ Management", "path": "/", "port": "15672" } ] }

/api/nodes 返回所有集群成员统计消息

字段名称 意义
mem_used 使用的内存总量
mem_limit 内存使用率
mem_alarm 内存警报开关
disk_free_limit 磁盘空间限制大小
disk_free_alarm 磁盘空间大小限制开关
fd_total 文件描述符限制
fd_used 文件描述符是否开始
io_file_handle_open_attempt_count io 文件句柄打开尝试计数
sockets_total socket 数量
sockets_used 正在使用的 socket 数量
message_stats.disk_reads 磁盘读取的消息数
message_stats.disk_writes 写入磁盘的消息数
cluster_links 节点间通信链路
gc_num GC 次数
gc_bytes_reclaimed GC 回收的字节数
proc_total Erlang 进程限制数量
proc_used Erlang 进行使用数量
run_queue 运行时队列数量
[ { "partitions": [], "os_pid": "4470", "fd_total": 256, "sockets_total": 138, "mem_limit": 6871947673, "mem_alarm": false, "disk_free_limit": 50000000, "disk_free_alarm": false, "proc_total": 1048576, "rates_mode": "basic", "uptime": 4176419, "run_queue": 1, "processors": 12, "exchange_types": [ { "name": "fanout", "description": "AMQP fanout exchange, as per the AMQP specification", "enabled": true }, { "name": "headers", "description": "AMQP headers exchange, as per the AMQP specification", "enabled": true }, { "name": "x-delayed-message", "description": "Delayed Message Exchange.", "enabled": true }, { "name": "direct", "description": "AMQP direct exchange, as per the AMQP specification", "enabled": true }, { "name": "topic", "description": "AMQP topic exchange, as per the AMQP specification", "enabled": true } ], "auth_mechanisms": [ { "name": "RABBIT-CR-DEMO", "description": "RabbitMQ Demo challenge-response authentication mechanism", "enabled": false }, { "name": "AMQPLAIN", "description": "QPid AMQPLAIN mechanism", "enabled": true }, { "name": "PLAIN", "description": "SASL PLAIN authentication mechanism", "enabled": true } ], "applications": [ { "name": "amqp10_common", "description": "Modules shared by rabbitmq-amqp1.0 and rabbitmq-amqp1.0-client", "version": "3.7.14" }, { "name": "amqp_client", "description": "RabbitMQ AMQP Client", "version": "3.7.14" }, { "name": "asn1", "description": "The Erlang ASN1 compiler version 5.0.8", "version": "5.0.8" }, { "name": "compiler", "description": "ERTS CXC 138 10", "version": "7.3.2" }, { "name": "cowboy", "description": "Small, fast, modern HTTP server.", "version": "2.6.1" }, { "name": "cowlib", "description": "Support library for manipulating Web protocols.", "version": "2.7.0" }, { "name": "crypto", "description": "CRYPTO", "version": "4.4.1" }, { "name": "goldrush", "description": "Erlang event stream processor", "version": "0.1.9" }, { "name": "inets", "description": "INETS CXC 138 49", "version": "7.0.6" }, { "name": "jsx", "description": "a streaming, evented json parsing toolkit", "version": "2.9.0" }, { "name": "kernel", "description": "ERTS CXC 138 10", "version": "6.3" }, { "name": "lager", "description": "Erlang logging framework", "version": "3.6.9" }, { "name": "mnesia", "description": "MNESIA CXC 138 12", "version": "4.15.6" }, { "name": "os_mon", "description": "CPO CXC 138 46", "version": "2.4.7" }, { "name": "public_key", "description": "Public key infrastructure", "version": "1.6.5" }, { "name": "rabbit", "description": "RabbitMQ", "version": "3.7.14" }, { "name": "rabbit_common", "description": "Modules shared by rabbitmq-server and rabbitmq-erlang-client", "version": "3.7.14" }, { "name": "rabbitmq_amqp1_0", "description": "AMQP 1.0 support for RabbitMQ", "version": "3.7.14" }, { "name": "rabbitmq_delayed_message_exchange", "description": "RabbitMQ Delayed Message Exchange", "version": "20171201-3.7.x" }, { "name": "rabbitmq_management", "description": "RabbitMQ Management Console", "version": "3.7.14" }, { "name": "rabbitmq_management_agent", "description": "RabbitMQ Management Agent", "version": "3.7.14" }, { "name": "rabbitmq_mqtt", "description": "RabbitMQ MQTT Adapter", "version": "3.7.14" }, { "name": "rabbitmq_stomp", "description": "RabbitMQ STOMP plugin", "version": "3.7.14" }, { "name": "rabbitmq_web_dispatch", "description": "RabbitMQ Web Dispatcher", "version": "3.7.14" }, { "name": "ranch", "description": "Socket acceptor pool for TCP protocols.", "version": "1.7.1" }, { "name": "recon", "description": "Diagnostic tools for production use", "version": "2.4.0" }, { "name": "sasl", "description": "SASL CXC 138 11", "version": "3.3" }, { "name": "ssl", "description": "Erlang/OTP SSL application", "version": "9.2.1" }, { "name": "stdlib", "description": "ERTS CXC 138 10", "version": "3.8" }, { "name": "syntax_tools", "description": "Syntax tools", "version": "2.1.7" }, { "name": "sysmon_handler", "description": "Rate-limiting system_monitor event handler", "version": "1.1.0" }, { "name": "xmerl", "description": "XML parser", "version": "1.3.20" } ], "contexts": [ { "description": "RabbitMQ Management", "path": "/", "port": "15672" } ], "log_files": [ "/usr/local/var/log/rabbitmq/rabbit@localhost.log", "/usr/local/var/log/rabbitmq/rabbit@localhost_upgrade.log" ], "db_dir": "/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost", "config_files": [], "net_ticktime": 60, "enabled_plugins": [ "rabbitmq_amqp1_0", "rabbitmq_delayed_message_exchange", "rabbitmq_management", "rabbitmq_mqtt", "rabbitmq_stomp" ], "mem_calculation_strategy": "rss", "name": "rabbit@localhost", "type": "disc", "running": true, "mem_used": 86556672, "mem_used_details": { "rate": 4096 }, "fd_used": 72, "fd_used_details": { "rate": -0.4 }, "sockets_used": 0, "sockets_used_details": { "rate": 0 }, "proc_used": 457, "proc_used_details": { "rate": 0 }, "disk_free": 172579655680, "disk_free_details": { "rate": -15564.8 }, "gc_num": 22686, "gc_num_details": { "rate": 4.6 }, "gc_bytes_reclaimed": 1060411720, "gc_bytes_reclaimed_details": { "rate": 158604.8 }, "context_switches": 307064, "context_switches_details": { "rate": 37.4 }, "io_read_count": 22, "io_read_count_details": { "rate": 0 }, "io_read_bytes": 2083, "io_read_bytes_details": { "rate": 0 }, "io_read_avg_time": 0.02909090909090909, "io_read_avg_time_details": { "rate": 0 }, "io_write_count": 0, "io_write_count_details": { "rate": 0 }, "io_write_bytes": 0, "io_write_bytes_details": { "rate": 0 }, "io_write_avg_time": 0, "io_write_avg_time_details": { "rate": 0 }, "io_sync_count": 0, "io_sync_count_details": { "rate": 0 }, "io_sync_avg_time": 0, "io_sync_avg_time_details": { "rate": 0 }, "io_seek_count": 0, "io_seek_count_details": { "rate": 0 }, "io_seek_avg_time": 0, "io_seek_avg_time_details": { "rate": 0 }, "io_reopen_count": 0, "io_reopen_count_details": { "rate": 0 }, "mnesia_ram_tx_count": 60, "mnesia_ram_tx_count_details": { "rate": 0 }, "mnesia_disk_tx_count": 10, "mnesia_disk_tx_count_details": { "rate": 0 }, "msg_store_read_count": 0, "msg_store_read_count_details": { "rate": 0 }, "msg_store_write_count": 0, "msg_store_write_count_details": { "rate": 0 }, "queue_index_journal_write_count": 0, "queue_index_journal_write_count_details": { "rate": 0 }, "queue_index_write_count": 0, "queue_index_write_count_details": { "rate": 0 }, "queue_index_read_count": 3, "queue_index_read_count_details": { "rate": 0 }, "io_file_handle_open_attempt_count": 73, "io_file_handle_open_attempt_count_details": { "rate": 0 }, "io_file_handle_open_attempt_avg_time": 0.031643835616438354, "io_file_handle_open_attempt_avg_time_details": { "rate": 0 }, "connection_created": 0, "connection_created_details": { "rate": 0 }, "connection_closed": 0, "connection_closed_details": { "rate": 0 }, "channel_created": 0, "channel_created_details": { "rate": 0 }, "channel_closed": 0, "channel_closed_details": { "rate": 0 }, "queue_declared": 0, "queue_declared_details": { "rate": 0 }, "queue_created": 0, "queue_created_details": { "rate": 0 }, "queue_deleted": 0, "queue_deleted_details": { "rate": 0 }, "cluster_links": [], "metrics_gc_queue_length": { "connection_closed": 0, "channel_closed": 0, "consumer_deleted": 0, "exchange_deleted": 0, "queue_deleted": 0, "vhost_deleted": 0, "node_node_deleted": 0, "channel_consumer_deleted": 0 } } ]

/api/nodes/ 返回单个节点的统计信息

{ "partitions": [], "os_pid": "4470", "fd_total": 256, "sockets_total": 138, "mem_limit": 6871947673, "mem_alarm": false, "disk_free_limit": 50000000, "disk_free_alarm": false, "proc_total": 1048576, "rates_mode": "basic", "uptime": 11728280, "run_queue": 1, "processors": 12, "exchange_types": [ { "name": "fanout", "description": "AMQP fanout exchange, as per the AMQP specification", "enabled": true }, { "name": "headers", "description": "AMQP headers exchange, as per the AMQP specification", "enabled": true }, { "name": "x-delayed-message", "description": "Delayed Message Exchange.", "enabled": true }, { "name": "direct", "description": "AMQP direct exchange, as per the AMQP specification", "enabled": true }, { "name": "topic", "description": "AMQP topic exchange, as per the AMQP specification", "enabled": true } ], "auth_mechanisms": [ { "name": "RABBIT-CR-DEMO", "description": "RabbitMQ Demo challenge-response authentication mechanism", "enabled": false }, { "name": "AMQPLAIN", "description": "QPid AMQPLAIN mechanism", "enabled": true }, { "name": "PLAIN", "description": "SASL PLAIN authentication mechanism", "enabled": true } ], "applications": [ { "name": "amqp10_common", "description": "Modules shared by rabbitmq-amqp1.0 and rabbitmq-amqp1.0-client", "version": "3.7.14" }, { "name": "amqp_client", "description": "RabbitMQ AMQP Client", "version": "3.7.14" }, { "name": "asn1", "description": "The Erlang ASN1 compiler version 5.0.8", "version": "5.0.8" }, { "name": "compiler", "description": "ERTS CXC 138 10", "version": "7.3.2" }, { "name": "cowboy", "description": "Small, fast, modern HTTP server.", "version": "2.6.1" }, { "name": "cowlib", "description": "Support library for manipulating Web protocols.", "version": "2.7.0" }, { "name": "crypto", "description": "CRYPTO", "version": "4.4.1" }, { "name": "goldrush", "description": "Erlang event stream processor", "version": "0.1.9" }, { "name": "inets", "description": "INETS CXC 138 49", "version": "7.0.6" }, { "name": "jsx", "description": "a streaming, evented json parsing toolkit", "version": "2.9.0" }, { "name": "kernel", "description": "ERTS CXC 138 10", "version": "6.3" }, { "name": "lager", "description": "Erlang logging framework", "version": "3.6.9" }, { "name": "mnesia", "description": "MNESIA CXC 138 12", "version": "4.15.6" }, { "name": "os_mon", "description": "CPO CXC 138 46", "version": "2.4.7" }, { "name": "public_key", "description": "Public key infrastructure", "version": "1.6.5" }, { "name": "rabbit", "description": "RabbitMQ", "version": "3.7.14" }, { "name": "rabbit_common", "description": "Modules shared by rabbitmq-server and rabbitmq-erlang-client", "version": "3.7.14" }, { "name": "rabbitmq_amqp1_0", "description": "AMQP 1.0 support for RabbitMQ", "version": "3.7.14" }, { "name": "rabbitmq_delayed_message_exchange", "description": "RabbitMQ Delayed Message Exchange", "version": "20171201-3.7.x" }, { "name": "rabbitmq_management", "description": "RabbitMQ Management Console", "version": "3.7.14" }, { "name": "rabbitmq_management_agent", "description": "RabbitMQ Management Agent", "version": "3.7.14" }, { "name": "rabbitmq_mqtt", "description": "RabbitMQ MQTT Adapter", "version": "3.7.14" }, { "name": "rabbitmq_stomp", "description": "RabbitMQ STOMP plugin", "version": "3.7.14" }, { "name": "rabbitmq_web_dispatch", "description": "RabbitMQ Web Dispatcher", "version": "3.7.14" }, { "name": "ranch", "description": "Socket acceptor pool for TCP protocols.", "version": "1.7.1" }, { "name": "recon", "description": "Diagnostic tools for production use", "version": "2.4.0" }, { "name": "sasl", "description": "SASL CXC 138 11", "version": "3.3" }, { "name": "ssl", "description": "Erlang/OTP SSL application", "version": "9.2.1" }, { "name": "stdlib", "description": "ERTS CXC 138 10", "version": "3.8" }, { "name": "syntax_tools", "description": "Syntax tools", "version": "2.1.7" }, { "name": "sysmon_handler", "description": "Rate-limiting system_monitor event handler", "version": "1.1.0" }, { "name": "xmerl", "description": "XML parser", "version": "1.3.20" } ], "contexts": [ { "description": "RabbitMQ Management", "path": "/", "port": "15672" } ], "log_files": [ "/usr/local/var/log/rabbitmq/rabbit@localhost.log", "/usr/local/var/log/rabbitmq/rabbit@localhost_upgrade.log" ], "db_dir": "/usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost", "config_files": [], "net_ticktime": 60, "enabled_plugins": [ "rabbitmq_amqp1_0", "rabbitmq_delayed_message_exchange", "rabbitmq_management", "rabbitmq_mqtt", "rabbitmq_stomp" ], "mem_calculation_strategy": "rss", "name": "rabbit@localhost", "running": true, "type": "disc", "mem_used": 86814720, "mem_used_details": { "rate": -117964.8 }, "fd_used": 72, "fd_used_details": { "rate": 0 }, "sockets_used": 0, "sockets_used_details": { "rate": 0 }, "proc_used": 457, "proc_used_details": { "rate": 0 }, "disk_free": 172549808128, "disk_free_details": { "rate": -31129.6 }, "gc_num": 38308, "gc_num_details": { "rate": 3.4 }, "gc_bytes_reclaimed": 1616503320, "gc_bytes_reclaimed_details": { "rate": 152201.6 }, "context_switches": 423307, "context_switches_details": { "rate": 37.6 }, "io_read_count": 22, "io_read_count_details": { "rate": 0 }, "io_read_bytes": 2083, "io_read_bytes_details": { "rate": 0 }, "io_read_avg_time": 0.02909090909090909, "io_read_avg_time_details": { "rate": 0 }, "io_write_count": 0, "io_write_count_details": { "rate": 0 }, "io_write_bytes": 0, "io_write_bytes_details": { "rate": 0 }, "io_write_avg_time": 0, "io_write_avg_time_details": { "rate": 0 }, "io_sync_count": 0, "io_sync_count_details": { "rate": 0 }, "io_sync_avg_time": 0, "io_sync_avg_time_details": { "rate": 0 }, "io_seek_count": 0, "io_seek_count_details": { "rate": 0 }, "io_seek_avg_time": 0, "io_seek_avg_time_details": { "rate": 0 }, "io_reopen_count": 0, "io_reopen_count_details": { "rate": 0 }, "mnesia_ram_tx_count": 60, "mnesia_ram_tx_count_details": { "rate": 0 }, "mnesia_disk_tx_count": 10, "mnesia_disk_tx_count_details": { "rate": 0 }, "msg_store_read_count": 0, "msg_store_read_count_details": { "rate": 0 }, "msg_store_write_count": 0, "msg_store_write_count_details": { "rate": 0 }, "queue_index_journal_write_count": 0, "queue_index_journal_write_count_details": { "rate": 0 }, "queue_index_write_count": 0, "queue_index_write_count_details": { "rate": 0 }, "queue_index_read_count": 3, "queue_index_read_count_details": { "rate": 0 }, "io_file_handle_open_attempt_count": 73, "io_file_handle_open_attempt_count_details": { "rate": 0 }, "io_file_handle_open_attempt_avg_time": 0.031643835616438354, "io_file_handle_open_attempt_avg_time_details": { "rate": 0 }, "connection_created": 0, "connection_created_details": { "rate": 0 }, "connection_closed": 0, "connection_closed_details": { "rate": 0 }, "channel_created": 0, "channel_created_details": { "rate": 0 }, "channel_closed": 0, "channel_closed_details": { "rate": 0 }, "queue_declared": 0, "queue_declared_details": { "rate": 0 }, "queue_created": 0, "queue_created_details": { "rate": 0 }, "queue_deleted": 0, "queue_deleted_details": { "rate": 0 }, "cluster_links": [], "metrics_gc_queue_length": { "connection_closed": 0, "channel_closed": 0, "consumer_deleted": 0, "exchange_deleted": 0, "queue_deleted": 0, "vhost_deleted": 0, "node_node_deleted": 0, "channel_consumer_deleted": 0 } }
  • RabbitMQ

    RabbitMQ 是一个开源的 AMQP 实现,服务器端用 Erlang 语言编写,支持多种语言客户端,如:Python、Ruby、.NET、Java、C、PHP、ActionScript 等。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。

    49 引用 • 60 回帖 • 345 关注
  • 队列
    6 引用 • 1 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...