defmodule FLAMEDashboard do @moduledoc """ FLAME statistics visualization for the Phoenix LiveDashboard. """ use Phoenix.LiveDashboard.PageBuilder defstruct pools: [] @impl true def init(pools) do {:ok, %FLAMEDashboard{pools: pools}, []} end @impl true def menu_link(_session, _caps) do {:ok, "FLAME"} end @impl true def mount(_params, %{pools: pools}, socket) do Process.send_after(self(), :update_stats, 1_000) {:ok, assign(socket, pools: pools, pool_states: get_pool_states(pools), selected_pool: List.first(pools) )} end @impl true def render(assigns) do ~H""" <%= if @pools == [] do %> No FLAME pools configured. You need to manually list FLAME pools when adding this page to the LiveDashboard. <% else %> <.live_nav_bar id="pools_nav" page={@page}> <:item :for={{name, pool_state} <- Enum.zip(@pools, @pool_states)} name={name |> to_string()} label={"Pool #{name}"} method="redirect" > <.pool_stats name={name} pool={pool_state} /> <% end %> """ end @impl true def handle_info(:update_stats, socket) do Process.send_after(self(), :update_stats, 1_000) pool_states = get_pool_states(socket.assigns.pools) # Update graphs for each pool for {name, state} <- Enum.zip(socket.assigns.pools, pool_states) do # Update total runners graph send_data_to_chart( "pool-runners-#{name}", [{nil, state.runner_count, System.system_time(:microsecond)}] ) # Update active calls graph for each runner for {pid, stats} <- state.runners do send_data_to_chart( "runner-calls-#{name}-#{inspect(pid)}", [{nil, stats.count, System.system_time(:microsecond)}] ) end end {:noreply, assign(socket, pool_states: pool_states)} end defp pool_stats(assigns) do ~H"""