Ops
This gem provides standardized support for obtaining version and heartbeat information from Sinatra or Rails-based web applications.
Typical usage:
/ops/version - displays version info as HTML
/ops/version.json - displays version info as JSON
/ops/heartbeat - returns 'OK' if the app is alive
This gem replaces the now-deprecated ops_routes.
Installation
For Rails 3 apps:
Add the gem to your project's Gemfile:
gem 'ops'Add the following to application.rb:
Ops.setup do |config| config.file_root = Rails.root config.environment = Rails.env endmount the gem in routes.rb:
mount Ops.new, :at => "/ops"
For Sinatra apps:
Add the gem to your project's Gemfile:
gem 'ops'Add the following to config.ru:
require 'ops' #... Ops.setup do |config| config.file_root = File.dirname __FILE__ config.environment = ENV['RACK_ENV'] end run Rack::URLMap.new \ "/" => YourAppClass, "/ops" => Ops.new# Implementation within rack cascade: run Rack::Cascade.new([ NewHomeGuide, ListingSearch::App, Ops.rack_app('/ops') ])
Adding Custom Heartbeats
Additionally, you can specify custom heartbeat monitoring pages as follows:
Ops.add_heartbeat :mysql do
conn = ActiveRecord::Base.connection
migrations = conn.select_all("SELECT COUNT(1) FROM schema_migrations;")
conn.disconnect!
end
The mysql example shown above would be accessed at ops/heartbeat/mysql. The heartbeat page will return a 200 ‘OK’ as long as the provided block returns true. If an error is raised, the heartbeat does not exist, or the block returns a falsey value, a 500 will be returned instead.
