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.