🚅Vital monitoring Elixir Web application.🚄
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
examples
lib
test
.credo.exs
.formatter.exs
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
coveralls.json
mix.exs
mix.lock

README.md

KomachiHeartbeat

🚅Vital monitoring Elixir Web application.🚄

Hex.pm Build Status

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. Response 200 "ok" or 503 "error".
  • GET /MOUNT_PATH/stats : Monitor the server statistics. Response 200 JSON or 503 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. In Plug app :

forward("/ops", to: KomachiHeartbeat, init_opts: [vitals: []])

In Phoenix app :

forward("/ops", KomachiHeartbeat, vitals: [])

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.3"}
  ]
end