How to Monitor Your Elixir Phoenix Application with Vigilmon
Elixir and Phoenix are known for fault tolerance — but "let it crash" still requires knowing when something crashed. Vigilmon provides external uptime monitoring for Phoenix applications.
Create a Health Check Endpoint
Add a health route to your Phoenix router:
# lib/my_app_web/router.ex
scope "/", MyAppWeb do
pipe_through :api
get "/health", HealthController, :check
end
Create the controller:
# lib/my_app_web/controllers/health_controller.ex
defmodule MyAppWeb.HealthController do
use MyAppWeb, :controller
def check(conn, _params) do
db_status = check_database()
overall = if db_status == :ok, do: :ok, else: :degraded
http_status = if overall == :ok, do: 200, else: 503
conn
|> put_status(http_status)
|> json(%{status: overall, database: db_status})
end
defp check_database do
case MyApp.Repo.query("SELECT 1") do
{:ok, _} -> :ok
{:error, _} -> :error
end
end
end
Plug-Based Health Check (Lightweight Option)
For minimal overhead, use a Plug directly:
defmodule MyApp.HealthPlug do
import Plug.Conn
def init(opts), do: opts
def call(%Plug.Conn{request_path: "/health"} = conn, _opts) do
conn
|> put_resp_content_type("application/json")
|> send_resp(200, ~s({"status":"ok"}))
|> halt()
end
def call(conn, _opts), do: conn
end
Add it to your endpoint before the Router:
# lib/my_app_web/endpoint.ex
plug MyApp.HealthPlug
plug MyAppWeb.Router
Add to Vigilmon
- Sign up at vigilmon.online
- Add monitor:
https://your-phoenix-app.com/health - Set 1-minute interval
- Add Slack or email alert
Monitoring OTP Supervisors
Elixir's OTP restarts crashed processes automatically — but if a supervisor hits its max restart intensity, it stops. Add supervisor health to your endpoint:
defp check_supervisor do
if Process.whereis(MyApp.Supervisor) != nil, do: :ok, else: :error
end
Vigilmon will alert you if the health check returns 503 — catching OTP-level failures before users notice.
Free Tier
Get started free at vigilmon.online — 5 monitors, 1-minute intervals, email and Slack alerts.
Top comments (0)