web: do not error when proxy is unreachable
This commit is contained in:
parent
c8620db157
commit
7a7fcd8e31
2 changed files with 14 additions and 4 deletions
|
@ -74,7 +74,19 @@ defmodule HAHandler.HAProxy do
|
||||||
Executes and parse the output of the `show stats` HAProxy command, returning
|
Executes and parse the output of the `show stats` HAProxy command, returning
|
||||||
a list of Maps.
|
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
|
case execute("show stat json") do
|
||||||
{:ok, raw} ->
|
{:ok, raw} ->
|
||||||
case Poison.decode(raw) do
|
case Poison.decode(raw) do
|
||||||
|
|
|
@ -19,10 +19,8 @@ defmodule HAHandler.Web.Controller do
|
||||||
def index(conn) do
|
def index(conn) do
|
||||||
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost)
|
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost)
|
||||||
|
|
||||||
stats = HAProxy.get_stats()
|
|
||||||
|
|
||||||
assigns = [
|
assigns = [
|
||||||
haproxy_stats: stats,
|
haproxy_stats: HAProxy.get_stats([hide_error: true]),
|
||||||
pgsql_status: PGSQL.status(),
|
pgsql_status: PGSQL.status(),
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
otp_app: HAHandler.otp_app(),
|
otp_app: HAHandler.otp_app(),
|
||||||
|
|
Loading…
Reference in a new issue