Include Health October 29, 2008
Posted by reidmix in Example, Plugins & Gems, Rails.Tags: big brother, check_health, monitoring, nagios, sa, sysadmin
1 comment so far
I created a little plugin to make it easier to offer health check URLs in all our applications called Health. These URLs are a necessity for our SysAdmins to hook into Big Brother or Nagios. These monitoring systems systematically poll an application at this URL to check the status of the application.
To get started, install the health plugin and include it in your Application controller:
class ApplicationController < ActionController::Base include Health end
That’s it. You should be able to navigate to http://localhost:3000/check_heath. Health sets up the named route ‘check_health’ and by default it will check the connection of the database by running a “select 1” SQL statement. If all goes well you should see “SERVERUP”. If there’s a problem with the query you will see “DBDOWN” or an 500 error depending on the level of problem. You can turn off the DB checking (our SysAdmins wanted it):
ApplicationController < ActionController::Base include Health health_check :with_db => false end
One more trick, it does is handle any additional / custom checks that you may require. Pass a block, Proc, or a symbol that represents the name of the method to the health_check directive:
ApplicationController < ActionController::Base
include Health
health_check do |controller|
controller.has_donut? || "no donut"
end
end
In this case, assuming the controller has a method called has_donut? which does not return false or nil, you will see the “SERVERUP” message, otherwise you will see what was last evaluated in a message like “PROCDOWN no donut”
And you can mix and match all three types of blocks, Procs, and symbols — more examples are in the README.
Adding vi keybindings to irb, script/console, and mysql October 19, 2008
Posted by John Dewey in Rails, Ruby.7 comments
I loves me my vi, and sun keyboard mappings (although it drives people crazy when they peer on my macbook).
Add the following on OS X 10.5:
john@emopop:~> cat .editrc bind -v
This will work for OS X 10.4 and other operating systems:
john@emopop:~> cat .inputrc set editing-mode vi
Hyphenated XML tags in Builder October 13, 2008
Posted by John Dewey in ActiveRecord, Example, Rails, Ruby.3 comments
I typically use to_xml when building a shallow representation of my model in XML. It becomes hella difficult to maintain the format of my XML when nesting numerous levels deep. Sometimes you gotta use a Builder.
If you would like your tags to be hyphenated (like the to_xml default), here is a nice trick:
xml.__send__('hyphenated-tag-name'.to_sym) do
xml.tag "data"
end
Coverage Nagging October 10, 2008
Posted by John Dewey in Code, Command Line, Example, RSpec, Rails.add a comment
I like to keep an eye on my coverage every so often. I run the following in my applications root, for occasional coverage reminders.
while : ; do rake spec:rcov ; open coverage/index.html; sleep 3600 ; done