Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Latest commit

 

History

History
111 lines (85 loc) · 3.51 KB

README.md

File metadata and controls

111 lines (85 loc) · 3.51 KB

Build Status

SupervisorHealth

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

Installation

The package can be installed as following:

  1. Add supervisor_health to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:supervisor_health, git: "https://github.com/meltwater/supervisor_health", tag: "0.1.1"}]
end
```
  1. Ensure supervisor_health is started before your application:
```elixir
def application do
  [applications: [:supervisor_health]]
end
```

Usage

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

Responses

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.

Example

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"
}

Contact

For questions, bug reports and feature requests do not hesitate to create an issue on github.

License

See License.