MiniCheck

MiniCheck provides a simple Rack application for adding simple health checks to your app. The JSON output is similar to the one provided by the Metrics Java library. It was started at Workshare ltd. as an easy way of providing monitoring to our Rack based applications.

Gem Version Build Status

Quick Start

Install the gem with the usual gem install mini_check. Build a new Rack app and register some checks

MyHealthCheck = MiniCheck::RackApp.new(path: '/healthcheck')
MyHealthCheck.register('health.redis_client'){ MyApp.redis_client.connected? }
MyHealthCheck.register('health.db_connection'){ MyApp.db_connection.fetch('show tables').to_a }

Mount it in your config.ru:

use MyHealthCheck
run MyApp

If you now visit http://localhost:XXXX/healthcheck you should get something like:

{
  "health.db_connection": {
    "healthy": true,
    "time": 0.111403303
  },
  "health.redis_client": {
    "healthy": true,
    "time": 4.41e-05
  }
}

The registered lambdas should do any of the following things:

  • Return true if the check was successful.
  • Return false if not.
  • Raise an exception which will be understood as not healthy. Find an example of the output below:
{
  "health.db_connection": {
    "healthy": false,
    "error": {
      "message": "Mysql2::Error: MySQL server has gone away",
      "stack": [
        "/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/adapters/mysql2.rb:77:in `query'",
        "/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/adapters/mysql2.rb:77:in `block in _execute'",
        "/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/database/logging.rb:37:in `log_yield'",
        "..."
      ],
      "time": 4.61e-05
    }
  },
  "health.redis_client": {
    "healthy": true,
    "time": 1.23e-04
  }
}

The http status code will be 200 if all checks are healthy and 500 otherwise.

Version

MyVersionCheck = MiniCheck::VersionRackApp.new(name: 'Cards', path: '/admin/version', build_file: './config/build.yml').tap do |app|
    app.metadata["Whatever Here"] = "Bla Bla"
    ...
end

The build_file can be a YML or a plain text file. It needs to have pairs key-values.

If you now visit http://localhost:XXXX/admin/version.json you should get something like:

{
  "Application Name": "Cards",
  "Whatever Here": "Bla Bla"
}

If you now visit http://localhost:XXXX/admin/version you should get something like:

  Application Name=Cards
  Whatever Here=Bla Bla

Maintaining

Here is a good tutorial on this: Developing a RubyGem using Bundler.

License

Released under the MIT License. See the LICENSE file for further details.