Skip to content

Commit a8670b4

Browse files
committed
cli status output
1 parent 99666c2 commit a8670b4

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
3333
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
3434

3535
def run([], %{node: node_name, timeout: timeout} = opts) do
36-
status =
36+
status0 =
3737
case :rabbit_misc.rpc_call(node_name, :rabbit_db_cluster, :cli_cluster_status, []) do
3838
{:badrpc, {:EXIT, {:undef, _}}} ->
3939
:rabbit_misc.rpc_call(node_name, :rabbit_mnesia, :status, [])
@@ -45,11 +45,13 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
4545
status
4646
end
4747

48-
case status do
48+
case status0 do
4949
{:badrpc, _} = err ->
5050
err
5151

52-
status ->
52+
status0 ->
53+
tags = cluster_tags(node_name, timeout)
54+
status = status0 ++ [{:cluster_tags, tags}]
5355
case :rabbit_misc.rpc_call(node_name, :rabbit_nodes, :list_running, []) do
5456
{:badrpc, _} = err ->
5557
err
@@ -122,7 +124,6 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
122124

123125
def output(result, %{node: node_name}) when is_list(result) do
124126
m = result_map(result)
125-
126127
total_cores = Enum.reduce(m[:cpu_cores], 0, fn {_, val}, acc -> acc + val end)
127128

128129
cluster_name_section = [
@@ -131,6 +132,15 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
131132
"Total CPU cores available cluster-wide: #{total_cores}"
132133
]
133134

135+
cluster_tag_section =
136+
[
137+
"\n#{bright("Cluster Tags")}\n"
138+
] ++
139+
case m[:cluster_tags] do
140+
[] -> ["(none)"]
141+
tags -> cluster_tag_lines(tags)
142+
end
143+
134144
disk_nodes_section =
135145
[
136146
"\n#{bright("Disk Nodes")}\n"
@@ -210,6 +220,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
210220

211221
lines =
212222
cluster_name_section ++
223+
cluster_tag_section ++
213224
disk_nodes_section ++
214225
ram_nodes_section ++
215226
running_nodes_section ++
@@ -260,6 +271,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
260271
# {rabbit@warp10,[{resource_limit,memory,rabbit@warp10}]}]}]
261272
%{
262273
cluster_name: Keyword.get(result, :cluster_name),
274+
cluster_tags: result |> Keyword.get(:cluster_tags, []),
263275
disk_nodes: result |> Keyword.get(:nodes, []) |> Keyword.get(:disc, []),
264276
ram_nodes: result |> Keyword.get(:nodes, []) |> Keyword.get(:ram, []),
265277
running_nodes: result |> Keyword.get(:running_nodes, []) |> Enum.map(&to_string/1),
@@ -383,6 +395,18 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
383395
{node, result}
384396
end
385397

398+
defp cluster_tags(node, timeout) do
399+
case :rabbit_misc.rpc_call(
400+
node,
401+
:application,
402+
:get_env,
403+
[:rabbit, :cluster_tags],
404+
timeout) do
405+
{:ok, tags} -> tags
406+
_ -> []
407+
end
408+
end
409+
386410
defp node_lines(nodes) do
387411
Enum.map(nodes, &to_string/1) |> Enum.sort()
388412
end
@@ -413,4 +437,10 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
413437
defp maintenance_lines(mapping) do
414438
Enum.map(mapping, fn {node, status} -> "Node: #{node}, status: #{status}" end)
415439
end
440+
441+
defp cluster_tag_lines(mapping) do
442+
Enum.map(mapping, fn {key, value} ->
443+
"#{key}: #{value}"
444+
end)
445+
end
416446
end

0 commit comments

Comments
 (0)