No commit activity in last 3 years
No release in over 3 years
Health check for Rails apps checking things like active record, redis, and AWS.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.17
~> 5.0
~> 10.0

Runtime

 Project Readme

server_health_check-rails

This gem provides a rails engine that automatically hooks in with the server_health_check gem. It will add a /health and /health/:id endpoint which will return a JSON string of the results of either all configured health checks, or just the one provided.

Installation

Add this line to your application's Gemfile:

gem "server_health_check-rails"

And then execute:

$ bundle

Then configure your checks with the gem using the built in server_health_check checks, or your own custom checks:

# config/initializers/health_checks.rb
ServerHealthCheckRails.check_active_record!
ServerHealthCheckRails.check_redis!(host: "someredis.host", port: 1234)
ServerHealthCheckRails.check_aws_s3!("aws-bucket-to-check")
ServerHealthCheckRails.check_aws_creds!
ServerHealthCheckRails.check "custom_check" do
  # Do some work here, then return true if it succeeded or false if not
  # (exceptions will be caught by the server_health_check gem and the message
  # will be reported as the status).
  true
end

And indicate the path for the server_health_check-rack gem to listen against (it defaults to /health):

# config/initializers/health_checks.rb
ServerHealthCheckRails::Config.path = "/check/health"

You can also indicate a custom logger for the server_health_check gem to utilize (it defaults to not overriding the logger):

# config/initializers/health_checks.rb
ServerHealthCheckRails::Config.logger = MyCustomLogger.new

Usage

You can now use your health checks in some automated service to monitor your app with your custom checks.

You may use the endpoint for all checks at /health, which might result in something like the following, though without the formatting:

{
    "status": {
        "active_record": "OK",
        "redis": "OK",
        "aws_s3": "Failed",
        "aws_creds": "OK",
        "custom_check": "OK"
    }
}

If you want to just check a single check, you can just use that in the url like /health/custom_check:

{
    "status": {
        "custom_check": "OK"
    }
}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test 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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/on-site/server_health_check-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.