Code Monkey home page Code Monkey logo

phoenix_live_dashboard's Introduction

Phoenix LiveDashboard

Online Documentation.

LiveDashboard provides real-time performance monitoring and debugging tools for Phoenix developers. It provides the following modules:

  • Home - See general information about the system

  • OS Data - See general information about OS, such as CPU, Memory and Disk usage

  • Metrics - See how your application performs under different conditions by visualizing :telemetry events with real-time charts

  • Request logging - See everything that was logged for certain requests

  • Applications - See, filter, and search applications in the current node

  • Processes - See, filter, and search processes in the current node

  • Ports - See, filter, and search ports (responsible for I/O) in the current node

  • Sockets - See, filter, and search sockets (responsible for tcp/udp) in the current node

  • ETS - See, filter, and search ETS tables (in-memory storage) in the current node

  • Ecto Stats - Shows index, table, and general usage about the underlying Ecto Repo storage

The dashboard also works across nodes. If your nodes are connected via Distributed Erlang, then you can access information from node B while accessing the dashboard on node A.

screenshot

Installation

To start using LiveDashboard, you will need three steps:

  1. Add the phoenix_live_dashboard dependency
  2. Configure LiveView
  3. Add dashboard access

1. Add the phoenix_live_dashboard dependency

Add the following to your mix.exs and run mix deps.get:

def deps do
  [
    {:phoenix_live_dashboard, "~> 0.1"}
  ]
end

2. Configure LiveView

The LiveDashboard is built on top of LiveView. If LiveView is already installed in your app, feel free to skip this section.

If you plan to use LiveView in your application in the future, we recommend you to follow the official installation instructions. This guide only covers the minimum steps necessary for the LiveDashboard itself to run.

First, update your endpoint's configuration to include a signing salt. You can generate a signing salt by running mix phx.gen.secret 32 (note Phoenix v1.5+ apps already have this configuration):

# config/config.exs
config :my_app, MyAppWeb.Endpoint,
  live_view: [signing_salt: "SECRET_SALT"]

Then add the Phoenix.LiveView.Socket declaration to your endpoint:

socket "/live", Phoenix.LiveView.Socket

And you are good to go!

3. Add dashboard access for development-only usage

Once installed, update your router's configuration to forward requests to a LiveDashboard with a unique name of your choosing:

# lib/my_app_web/router.ex
use MyAppWeb, :router
import Phoenix.LiveDashboard.Router

...

if Mix.env() == :dev do
  scope "/" do
    pipe_through :browser
    live_dashboard "/dashboard"
  end
end

This is all. Run mix phx.server and access the "/dashboard" to configure the necessary modules.

Extra: Add dashboard access on all environments (including production)

If you want to use the LiveDashboard in production, you should put it behind some authentication and allow only admins to access it. If your application does not have an admins-only section yet, you can use Plug.BasicAuth to set up some basic authentication as long as you are also using SSL (which you should anyway):

# lib/my_app_web/router.ex
use MyAppWeb, :router
import Plug.BasicAuth
import Phoenix.LiveDashboard.Router

...

pipeline :admins_only do
  plug :basic_auth, username: "admin", password: "a very special secret"
end

scope "/" do
  pipe_through [:browser, :admins_only]
  live_dashboard "/dashboard"
end

If you are running your application behind a proxy or a webserver, you also have to make sure they are configured for allowing WebSocket upgrades. For example, here is an article on how to configure Nginx with Phoenix and WebSockets.

Finally, you will also want to configure your config/prod.exs and use your domain name under the check_origin configuration:

check_origin: ["//myapp.com"]

Then you should be good to go!

Contributing

For those planning to contribute to this project, you can run a dev version of the dashboard with the following commands:

$ mix setup
$ mix dev

Alternatively, run iex -S mix dev if you also want a shell.

Assets are minimized by default. If you'd like to skip assets optimization and run webpack in development mode you can do it using the NODE_ENV enviroment variable:

$ NODE_ENV=development mix dev

or

$ NODE_ENV=development iex -S mix dev

License

MIT License. Copyright (c) 2019 Michael Crumm, Chris McCord, José Valim.

phoenix_live_dashboard's People

Contributors

josevalim avatar mcrumm avatar archdragon avatar alexcastano avatar chrismccord avatar wojtekmach avatar dkuku avatar dependabot[bot] avatar lostkobrakai avatar pawurb avatar rupurt avatar davydog187 avatar maennchen avatar aaronrenner avatar aerosol avatar adrianomitre avatar albertored avatar andrew0914 avatar bemesa21 avatar bamorim avatar achempion avatar bglusman avatar cblavier avatar danieldent avatar dmcbrayer avatar glv avatar shamanime avatar moogle19 avatar drozdzynski avatar mhanberg avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.