= Operations Middleware
This library provides a piece of Rack middleware for monitoring application status. To include it in a rails application, you need to provide the following minimum configuration:
config.gem 'operations_middleware'
require 'operations_middleware'
config.middleware.use OperationsMiddleware do |ops|
ops.file_root = RAILS_ROOT
end
== Version Page
This will provide a page at /ops/version which shows, in development mode, the current git branch and last commit SHA. In all other modes, it shows the same information, but taken from the contents of VERSION and REVISION files in the file_root directory. If you are deploying with Capistrano, the REVISION file will be created for you. If you want the VERSION file, you'll need to add that to your project or your Capistrano scripts.
== Heartbeat Page
It also provides a simple page at /ops/heartbeat which returns a 200 'OK' as long as the application is running.
The application name is taken from the enclosing folder of the file_root option. If that folder is a Capistrano timestamped release, it goes up 2 additional levels for the name, stripping .com from the end of the directory if necessary. If this logic does not get the correct application name, it can be set manually in the configuration block:
ops.app_name = 'Custom Application Name'
=== Adding Custom Heartbeats
Additionally, you can specify custom heartbeat monitoring pages as follows:
ops.heartbeat[:mysql] = lambda 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 can be set to any object which responds to call. The heartbeat page will return a 200 'OK' as long as the provided lambda does not raise an error. If an error is raised, a 500 will be returned instead.
== Note on Patches/Pull Requests
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a
future version unintentionally.
- Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
== Copyright
Copyright (c) 2010 PRIMEDIA Inc. See LICENSE for details.