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.2.0"}
]
end
- Create your checks
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{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 the following JSON schema
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Health check list",
"type": "array",
"items": {
"title": "Check",
"type": "object",
"properties": {
"name": {
"description": "The name of this check, for example: 'redis', or 'postgres'",
"type": "string"
},
"healthy": {
"description": "If the check was successful or not",
"type" : "boolean"
},
"time": {
"description": "How long the check took to run",
"type": "integer"
},
"error": {
"description": "The error reason in case the check fails",
"type": "string"
}
}
}
}