ex_health v0.2.0 ExHealth View Source
ExHealth is a simple extensible health check utility that monitors your applications.
By itself, ExHealth is a supervised GenServer that periodically performs a set of checks, but you can easily configure your it to serve JSON responses that look like:
{
last_check:"2018-09-18T06:43:53.773719Z",
result:{
check_results:[
[
"Database",
"ok"
],
[
"PhoenixExampleWeb_Endpoint",
"ok"
]
],
msg:"healthy"
}
}
Getting Started
Configuration for ExHealth must be present the Application environment. This
can be done by updating the :ex_health
values in your config/config.exs
:
config :ex_health,
module: MyApplication.HealthChecks,
interval_ms: 1000
Then you must define a module MyApplication.HealthChecks
with some checks:
defmodule MyApplication.HealthChecks do
process_check(MyApplication.CacheServer)
test "Redis" do
MyRedis.ping() # This should return :ok | {:error, "Message"}
end
end
Integrating with Phoenix
To integrate with Phoenix
or any other web framework, you can take advantage of ExHealth.Plug
which handles serving a JSON response for you.
See ExHealth.Plug
for instructions.
Link to this section Summary
Functions
Defines a healthcheck function.
Defines a healthcheck function for a given process.
Starts the application with empty state
Callback implementation for Application.start/2
.
Synchronously fetches the latest status from ExHealth.HealthServer
Stops the Application
Link to this section Functions
Defines a healthcheck function.
Takes the following arguments:
name
- a string for the name of the health checkblock
- block that returns:ok | true | {:error, "Reason"}
Examples:
defmodule MyApp.HealthChecks do
health_check("Database") do
MyDB.ping() # This should return :ok | true | {:error, "Reason"}
end
end
Defines a healthcheck function for a given process.
Returns :ok
if the process has one of the following statuses:
:running
:waiting
See Process.info/1 for more information about process status.
Examples:
defmodule MyApp.HealthChecks do
process_check(MyApp.SomeImportantService)
end
Starts the application with empty state
Callback implementation for Application.start/2
.
Synchronously fetches the latest status from ExHealth.HealthServer
Examples:
iex(1)> ExHealth.status()
%ExHealth.Status{
checks: [
%ExHealth.Check{
mfa: {ExHealth.SelfCheck, :hc__ExHealth_HealthServer, []},
name: "ExHealth_HealthServer"
}
],
interval_ms: 15000,
last_check: nil,
result: %{check_results: [], msg: :pending}
}
Stops the Application