defmodule ElixirDashboardWeb.PerformanceLive.Endpoints do @moduledoc """ Demo app wrapper - delegates to the library LiveView. """ use ElixirDashboardWeb, :live_view alias ElixirDashboard.PerformanceMonitor.Store @impl true def mount(_params, _session, socket) do if connected?(socket) do # Refresh data every 5 seconds :timer.send_interval(5000, self(), :refresh) end endpoints = Store.get_slow_endpoints() {:ok, assign(socket, :endpoints, endpoints)} end @impl true def handle_info(:refresh, socket) do endpoints = Store.get_slow_endpoints() {:noreply, assign(socket, :endpoints, endpoints)} end @impl true def handle_event("clear", _params, socket) do Store.clear_all() {:noreply, assign(socket, :endpoints, [])} end @impl true def render(assigns) do ~H"""

Slow API Endpoints

Showing the 100 slowest endpoints recorded since the server started (threshold: 100ms).

No slow endpoints recorded yet. Start making requests to see data.

0} class="bg-white shadow-md rounded-lg overflow-hidden">
Duration (ms) Endpoint Path Recorded At
<%= endpoint.duration_ms %>ms <%= endpoint.path %> <%= format_timestamp(endpoint.timestamp) %>
""" end defp format_timestamp(milli) do milli |> DateTime.from_unix!(:millisecond) |> Calendar.strftime("%Y-%m-%d %H:%M:%S") end defp duration_color(ms) when ms > 1000, do: "text-red-600" defp duration_color(ms) when ms > 500, do: "text-orange-600" defp duration_color(ms) when ms > 200, do: "text-yellow-600" defp duration_color(_), do: "text-green-600" end