A simple way to see what's up, dawg (and what's not.)
Define a list of checks and create a controller that renders the results. Ping the controller with the monitoring tool of your choice, perhaps setting a 503 response when one of the checks fails.
Some options can be set:
UpDawg.configure do |config| config.success_text = 'OK' end
Checks are defined with a simple DSL:
monitor = Updawg.monitor do check 'MySQL' do # Will raise an exception if the connection is unavailable resulting in a failed check ActiveRecord::Base.connection.execute('SELECT 1 FROM DUAL') end check 'Some threshold' do result ||= error('Threshold exceeded y') if threshold_value > y result ||= warning('Threshold exceeded x') if threshold_value > x result end # alternatively, use warning!/error!/pass! to break out of the check immediately check 'Something else' do warning!('Something kind of bad happened') if threshold_value > x error! ('Something really bad happened') if threshold_value > y pass!('Everything is just fine') end # Specify a threshold check for captured purchases in the last 24 hours threshold 'Captured Purchases (24 hours)', :warn_under => 10, :error_under => 1 do Purchase.captured_at_after(24.hours.ago) end # Specify a "sweet spot threshold check" to alert when a business metric goes out of normal range threshold 'Transactions (24 hours)', :warn_under => 100, :error_under => 1, :warn_over => 1000, :error_over => 2000 do Transaction.created_at_after(24.hours.ago) end # Specify a std deviation check to alert when a value is outside of 2 std deviations from the mean # The block should yield an array of values, the last of which is considered the sample. # Supports options: # scale_factor - multiple of the std_dev to user (default: 2) # smoothing - whether to ignore outliers in the dataset (default: true) deviation 'Hourly Transaction Value' do Transaction.group('hour').order('hour ASC') # will report if the last hour of data is our of range end end results = monitor.perform results.success? => true if no checks error results.warning? => true if no checks error and at least one has a warning results.error? => true if at least one check fails
results.to_html <table class="updawg monitor"> <tr class="check error"> <td class="name">MySQL</td> <td class="message">ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax</td> <td class="status">ERROR</td> </tr> <tr class="check pass"> <td class="name">Some threshold</td> <td class="message"></td> <td class="status">PASS</td> </tr> </table>
Use Updawg to easily script nagios checks in Ruby. Create your checks as usual and call #nagios_report! on the result. Updawg will print a status line formatted for nagios and exit with an appropriate status code.
Note on Patches/Pull Requests
Fork the project.
Create a feature branch and make your feature addition or bug fix there.
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.
Matt Griffin github.com/betamatt (email@example.com)
Copyright © 2010 Viximo, Inc. See LICENSE for details.