This project is no longer maintained. Feel free to fork it if you want to maintain your own version!
Goodoo is a simple, robust, and highly customizable health check solution written in Elixir.
Add :goodoo to your Mix project.
defdeps()do[{:goodoo,"~> 0.1"}]endFull documentation can be found on Hex.
Goodoo works by periodically checking the availablity of the sub-systems based on your configuration, and provides a few APIs to retrieves the report.
To start using Goodoo, create a module:
defmoduleMyHealthCheckdouseGoodooendAfter that, add the module with the desired checkers to the supervisor tree. Please see the "Checkers" section for all currently supported checkers.
checkers=%{"primary"=>{Goodoo.Checker.EctoSQL,repo: MyPrimaryRepo},"replica"=>{Goodoo.Checker.EctoSQL,repo: MyReplicaRepo},"persistent_cache"=>{Goodoo.Checker.Redix,connection: MyCache}}children=[MyPrimaryRepo,MyReplicaRepo,MyCache,...,{MyHealthCheck,checkers},MyEndpoint]Supervisor.start_link(children,strategy: :one_for_one,name: MyApp)Allez, hop! You are "goodoo" to go. To retrieve the health check report,
list_health_states/1 and get_health_state/2 can be used.
Usually you might want to expose an HTTP endpoint for some uptime checkers e.g. AWS ALB, Pingdom, etc. It can be easily done with Plug or Phoenix controller.
defmoduleMyRouterdousePlug.Routerplug:matchplug:dispatchget"/health"dohealthy?=Enum.all?(Goodoo.list_health_states(MyHealthCheck),fn{_checker_name,{state,_last_checked_at}}->state==:healthyend)ifhealthy?dosend_resp(conn,200,"Everything is 200 OK")elsesend_resp(conn,503,"Something is on fire!")endendget"/health/:checker_name"docaseGoodoo.get_health_state(MyHealthCheck,checker_name)donil->send_resp(conn,404,"Not found"){state,_last_checked_at}->ifstate==:healthydosend_resp(conn,200,"Service is doing fine")elsesend_resp(conn,503,"Service is on fire")endendendenddefmoduleHealthControllerdouseMyWeb,:controllerdefindex(conn,_params)dohealthy?=Enum.all?(Goodoo.list_health_states(MyHealthCheck),fn{_checker_name,{state,_last_checked_at}}->state==:healthyend)conn=put_status(conn,200)ifhealthy?dotext(conn,"Everything is 200 OK")elsetext(conn,"Something is on fire!")endendendGoodoo is the local name of Murray Cod in Australia. Here is a picture of it.
Make sure you have Elixir installed.
- Fork the project.
- Run
mix deps.getto fetch dependencies. - Run
mix test.
If you have any ideas or suggestions, feel free to submit an issue or a pull request.
MIT
