diff --git a/server/lib/server_web/live/overview_live.ex b/server/lib/server_web/live/overview_live.ex new file mode 100644 index 0000000..1732f82 --- /dev/null +++ b/server/lib/server_web/live/overview_live.ex @@ -0,0 +1,130 @@ +defmodule ServerWeb.OverviewLive do + use ServerWeb, :live_view + + alias Server.{Hosts, Metrics, Status} + + @impl true + def mount(_params, _session, socket) do + if connected?(socket), do: Phoenix.PubSub.subscribe(Server.PubSub, "metrics") + {:ok, assign(socket, :hosts, load_hosts())} + end + + @impl true + def handle_info({:metric_inserted, _host_id, _interval}, socket) do + {:noreply, assign(socket, :hosts, load_hosts())} + end + + defp load_hosts do + for host <- Hosts.list_all() do + sample = Metrics.latest_sample(host.id, "fast") + payload = sample && sample.payload + %{host: host, sample: sample, status: Status.compute(host.status, payload)} + end + end + + @impl true + def render(assigns) do + ~H""" +
+ No hosts registered yet. Add one via /admin/hosts.
+