has_heartbeat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,12 @@
1
+ = HasHeartbeat Change Log
2
+
3
+ This document details notable changes between versions in the gem.
4
+
5
+ === v0.1 (this version)
6
+
7
+ * Initial gem build
8
+ * HeartbeatController with index action
9
+ * Database model search test
10
+ * HTTP Status Code appropriate response (200, 500)
11
+ * Airbrake notification for heartbeat failures
12
+
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ # AWEXOME LABS
2
+ # HasHeartbeat -- Gem dependencies
3
+
4
+ source "http://rubygems.org"
5
+
6
+ # Runtime dependencies:
7
+
8
+ # This gem adds functionality to Rails applications:
9
+ gem "rails", ">= 3.1.0"
10
+
11
+ # And requires Airbrake notification for some features:
12
+ gem "airbrake", "~> 3.1.4"
13
+
14
+
15
+ # Development dependencies:
16
+ group :development do
17
+ gem "bundler", "~> 1.1.0"
18
+ gem "jeweler", "~> 1.8.4"
19
+ gem "rdoc", "~> 3.12"
20
+ gem "rspec", ">= 2.11.0"
21
+ # gem "rspec-rails", ">= 2.11.0"
22
+ # gem "capybara", "~> 1.1.2"
23
+ # gem "combustion", "~> 0.3.2"
24
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.8)
18
+ activesupport (= 3.2.8)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.8)
21
+ activemodel (= 3.2.8)
22
+ activesupport (= 3.2.8)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.8)
26
+ activemodel (= 3.2.8)
27
+ activesupport (= 3.2.8)
28
+ activesupport (3.2.8)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ airbrake (3.1.4)
32
+ builder
33
+ girl_friday
34
+ arel (3.0.2)
35
+ builder (3.0.3)
36
+ connection_pool (0.9.2)
37
+ diff-lcs (1.1.3)
38
+ erubis (2.7.0)
39
+ girl_friday (0.10.0)
40
+ connection_pool (~> 0.9.0)
41
+ git (1.2.5)
42
+ hike (1.2.1)
43
+ i18n (0.6.1)
44
+ jeweler (1.8.4)
45
+ bundler (~> 1.0)
46
+ git (>= 1.2.5)
47
+ rake
48
+ rdoc
49
+ journey (1.0.4)
50
+ json (1.7.5)
51
+ mail (2.4.4)
52
+ i18n (>= 0.4.0)
53
+ mime-types (~> 1.16)
54
+ treetop (~> 1.4.8)
55
+ mime-types (1.19)
56
+ multi_json (1.3.6)
57
+ polyglot (0.3.3)
58
+ rack (1.4.1)
59
+ rack-cache (1.2)
60
+ rack (>= 0.4)
61
+ rack-ssl (1.3.2)
62
+ rack
63
+ rack-test (0.6.2)
64
+ rack (>= 1.0)
65
+ rails (3.2.8)
66
+ actionmailer (= 3.2.8)
67
+ actionpack (= 3.2.8)
68
+ activerecord (= 3.2.8)
69
+ activeresource (= 3.2.8)
70
+ activesupport (= 3.2.8)
71
+ bundler (~> 1.0)
72
+ railties (= 3.2.8)
73
+ railties (3.2.8)
74
+ actionpack (= 3.2.8)
75
+ activesupport (= 3.2.8)
76
+ rack-ssl (~> 1.3.2)
77
+ rake (>= 0.8.7)
78
+ rdoc (~> 3.4)
79
+ thor (>= 0.14.6, < 2.0)
80
+ rake (0.9.2.2)
81
+ rdoc (3.12)
82
+ json (~> 1.4)
83
+ rspec (2.11.0)
84
+ rspec-core (~> 2.11.0)
85
+ rspec-expectations (~> 2.11.0)
86
+ rspec-mocks (~> 2.11.0)
87
+ rspec-core (2.11.1)
88
+ rspec-expectations (2.11.3)
89
+ diff-lcs (~> 1.1.3)
90
+ rspec-mocks (2.11.2)
91
+ sprockets (2.1.3)
92
+ hike (~> 1.2)
93
+ rack (~> 1.0)
94
+ tilt (~> 1.1, != 1.3.0)
95
+ thor (0.16.0)
96
+ tilt (1.3.3)
97
+ treetop (1.4.10)
98
+ polyglot
99
+ polyglot (>= 0.3.1)
100
+ tzinfo (0.3.33)
101
+
102
+ PLATFORMS
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ airbrake (~> 3.1.4)
107
+ bundler (~> 1.1.0)
108
+ jeweler (~> 1.8.4)
109
+ rails (>= 3.1.0)
110
+ rdoc (~> 3.12)
111
+ rspec (>= 2.11.0)
data/README.rdoc ADDED
@@ -0,0 +1,85 @@
1
+ = HasHeartbeat
2
+
3
+ Controller with target for heartbeat monitoring with body, HTTP status code, and Airbrake
4
+ issue identification.
5
+
6
+
7
+ == Install
8
+
9
+ HasHeartbeat is intended for use in Rails applications. To add a heartbeat endpoint to your
10
+ application, add HasHeartbeat to your Gemfile:
11
+
12
+ gem "has_heartbeat"
13
+
14
+ The gem has dependencies on versions of Rails from 3.1 and upward, as well as a dependency
15
+ on the Airbrake notification gem, which will be added to your dependency set.
16
+
17
+
18
+ == Usage
19
+
20
+ By adding the HasHeartbeat gem to your project, your project will have a "/heartbeat" endpoint
21
+ added to your routes. You can add this URL to your heartbeat/monitring service of choice or
22
+ strike it directly to verify that your application is alive and well.
23
+
24
+ The heartbeat action responds with one of two possible responses. In the case of an app's
25
+ successfully beating heart:
26
+
27
+ HTTP Status: 200 OK
28
+ Response Body: Application Heart Beating OK
29
+
30
+ And the case arising from internal issue or error:
31
+
32
+ HTTP Status: 500 Server Error
33
+ Response Body: 500 Internet Server Error: Application Heart Palpitations
34
+
35
+ Configure your monitoring service to check against status codes and/or response body text to
36
+ properly triage responses.
37
+
38
+
39
+ == Options
40
+
41
+ By default, HasHeartbeat simply responds with success or failure and can be used for up/down
42
+ verification.
43
+
44
+ === Check Database Up/Down
45
+
46
+ You can ask the heartbeat action to also check against a model of your database to ensure that
47
+ your database is up and running by adding the following to a file in your config/initializers:
48
+
49
+ HasHeartbeat.configure do |config|
50
+ config.check_model = User
51
+ end
52
+
53
+ Specify any of your ActiveRecord models (in place of User) and the heartbeat will attempt to
54
+ load the first row from the corresponding table when it is struck.
55
+
56
+ === External Notifications
57
+
58
+ Further, if you'd like HasHeartbeat to notify an external service when your application is down
59
+ or experiencing an error, you can ask it to piggy-back off an existing Airbrake configuration
60
+ you are using. To do so, add the following to a config/initializer:
61
+
62
+ HasHeartbeat.configure do |config|
63
+ config.use_airbrake!
64
+ end
65
+
66
+ By specifying +use_airbrake!+, HasHeartbeat will use any existing Airbrake configuration and send
67
+ a notification to your Airbrake service in the following form:
68
+
69
+ {
70
+ :error_class => "Heartbeat Failure", # <= Generic title
71
+ :error_message => "Heartbeat Failure: #{e.message}", # <= Raised error message
72
+ :parameters => params # <= Request parameters
73
+ }
74
+
75
+ If you don't wish to use Airbrake, simply leave out the call to +use_airbrake!+ and all is well.
76
+
77
+
78
+
79
+ == Copyright
80
+
81
+ Copyright 2012 Awexome Labs, LLC
82
+ http://awexomelabs.com
83
+ http://facebook.com/AwexomeLabs
84
+ http://twitter.com/awexomelabs
85
+
data/ROADMAP.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ = HasHeartbeat Road Map
2
+
3
+
4
+ == v0.1
5
+
6
+ Expected release October 2012.
7
+
8
+ Initial features planned, pulled from previous Awexome Labs client
9
+ project components.
10
+
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require "rake"
13
+
14
+ require "jeweler"
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "has_heartbeat"
18
+ gem.homepage = "http://github.com/awexome/has_heartbeat"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Simple heartbeat monitoring target for Rails with body, HTTP status code, and Airbrake issue identification.}
21
+ gem.description = %Q{Simple heartbeat monitoring target for Rails with body, HTTP status code, and Airbrake issue identification.}
22
+ gem.email = "engineering@awexomelabs.com"
23
+ gem.authors = ["Awexome Labs"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require "rspec/core"
29
+ require "rspec/core/rake_task"
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ end
32
+
33
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :default => :spec
38
+
39
+ # require "rake/testtask"
40
+ # Rake::TestTask.new(:test) do |test|
41
+ # test.libs << "lib" << "test"
42
+ # test.pattern = "test/**/test_*.rb"
43
+ # test.verbose = true
44
+ # end
45
+
46
+ # require "rcov/rcovtask"
47
+ # Rcov::RcovTask.new do |test|
48
+ # test.libs << "test"
49
+ # test.pattern = "test/**/test_*.rb"
50
+ # test.verbose = true
51
+ # test.rcov_opts << "--exclude "gems/*""
52
+ # end
53
+
54
+ # task :default => :test
55
+
56
+ require "rdoc/task"
57
+ Rake::RDocTask.new do |rdoc|
58
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
59
+
60
+ rdoc.rdoc_dir = "rdoc"
61
+ rdoc.title = "DoesKeyValue #{version}"
62
+ rdoc.rdoc_files.include("README*")
63
+ rdoc.rdoc_files.include("lib/**/*.rb")
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,37 @@
1
+ # AWEXOME LABS
2
+ # HeartbeatController
3
+ #
4
+ # Useful endpoints for ping and availability services.
5
+ #
6
+
7
+ class HeartbeatController < ActionController::Base
8
+
9
+ def index
10
+ begin
11
+ if HasHeartbeat.configuration.check_model?
12
+ Rails.logger.info "Heartbeat checking database against model #{HasHeartbeat.configuration.check_model.to_s}"
13
+ HasHeartbeat.configuration.check_model.send(:first)
14
+ else
15
+ Rails.logger.info "Heartbeat not checking against database"
16
+ end
17
+ raise Exception.new("Funky error occurred in your systemz")
18
+ Rails.logger.info "Application Heart Beating OK"
19
+ render :text => "Application Heart Beating OK"
20
+ rescue Exception => e
21
+ Rails.logger.error "Heartbeat Error: #{e.message}"
22
+ if HasHeartbeat.configuration.use_airbrake?
23
+ Rails.logger.error "Heartbeat notifying Airbrake endpoint."
24
+ ::Airbrake.notify(
25
+ :error_class => "Heartbeat Failure",
26
+ :error_message => "Heartbeat Failure: #{e.message}",
27
+ :parameters => params
28
+ )
29
+ else
30
+ Rails.logger.error "Heartbeat not notifying Airbrake endpoint."
31
+ end
32
+ render :text => "500 Internet Server Error: Application Heart Palpitations", :status => 500
33
+ end
34
+ end
35
+
36
+ end
37
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # AWEXOME LABS
2
+ # HasHeartbeat - Routing the check for heartbeat
3
+
4
+ Rails.application.routes.draw do
5
+ get "heartbeat"=>"heartbeat#index"
6
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "has_heartbeat"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Awexome Labs"]
12
+ s.date = "2012-10-18"
13
+ s.description = "Simple heartbeat monitoring target for Rails with body, HTTP status code, and Airbrake issue identification."
14
+ s.email = "engineering@awexomelabs.com"
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "CHANGELOG.rdoc",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "README.rdoc",
23
+ "ROADMAP.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "app/controllers/heartbeat_controller.rb",
27
+ "config/routes.rb",
28
+ "has_heartbeat.gemspec",
29
+ "lib/has_heartbeat.rb",
30
+ "lib/has_heartbeat/configuration.rb"
31
+ ]
32
+ s.homepage = "http://github.com/awexome/has_heartbeat"
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = "1.8.17"
36
+ s.summary = "Simple heartbeat monitoring target for Rails with body, HTTP status code, and Airbrake issue identification."
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
43
+ s.add_runtime_dependency(%q<airbrake>, ["~> 3.1.4"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<rspec>, [">= 2.11.0"])
48
+ else
49
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
50
+ s.add_dependency(%q<airbrake>, ["~> 3.1.4"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<rspec>, [">= 2.11.0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rails>, [">= 3.1.0"])
58
+ s.add_dependency(%q<airbrake>, ["~> 3.1.4"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
+ s.add_dependency(%q<rspec>, [">= 2.11.0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,48 @@
1
+ # AWEXOME LABS
2
+ # HasHeartbeat : Configuration
3
+
4
+ module HasHeartbeat
5
+
6
+ class Configuration
7
+
8
+ # Configurable options:
9
+ attr_accessor :check_model, :use_airbrake
10
+
11
+ # Declare defaults on load:
12
+ def initialize
13
+ @check_model = nil
14
+ @use_airbrake = false
15
+ end
16
+
17
+ # Does the heartbeat check a database model?
18
+ def check_model?
19
+ !check_model.nil?
20
+ end
21
+
22
+ # Set the configuration to use Airbrake notifier:
23
+ def use_airbrake!
24
+ @use_airbrake = true
25
+ end
26
+
27
+ # Does this heartbeat check use Airbrake notifier?
28
+ def use_airbrake?
29
+ @use_airbrake == true
30
+ end
31
+
32
+ end # Configuration
33
+
34
+
35
+ # Provide an accessor to the gem configuration:
36
+ class << self
37
+ attr_accessor :configuration
38
+ end
39
+
40
+ # Yield the configuration to host:
41
+ def self.configure
42
+ self.configuration ||= Configuration.new
43
+ yield(configuration)
44
+ end
45
+
46
+ HasHeartbeat.configuration = Configuration.new
47
+
48
+ end # HasHeartbeat
@@ -0,0 +1,23 @@
1
+ # AWEXOME LABS
2
+ # HasHeartbeat
3
+
4
+ require "has_heartbeat"
5
+ require "rails"
6
+ require "action_controller"
7
+ require "airbrake"
8
+
9
+ require "has_heartbeat/configuration"
10
+
11
+ module HasHeartbeat
12
+
13
+ # Add features to Rails as an Engine:
14
+ class Engine < Rails::Engine
15
+ end
16
+
17
+ # Return the current version of the gem:
18
+ def self.version
19
+ Gem.loaded_specs["doesopengraph"].version.to_s
20
+ end
21
+
22
+ end # HasHeartbeat
23
+
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_heartbeat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Awexome Labs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2155755940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2155755940
25
+ - !ruby/object:Gem::Dependency
26
+ name: airbrake
27
+ requirement: &2155755420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2155755420
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &2155754820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2155754820
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &2155754300 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2155754300
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &2155753700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2155753700
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &2155753100 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 2.11.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2155753100
80
+ description: Simple heartbeat monitoring target for Rails with body, HTTP status code,
81
+ and Airbrake issue identification.
82
+ email: engineering@awexomelabs.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - README.rdoc
87
+ files:
88
+ - CHANGELOG.rdoc
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - README.rdoc
92
+ - ROADMAP.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - app/controllers/heartbeat_controller.rb
96
+ - config/routes.rb
97
+ - has_heartbeat.gemspec
98
+ - lib/has_heartbeat.rb
99
+ - lib/has_heartbeat/configuration.rb
100
+ homepage: http://github.com/awexome/has_heartbeat
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: 4356699598253285327
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.17
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Simple heartbeat monitoring target for Rails with body, HTTP status code,
128
+ and Airbrake issue identification.
129
+ test_files: []