如何以json格式获取Rabbitmq集群状态

时间:2019-09-24 17:25:25

标签: rabbitmq

如何从Rabbitmq获取JSON格式的状态和cluster_status

sudo rabbitmqctl status
sudo rabbitmqctl cluster_status

2 个答案:

答案 0 :(得分:2)

help是你的朋友:

# rabbitmqctl help cluster_status
Error:

Usage

rabbitmqctl [--node <node>] [--longnames] [--quiet] cluster_status

Displays all the nodes in the cluster grouped by node type, together with the currently running nodes.


Relevant Doc Guides

 * https://rabbitmq.com/clustering.html

 * https://rabbitmq.com/cluster-formation.html

 * https://rabbitmq.com/monitoring.html


General Options

The following options are accepted by most or all commands.

short            | long          | description
-----------------|---------------|--------------------------------
-?               | --help        | displays command help
-n <node>        | --node <node> | connect to node <node>
-l               | --longnames   | use long host names
-t               | --timeout <n> | for commands that support it, operation timeout in seconds
-q               | --quiet       | suppress informational messages
-s               | --silent      | suppress informational messages
                                 | and table header row
-p               | --vhost       | for commands that are scoped to a virtual host,
                 |               | virtual host to use
                 | --formatter   | alternative result formatter to use
                                 | if supported: json, pretty_table, table, csv.
                                   not all commands support all (or any) alternative formatters.

答案 1 :(得分:1)

自己弄清楚。您可以使用选项--formatter jsonrabbitmq documentation中找不到它!

sudo rabbitmqctl cluster_status --formatter json
sudo rabbitmqctl cluster_status --formatter json | jq .running_nodes

要对此进行解析并在bash脚本中使用:

running_nodes=($(egrep -o '[a-z0-9@-]+' <<< $(sudo rabbitmqctl cluster_status --formatter json | jq .running_nodes)))