Healthier
Short description and motivation.
Usage
How to use my plugin.
Installation
Add this line to your application's Gemfile:
gem "healthier"
And then execute:
$ bundle
Or install it yourself as:
$ gem install healthier
Installer:
rails generate healthier:config
This will generate these two files:
- config/healthier.yml
---
healthier:
depends_on:
# Uncomment accordingly
# - name: 'postgresql'
# config: {}
# - name: 'mongodb'
# config: {}
# - name: 'redis'
# config: {}
# - name: 'rabbitmq'
# config: {}
NOTE: In future, config above will accept a hash each service's configuration
- config/initializers/healthier.rb
Healthier.setup do |config|
# If you don't specify auth_mechanism, then it defaults to http_basic.
# Currently, only http_basic and bearer_token are supported
config.auth_mechanism = 'bearer_token'
config.depends_on = config.healthier.call
end
In your application routes.rb file(namespace according to your need):
mount Healthier::Engine => '/healthier'
ENVs for basic authentication:
HEALTHIER_USERNAME: 'demouser'
HEALTHIER_PASSWORD: 'demouser@2023'
ENVs for Bearer token authentication:
BEARER_TOKEN: 'e66cfadb3ce37a714fdf3df237dcfded9ed9a0f9ccb09e6a744d731e9214bae6fac7bf6d27cab3969702b7aa54c81fe1cff1842ac03b3d5f1a918e1f5061dcb80b80363976ae5f3b916c793fdfa5283ce5f387286152d62e2dcaa5c8c0f857ceb2cda045'
However, if you want to leave the API open, just set:
Healthier.auth_mechanism = :none
Health Check Endpoints
Healthier provides three distinct health check endpoints for monitoring your application:
1. Ping Endpoint (GET /healthier/ping)
Returns detailed health status of all configured services.
Response: JSON object with service health statuses
{
"postgresql": {
"status": "success",
"message": "PostgreSQL service is healthy"
},
"redis": {
"status": "success",
"message": "Redis service is healthy"
}
}
2. Live Endpoint (GET /healthier/live)
Basic liveness check that verifies if the application is running.
Response: Boolean value
true
3. Ready Endpoint (GET /healthier/ready)
Readiness check that verifies if all configured services are healthy and the application is ready to serve requests.
Response: Boolean value
true
Example Usage
# Ping - detailed service health
curl http://localhost:3000/healthier/ping
# Live - basic liveness check
curl http://localhost:3000/healthier/live
# Ready - service readiness check
curl http://localhost:3000/healthier/ready
Example Curl with authentication:
curl -H "Bearer your_token_here" -H "Content-Type: application/json" 'http://localhost:3000/healthier/ping'
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.