web: do not error when proxy is unreachable

This commit is contained in:
Timothée Floure 2022-02-21 09:31:24 +01:00
parent c8620db157
commit 7a7fcd8e31
Signed by: tfloure
GPG key ID: 4502C902C00A1E12
2 changed files with 14 additions and 4 deletions

View file

@ -74,7 +74,19 @@ defmodule HAHandler.HAProxy do
Executes and parse the output of the `show stats` HAProxy command, returning
a list of Maps.
"""
def get_stats() do
def get_stats(opts \\ [])
def get_stats([hide_error: true]) do
case get_stats() do
{:error, _err} ->
%{
"Frontend" => %{},
"Backend" => %{},
"Server" => %{}
}
stats -> stats
end
end
def get_stats(_opts) do
case execute("show stat json") do
{:ok, raw} ->
case Poison.decode(raw) do

View file

@ -19,10 +19,8 @@ defmodule HAHandler.Web.Controller do
def index(conn) do
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost)
stats = HAProxy.get_stats()
assigns = [
haproxy_stats: stats,
haproxy_stats: HAProxy.get_stats([hide_error: true]),
pgsql_status: PGSQL.status(),
hostname: hostname,
otp_app: HAHandler.otp_app(),