forked from phoenixframework/phoenix_live_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Configuring Ecto repository stats | ||
|
||
This guide covers how to configure the LiveDashboard to stats from your underlying database. At the moment, these stats can only be show for Ecto repositories running on `Ecto.Adapters.Postgres`. | ||
|
||
## Installing Ecto Stats | ||
|
||
To enable the "Ecto Stats" functionality in your dashboard, you will need to do the three steps below: | ||
|
||
1. Add the ecto_psql_extras dependency | ||
2. Configure the dashboard | ||
3. (optional) Install custom extensions | ||
|
||
### Add the `ecto_psql_extras` dependency | ||
|
||
In your `mix.exs`, add the following to your `deps`: | ||
|
||
```elixir | ||
{:ecto_psql_extras, "~> 0.2"}, | ||
``` | ||
|
||
### Configure the dashboard | ||
|
||
The next step is to configure the dashboard. Go to the `live_dashboard` call in your router and list all of your repositories: | ||
|
||
```elixir | ||
live_dashboard "/dashboard", ecto_repos: [MyApp.Repo] | ||
``` | ||
|
||
You want to list all repositories that connect to distinct databases. For example, if you have both `MyApp.Repo` and `MyApp.RepoAnother` but they connect to the same database, there is no benefit in listing both. Remember only Ecto repositories running on `Ecto.Adapters.Postgres` are currently supported. | ||
|
||
If you want to disable the "Ecto Stats" option altogether, set `ecto_repos: []`. | ||
|
||
### Install custom extensions | ||
|
||
Once the repository page is enabled, some of the queries (Calls and Outliers) require the [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension installed. If you wish to access said functionality, you must install the extension first, otherwise an error will be shown. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule Phoenix.LiveDashboard.EctoStatsPageTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Phoenix.ConnTest | ||
import Phoenix.LiveViewTest | ||
@endpoint Phoenix.LiveDashboardTest.Endpoint | ||
|
||
alias Phoenix.LiveDashboard.EctoStatsPage | ||
alias Phoenix.LiveDashboardTest.Repo | ||
@link "https://hexdocs.pm/phoenix_live_dashboard/ecto_stats.html" | ||
|
||
test "menu_link/2" do | ||
assert {:disabled, "Ecto Stats", @link} = EctoStatsPage.menu_link(%{repo: nil}, %{}) | ||
assert :skip = EctoStatsPage.menu_link(%{repo: Repo}, %{processes: []}) | ||
|
||
assert {:ok, "Phoenix LiveDashboardTest Repo Stats"} = | ||
EctoStatsPage.menu_link(%{repo: Repo}, %{processes: [Repo]}) | ||
end | ||
|
||
test "renders" do | ||
{:ok, live, _} = live(build_conn(), ecto_stats_path()) | ||
rendered = render(live) | ||
assert rendered =~ "All locks" | ||
assert rendered =~ "Extensions" | ||
assert rendered =~ "Transactionid" | ||
assert rendered =~ "Granted" | ||
end | ||
|
||
test "navs" do | ||
{:ok, live, _} = live(build_conn(), ecto_stats_path(:extensions)) | ||
rendered = render(live) | ||
assert rendered =~ "Default version" | ||
assert rendered =~ "Installed version" | ||
assert rendered =~ "fuzzystrmatch" | ||
assert rendered =~ "hstore" | ||
end | ||
|
||
test "search" do | ||
{:ok, live, _} = live(build_conn(), ecto_stats_path(:extensions, "hstore")) | ||
rendered = render(live) | ||
assert rendered =~ "Default version" | ||
assert rendered =~ "Installed version" | ||
refute rendered =~ "fuzzystrmatch" | ||
assert rendered =~ "hstore" | ||
end | ||
|
||
defp ecto_stats_path() do | ||
"/dashboard/nonode%40nohost/phoenix_live_dashboard_test_repo_info" | ||
end | ||
|
||
defp ecto_stats_path(nav) do | ||
"#{ecto_stats_path()}?nav=#{nav}" | ||
end | ||
|
||
defp ecto_stats_path(nav, search) do | ||
"#{ecto_stats_path()}?nav=#{nav}&search=#{search}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
System.put_env("PHX_DASHBOARD_TEST", "PHX_DASHBOARD_ENV_VALUE") | ||
|
||
pg_url = System.get_env("PG_URL") || "postgres:[email protected]" | ||
|
||
Application.put_env(:phoenix_live_dashboard, Phoenix.LiveDashboardTest.Repo, | ||
url: "ecto://#{pg_url}/phx_dashboard_test" | ||
) | ||
|
||
defmodule Phoenix.LiveDashboardTest.Repo do | ||
use Ecto.Repo, otp_app: :phoenix_live_dashboard, adapter: Ecto.Adapters.Postgres | ||
end | ||
|
||
_ = Ecto.Adapters.Postgres.storage_up(Phoenix.LiveDashboardTest.Repo.config()) | ||
|
||
Application.put_env(:phoenix_live_dashboard, Phoenix.LiveDashboardTest.Endpoint, | ||
url: [host: "localhost", port: 4000], | ||
secret_key_base: "Hu4qQN3iKzTV4fJxhorPQlA/osH9fAMtbtjVS58PFgfw3ja5Z18Q/WSNR9wP4OfW", | ||
|
@@ -42,7 +54,8 @@ defmodule Phoenix.LiveDashboardTest.Router do | |
pipe_through :browser | ||
|
||
live_dashboard "/dashboard", | ||
metrics: Phoenix.LiveDashboardTest.Telemetry | ||
metrics: Phoenix.LiveDashboardTest.Telemetry, | ||
ecto_repos: [Phoenix.LiveDashboardTest.Repo] | ||
|
||
live_dashboard "/config", | ||
live_socket_path: "/custom/live", | ||
|
@@ -86,6 +99,7 @@ Application.ensure_all_started(:os_mon) | |
|
||
Supervisor.start_link( | ||
[ | ||
Phoenix.LiveDashboardTest.Repo, | ||
{Phoenix.PubSub, name: Phoenix.LiveDashboardTest.PubSub, adapter: Phoenix.PubSub.PG2}, | ||
Phoenix.LiveDashboardTest.Endpoint | ||
], | ||
|