summaryrefslogtreecommitdiff
path: root/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics')
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/alarms_command.ex4
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_alarms_command.ex3
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_local_alarms_command.ex2
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex9
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_listener_command.ex2
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_protocol_listener_command.ex2
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/listeners_command.ex2
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex199
8 files changed, 8 insertions, 215 deletions
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/alarms_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/alarms_command.ex
index f0ead11314..4b973732df 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/alarms_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/alarms_command.ex
@@ -21,9 +21,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.AlarmsCommand do
errors. This command is not meant to be used in health checks.
"""
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
-
- import RabbitMQ.CLI.Diagnostics.Helpers,
- only: [alarm_lines: 2, local_alarms: 2, clusterwide_alarms: 2]
+ import RabbitMQ.CLI.Core.Alarms
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_alarms_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_alarms_command.ex
index ce80ee8ca1..2b71ca7df7 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_alarms_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_alarms_command.ex
@@ -22,8 +22,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckAlarmsCommand do
This command is meant to be used in health checks.
"""
- import RabbitMQ.CLI.Diagnostics.Helpers,
- only: [alarm_lines: 2, local_alarms: 2, clusterwide_alarms: 2]
+ import RabbitMQ.CLI.Core.Alarms
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_local_alarms_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_local_alarms_command.ex
index 0f94a7fb9b..6bdfcd198d 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_local_alarms_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_local_alarms_command.ex
@@ -20,7 +20,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckLocalAlarmsCommand do
This command is meant to be used in health checks.
"""
- import RabbitMQ.CLI.Diagnostics.Helpers, only: [alarm_lines: 2, local_alarms: 2]
+ import RabbitMQ.CLI.Core.Alarms
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex
index 7dd62bc6cb..90a429baa3 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_connectivity_command.ex
@@ -23,14 +23,9 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckPortConnectivityCommand do
"""
import RabbitMQ.CLI.Diagnostics.Helpers,
- only: [
- listeners_on: 2,
- listener_lines: 1,
- listener_map: 1,
- listener_maps: 1,
- check_listener_connectivity: 3
- ]
+ only: [check_listener_connectivity: 3]
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
+ import RabbitMQ.CLI.Core.Listeners
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_listener_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_listener_command.ex
index 04316271d9..6dd15b91e2 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_listener_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_port_listener_command.ex
@@ -21,7 +21,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckPortListenerCommand do
This command is meant to be used in health checks.
"""
- import RabbitMQ.CLI.Diagnostics.Helpers, only: [listeners_on: 2, listener_maps: 1]
+ import RabbitMQ.CLI.Core.Listeners, only: [listeners_on: 2, listener_maps: 1]
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_protocol_listener_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_protocol_listener_command.ex
index 5fd7a4a034..70dc4d2d2a 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_protocol_listener_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/check_protocol_listener_command.ex
@@ -21,7 +21,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckProtocolListenerCommand do
This command is meant to be used in health checks.
"""
- import RabbitMQ.CLI.Diagnostics.Helpers,
+ import RabbitMQ.CLI.Core.Listeners,
only: [listeners_on: 2, listener_maps: 1, normalize_protocol: 1]
@behaviour RabbitMQ.CLI.CommandBehaviour
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/listeners_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/listeners_command.ex
index 5661ece910..a3ae42c3c1 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/listeners_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/commands/listeners_command.ex
@@ -21,7 +21,7 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.ListenersCommand do
errors. This command is not meant to be used in health checks.
"""
- import RabbitMQ.CLI.Diagnostics.Helpers,
+ import RabbitMQ.CLI.Core.Listeners,
only: [listeners_on: 2, listener_lines: 1, listener_maps: 1, listener_rows: 1]
import RabbitMQ.CLI.Core.Platform, only: [line_separator: 0]
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex
index 6023f32b00..168d5a272c 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/diagnostics/diagnostics_helpers.ex
@@ -14,67 +14,6 @@
## Copyright (c) 2007-2019 Pivotal Software, Inc. All rights reserved.
defmodule RabbitMQ.CLI.Diagnostics.Helpers do
- import Record, only: [defrecord: 2, extract: 2]
- import RabbitCommon.Records
- import Rabbitmq.Atom.Coerce
-
- #
- # Listeners
- #
-
- defrecord :hostent, extract(:hostent, from_lib: "kernel/include/inet.hrl")
-
- def listeners_on(listeners, target_node) do
- Enum.filter(listeners, fn listener(node: node) ->
- node == target_node
- end)
- end
-
- def listener_lines(listeners) do
- listeners
- |> listener_maps
- |> Enum.map(fn %{interface: interface, port: port, protocol: protocol} ->
- "Interface: #{interface}, port: #{port}, protocol: #{protocol}, purpose: #{
- protocol_label(to_atom(protocol))
- }"
- end)
- end
-
- def listener_map(listener) do
- # Listener options are left out intentionally: they can contain deeply nested values
- # that are impossible to serialise to JSON.
- #
- # Management plugin/HTTP API had its fair share of bugs because of that
- # and now filters out a lot of options. Raw listener data can be seen in
- # rabbitmq-diagnostics status.
- listener(node: node, protocol: protocol, ip_address: interface, port: port) = listener
-
- %{
- node: node,
- protocol: protocol,
- interface: :inet.ntoa(interface) |> to_string |> maybe_enquote_interface,
- port: port,
- purpose: protocol_label(to_atom(protocol))
- }
- end
-
- def listener_maps(listeners) do
- Enum.map(listeners, &listener_map/1)
- end
-
- def listener_rows(listeners) do
- for listener(node: node, protocol: protocol, ip_address: interface, port: port) <- listeners do
- # Listener options are left out intentionally, see above
- [
- node: node,
- protocol: protocol,
- interface: :inet.ntoa(interface) |> to_string |> maybe_enquote_interface,
- port: port,
- purpose: protocol_label(to_atom(protocol))
- ]
- end
- end
-
def check_port_connectivity(port, node_name, timeout) do
hostname = Regex.replace(~r/^(.+)@/, to_string(node_name), "") |> to_charlist
@@ -98,142 +37,4 @@ defmodule RabbitMQ.CLI.Diagnostics.Helpers do
def check_listener_connectivity(%{port: port}, node_name, timeout) do
check_port_connectivity(port, node_name, timeout)
end
-
- def protocol_label(:amqp), do: "AMQP 0-9-1 and AMQP 1.0"
- def protocol_label(:'amqp/ssl'), do: "AMQP 0-9-1 and AMQP 1.0 over TLS"
- def protocol_label(:mqtt), do: "MQTT"
- def protocol_label(:'mqtt/ssl'), do: "MQTT over TLS"
- def protocol_label(:stomp), do: "STOMP"
- def protocol_label(:'stomp/ssl'), do: "STOMP over TLS"
- def protocol_label(:http), do: "HTTP API"
- def protocol_label(:https), do: "HTTP API over TLS (HTTPS)"
- def protocol_label(:"http/web-mqtt"), do: "MQTT over WebSockets"
- def protocol_label(:"https/web-mqtt"), do: "MQTT over WebSockets and TLS (HTTPS)"
- def protocol_label(:"http/web-stomp"), do: "STOMP over WebSockets"
- def protocol_label(:"https/web-stomp"), do: "STOMP over WebSockets and TLS (HTTPS)"
- def protocol_label(:clustering), do: "inter-node and CLI tool communication"
- def protocol_label(other), do: to_string(other)
-
- def normalize_protocol(proto) do
- val = proto |> to_string |> String.downcase()
-
- case val do
- "amqp091" -> "amqp"
- "amqp0.9.1" -> "amqp"
- "amqp0-9-1" -> "amqp"
- "amqp0_9_1" -> "amqp"
- "amqp10" -> "amqp"
- "amqp1.0" -> "amqp"
- "amqp1-0" -> "amqp"
- "amqp1_0" -> "amqp"
- "amqps" -> "amqp/ssl"
- "mqtt3.1" -> "mqtt"
- "mqtt3.1.1" -> "mqtt"
- "mqtt31" -> "mqtt"
- "mqtt311" -> "mqtt"
- "mqtt3_1" -> "mqtt"
- "mqtt3_1_1" -> "mqtt"
- "mqtts" -> "mqtt/ssl"
- "mqtt+tls" -> "mqtt/ssl"
- "mqtt+ssl" -> "mqtt/ssl"
- "stomp1.0" -> "stomp"
- "stomp1.1" -> "stomp"
- "stomp1.2" -> "stomp"
- "stomp10" -> "stomp"
- "stomp11" -> "stomp"
- "stomp12" -> "stomp"
- "stomp1_0" -> "stomp"
- "stomp1_1" -> "stomp"
- "stomp1_2" -> "stomp"
- "stomps" -> "stomp/ssl"
- "stomp+tls" -> "stomp/ssl"
- "stomp+ssl" -> "stomp/ssl"
- "https" -> "https"
- "http1" -> "http"
- "http1.1" -> "http"
- "http_api" -> "http"
- "management" -> "http"
- "management_ui" -> "http"
- "ui" -> "http"
- "cli" -> "clustering"
- "distribution" -> "clustering"
- "webmqtt" -> "http/web-mqtt"
- "web-mqtt" -> "http/web-mqtt"
- "web_mqtt" -> "http/web-mqtt"
- "webmqtt/tls" -> "https/web-mqtt"
- "web-mqtt/tls" -> "https/web-mqtt"
- "webmqtt/ssl" -> "https/web-mqtt"
- "web-mqtt/ssl" -> "https/web-mqtt"
- "webmqtt+tls" -> "https/web-mqtt"
- "web-mqtt+tls" -> "https/web-mqtt"
- "webmqtt+ssl" -> "https/web-mqtt"
- "web-mqtt+ssl" -> "https/web-mqtt"
- "webstomp" -> "http/web-stomp"
- "web-stomp" -> "http/web-stomp"
- "web_stomp" -> "http/web-stomp"
- "webstomp/tls" -> "https/web-stomp"
- "web-stomp/tls" -> "https/web-stomp"
- "webstomp/ssl" -> "https/web-stomp"
- "web-stomp/ssl" -> "https/web-stomp"
- "webstomp+tls" -> "https/web-stomp"
- "web-stomp+tls" -> "https/web-stomp"
- "webstomp+ssl" -> "https/web-stomp"
- "web-stomp+ssl" -> "https/web-stomp"
- _ -> val
- end
- end
-
- #
- # Alarms
- #
-
- def alarm_lines(alarms, node_name) do
- Enum.reduce(alarms, [], fn
- :file_descriptor_limit, acc ->
- ["File descriptor limit alarm on node #{node_name}" | acc]
-
- {{:resource_limit, :memory, alarmed_node_name}, _}, acc ->
- ["Memory alarm on node #{alarmed_node_name}" | acc]
-
- {{:resource_limit, :disk, alarmed_node_name}, _}, acc ->
- ["Free disk space alarm on node #{alarmed_node_name}" | acc]
- end)
- |> Enum.reverse()
- end
-
- def local_alarms(alarms, node_name) do
- Enum.filter(
- alarms,
- fn
- # local by definition
- :file_descriptor_limit ->
- true
-
- {{:resource_limit, _, a_node}, _} ->
- node_name == a_node
- end
- )
- end
-
- def clusterwide_alarms(alarms, node_name) do
- alarms
- |> Enum.reject(fn x -> x == :file_descriptor_limit end)
- |> Enum.filter(fn {{:resource_limit, _, a_node}, _} ->
- a_node != node_name
- end)
- end
-
- #
- # Implementation
- #
-
- defp maybe_enquote_interface(value) do
- # This simplistic way of distinguishing IPv6 addresses,
- # networks address ranges, etc actually works better
- # for the kind of values we can get here than :inet functions. MK.
- case value =~ ~r/:/ do
- true -> "[#{value}]"
- false -> value
- end
- end
end