The Rack middleware to provide health check endpoints.
Installation
Add this line to your application's Gemfile:
gem 'liveness'Usage
Configuration the Liveness to add dependency.
Liveness.config do |c|
c.add :postgres, timeout: 10
endNamed Dependency
Liveness.config do |c|
c.add :postgres, name: :primary_db, timeout: 10
c.add :postgres, name: :read_replica, timeout: 10
endAccess Protected
Liveness.config do |c|
c.token = 'unm@tnh8ugq-WAR-myr'
endTo access the status endpoint should add ?token=unm@tnh8ugq-WAR-myr params to access it.
Liveness.config do |c|
c.ip_whitelist = ['192.168.0.0/24']
endTo access the status endpoint should called from 127.0.0.1 or ::1 or under 192.168.0.0/24.
Customize Connector
Liveness.config do |c|
c.add :redis, timeout: 10 do
Redis.new(url: 'redis://example:6379/15')
end
endRails Application
Mount the Liveness::Status to config/routes.rb
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
mount Liveness::Status => '/health'
endDependency Providers
| Name | Description |
|---|---|
postgres |
The PostgreSQL adapter which for ActiveRecord::Base
|
mysql |
The MySQL adapter which for ActiveRecord::Base
|
redis |
Test Redis via redis-rb gem via #ping method |
Roadmap
- Status Endpoint
- Metrics Endpoint (for single dependency)
- Dependency Provider
- PostgreSQL
- ActiveRecord
- Sequel
- MySQL
- ActiveRecord
- Sequel
- Redis
- HTTP Endpoint
- PostgreSQL
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/liveness. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Code of Conduct
Everyone interacting in the Liveness project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.