This is the Supervisor Health module for Elixir applications. This can be used to provide a health endpoint in a web-based application or API.
Table of Contents generated with DocToc
The package can be installed as following:
- Add
supervisor_health
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:supervisor_health, git: "https://github.com/meltwater/supervisor_health", tag: "0.1.1"}]
end
```
- Ensure
supervisor_health
is started before your application:
```elixir
def application do
[applications: [:supervisor_health]]
end
```
In an application, e.g. a Plug API, you could use SupervisorHealth like this:
get "/_health" do
case SupervisorHealth.health(MyApp.Supervisor) do
{:ok, resp} -> send_resp(conn, 200, resp)
{:error, resp} -> send_resp(conn, 500, resp)
end
end
In general, the library will produce following 2 responses:
{:ok, response}
if everything is OK{:error, response}
if any error occurred
The response contains information on any Supervisor child processes.
Using curl on the Plug-based API mentioned above, a possible response could be:
$ curl http://localhost:4200/_health | jq .
{
"internalProcesses": {
"{:ranch_listener_sup, MyApp.Http.Router.HTTP}": {
"status": "waiting",
"stack_size": 9,
"reductions": 175,
"current_function": [
"gen_server",
"loop",
6
]
},
"MyApp.Database": {
"status": "waiting",
"stack_size": 9,
"reductions": 1136,
"current_function": [
"gen_server",
"loop",
6
]
}
},
"health": "ok"
}
For questions, bug reports and feature requests do not hesitate to create an issue on github.
See License.