ha-handler/lib/ha_handler/web/controller.ex

35 lines
754 B
Elixir
Raw Normal View History

defmodule HAHandler.Web.Controller do
import Plug.Conn
2022-02-19 10:18:05 +01:00
alias HAHandler.{HAProxy, PGSQL}
@template_dir "lib/ha_handler/web/templates"
@index_template EEx.compile_file(
Path.join(@template_dir, "index.html.eex")
)
defp render(conn, template, assigns) do
{body, _binding} = Code.eval_quoted(template, assigns)
conn
|> put_resp_content_type("text/html")
|> send_resp(200, body)
end
def index(conn) do
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost)
stats = HAProxy.get_stats()
assigns = [
haproxy_stats: stats,
2022-02-19 10:18:05 +01:00
pgsql_status: PGSQL.status(),
hostname: hostname,
otp_app: HAHandler.otp_app(),
version: HAHandler.version(),
env: HAHandler.env()
]
render(conn, @index_template, assigns)
end
end