0.01
No commit activity in last 3 years
No release in over 3 years
Simple heartbeat monitoring target for Rails apps with database connection testing, customizable output, HTTP status code, and Airbrake notification.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 3.12
~> 2.11

Runtime

~> 3.1
>= 3.1.0
 Project Readme

HasHeartbeat¶ ↑

Controller with target for heartbeat monitoring with customizable status body text, HTTP status codes, and optional integration with Airbrake notifier.

Install¶ ↑

HasHeartbeat is intended for use in Rails applications. To add a heartbeat endpoint to your application, add HasHeartbeat to your Gemfile:

gem "has_heartbeat"

The gem has dependencies on versions of Rails from 3.1 and upward, as well as a dependency on the Airbrake notification gem, which will be added to your dependency set.

Usage¶ ↑

By adding the HasHeartbeat gem to your project, your project will have a “/heartbeat” endpoint added to your routes. You can add this URL to your heartbeat/monitoring service of choice or strike it directly to verify that your application is alive and well.

The heartbeat action responds with one of two possible responses. In the case of an app’s successfully beating heart:

HTTP Status:   200 OK
Response Body: Application Heart Beating OK
Logger Output: Application Heart Beating OK

And the case arising from internal issue or error:

HTTP Status:   500 Server Error
Response Body: 500 Internet Server Error: Application Heart Palpitations
Logger Output: 500 Internet Server Error: Application Heart Palpitations

Configure your monitoring service to check against status codes and/or response body text to properly triage responses.

Options¶ ↑

By default, HasHeartbeat simply responds with success or failure and can be used for up/down verification. You can customize its behavior as follows:

Check Database Up/Down¶ ↑

You can ask the heartbeat to also check that your application is connected to your database. To do so, configure like so:

# config/initializers/heartbeat.rb
HasHeartbeat.configure do |config|
  config.check_db!
end

HasHeartbeat will check against the database by default. You can turn this off, if you really don’t need it:

config.check_db!(false)

Custom Responses¶ ↑

By default, the heartbeat action will render text responses with the HTTP service codes as described above. You may wish to customize the success or failure messages or the failure status code. To do so, get back into your initializer:

# config/initializers/heartbeat.rb
HasHeartbeat.configure do |config|
  config.ok_text = "This is my OK output"
  config.fail_text = "This response text is output on DB connect issues"
  config.fail_status = 404      # Change from 500 to something more specific
end

External Notifications¶ ↑

Further, if you’d like HasHeartbeat to notify an external service when your application is experiencing a database connection error, you can ask it to piggy-back off an existing Airbrake configuration you are using. To do so, add the following to a config/initializer:

HasHeartbeat.configure do |config|
  config.use_airbrake!
end

By specifying use_airbrake!, HasHeartbeat will use any existing Airbrake configuration and send a notification to your Airbrake service in the following form:

{
  :error_class   => "Heartbeat Failure",                    # <= Generic title
  :error_message => "Heartbeat Failure: #{e.message}",      # <= Raised error message
  :parameters    => params                                  # <= Request parameters
}

If you don’t wish to use Airbrake, simply leave out the call to use_airbrake! and all is well.

Copyright 2014 Awexome Labs, LLC awexomelabs.com facebook.com/AwexomeLabs twitter.com/awexomelabs