PlugCheckup provides a Plug for adding simple health checks to your app
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib Format files Mar 17, 2018
priv/schemas Fix nullable fields in the response Jan 1, 2018
test
.credo.exs Fix credo issues Dec 4, 2017
.formatter.exs Format files Mar 17, 2018
.gitignore Start with Readme and mix information to submit to hex Dec 1, 2017
.iex.exs Format files Mar 17, 2018
.tool-versions
.travis.yml Add coveralls (#3) Dec 7, 2017
README.md Add demo section Mar 17, 2018
mix.exs Release new version Mar 17, 2018
mix.lock Add integration tests Jan 1, 2018

README.md

Build Status Coverage Status || Hex version Hex downloads

PlugCheckup

PlugCheckup provides a Plug for adding simple health checks to your app. The JSON output is similar to the one provided by the MiniCheck Ruby library. It was started at solarisBank as an easy way of providing monitoring to our Plug based applications.

Usage

  • Add the package to "mix.exs"
defp deps do
  [
    {:plug_checkup, "~> 0.3.0"}
  ]
end
defmodule MyHealthChecks do
  def check_db do
    :ok
  end

  def check_redis do
    :ok
  end
end
  • Forward your health path to PlugCheckup in your Plug Router
checks = [
  %PlugCheckup.Check{name: "DB", module: MyHealthChecks, function: :check_db},
  %PlugCheckup.Check{name: "Redis", module: MyHealthChecks, function: :check_redis}
]

forward(
  "/health",
  to: PlugCheckup,
  init_opts: PlugCheckup.Options.new(checks: checks)
)

If you're working with Phoenix, you need to change the syntax slightly to accomodate Phoenix.Router.forward/4:

checks = [
  %PlugCheckup.Check{name: "DB", module: MyHealthChecks, function: :check_db},
  %PlugCheckup.Check{name: "Redis", module: MyHealthChecks, function: :check_redis}
]

forward("/health", PlugCheckup, PlugCheckup.Options.new(checks: checks))

The Checks

A check is a function with arity zero, which should return either :ok or {:error, term}. In case the check raises an exception or times out, that will be mapped to an {:error, reason} result.

Response

PlugCheckup should return either 200 or 500 statuses, Content-Type header "application/json", and the body should respect this JSON schema

Demo

Check .iex.exs for a demo of plug_checkup in a Plug.Router. The demo can be run as following.

git clone https://github.com/ggpasqualino/plug_checkup
cd plug_checkup
mix deps.get
iex -S mix

Open your browse either on http://localhost:4000/selfhealth or http://localhost:4000/dependencyhealth