KomachiHeartbeat

๐Ÿš…Vital monitoring Elixir Web application.๐Ÿš„

Hex.pm Build Status Coverage 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