KomachiHeartbeat
🚅Vital monitoring Elixir Web application.🚄
This respects Rails’s KomachiHeartbeat.
Usage
Mount KomachiHeartbeat at any path. We mount it for example at /ops
below.
In Plug app. example
defmodule Example.Router do
use Plug.Router
plug(:match)
plug(:dispatch)
forward("/ops", to: KomachiHeartbeat)
end
In Phoenix app. example
defmodule ExampleWeb.Router do
use ExampleWeb, :router
forward("/ops", KomachiHeartbeat)
end
KomachiHeartbeat provides 2 endpoints.
GET /MOUNT_PATH/heartbeat
: Monitor the server is OK. Response200 "ok"
or503 "error"
.GET /MOUNT_PATH/stats
: Monitor the server statistics. Response200 JSON
or503 JSON
.
Extend KomachiHeartbeat
You can extend KomachiHeartbeat to write vital plugins. Vital plugins should implement KomachiHeartbeat.Vital
.
defmodule ExampleVital do
@behaviour KomachiHeartbeat.Vital
def stats, do: {:ok, 42}
def vital, do: :ok
end
Add this at config.
# config.exs
config :komachi_heartbeat, vitals: [ExampleVital]
Now GET /MOUNT_PATH/heartbeat
calls ExampleVital.vital/0
& response ok
.
GET /MOUNT_PATH/stats
calls ExampleVital.stats/0
& response {"Elixir.ExampleVital": 42}
.
Installation
Add :komachi_heartbeat
at mix.exs
.
def deps do
[
{:komachi_heartbeat, "~> 0.1"}
]
end