diff --git a/lib/towerops_web/telemetry.ex b/lib/towerops_web/telemetry.ex index bc8eb05a..da65428c 100644 --- a/lib/towerops_web/telemetry.ex +++ b/lib/towerops_web/telemetry.ex @@ -143,29 +143,33 @@ defmodule ToweropsWeb.Telemetry do queues = ["default", "discovery", "polling", "monitoring", "maintenance"] for queue <- queues do - {:ok, size} = Exq.Api.queue_size(Exq, queue) + case Exq.Api.queue_size(Exq, queue) do + {:ok, size} -> + :telemetry.execute( + [:towerops, :exq, :queue, :size], + %{value: size}, + %{queue: queue} + ) - :telemetry.execute( - [:towerops, :exq, :queue, :size], - %{value: size}, - %{queue: queue} - ) + _error -> + :ok + end end - {:ok, processes} = Exq.Api.processes(Exq) - {:ok, busy} = Exq.Api.busy(Exq) + with {:ok, processes} <- Exq.Api.processes(Exq), + {:ok, busy} <- Exq.Api.busy(Exq) do + :telemetry.execute( + [:towerops, :exq, :processes, :busy], + %{value: length(busy)}, + %{} + ) - :telemetry.execute( - [:towerops, :exq, :processes, :busy], - %{value: length(busy)}, - %{} - ) - - :telemetry.execute( - [:towerops, :exq, :processes, :total], - %{value: length(processes)}, - %{} - ) + :telemetry.execute( + [:towerops, :exq, :processes, :total], + %{value: length(processes)}, + %{} + ) + end :ok catch @@ -193,40 +197,42 @@ defmodule ToweropsWeb.Telemetry do redis_config = Application.get_env(:towerops, :redis, []) host = Keyword.get(redis_config, :host, "localhost") port = Keyword.get(redis_config, :port, 6379) - {:ok, conn} = Redix.start_link(host: host, port: port) - {:ok, info} = Redix.command(conn, ["INFO", "stats"]) - {:ok, memory_info} = Redix.command(conn, ["INFO", "memory"]) - {:ok, clients_info} = Redix.command(conn, ["INFO", "clients"]) - stats = parse_redis_info(info) - memory_stats = parse_redis_info(memory_info) - client_stats = parse_redis_info(clients_info) - if total_commands = stats["total_commands_processed"] do - :telemetry.execute( - [:towerops, :redis, :commands_processed], - %{value: String.to_integer(total_commands)}, - %{} - ) + with {:ok, conn} <- Redix.start_link(host: host, port: port), + {:ok, info} <- Redix.command(conn, ["INFO", "stats"]), + {:ok, memory_info} <- Redix.command(conn, ["INFO", "memory"]), + {:ok, clients_info} <- Redix.command(conn, ["INFO", "clients"]) do + stats = parse_redis_info(info) + memory_stats = parse_redis_info(memory_info) + client_stats = parse_redis_info(clients_info) + + if total_commands = stats["total_commands_processed"] do + :telemetry.execute( + [:towerops, :redis, :commands_processed], + %{value: String.to_integer(total_commands)}, + %{} + ) + end + + if used_memory = memory_stats["used_memory"] do + :telemetry.execute( + [:towerops, :redis, :used_memory], + %{value: String.to_integer(used_memory)}, + %{} + ) + end + + if connected_clients = client_stats["connected_clients"] do + :telemetry.execute( + [:towerops, :redis, :connected_clients], + %{value: String.to_integer(connected_clients)}, + %{} + ) + end + + Redix.stop(conn) + :ok end - - if used_memory = memory_stats["used_memory"] do - :telemetry.execute( - [:towerops, :redis, :used_memory], - %{value: String.to_integer(used_memory)}, - %{} - ) - end - - if connected_clients = client_stats["connected_clients"] do - :telemetry.execute( - [:towerops, :redis, :connected_clients], - %{value: String.to_integer(connected_clients)}, - %{} - ) - end - - Redix.stop(conn) - :ok rescue _ -> :ok end