healthchecker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a9bc0e1293988838cf32b3091464c1467328fac
4
+ data.tar.gz: 41dd4ca7acec8aaca9b41d73188ad9d5c51306f2
5
+ SHA512:
6
+ metadata.gz: 9dd66042574acd282da4d529ac0dd396210e503e157c1e2fc47222437eef57e284c1c4eb4f7852e4942b358f8641d4a982537197f91ab5d3a6088358f184d3b3
7
+ data.tar.gz: bef459651989aeb1a6ccef0af5f04ecd40ac89c985da363e78da9ea864ec380269a5a59684e16f147fbead9a84af16cbb0a4c77c59117f9b1e20aa1a29262088
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Healthchecker'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Healthchecker
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Healthchecker
2
+ class HealthController < ActionController::Base
3
+
4
+ def show
5
+ checks = Healthchecker.perform_checks
6
+ render status: 500, json: {status: checks} and return unless checks.empty?
7
+ render json: {status: 'ok'}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module Healthchecker
2
+ class MetricsController < ActionController::Base
3
+
4
+ def show
5
+ render json: current_status
6
+ end
7
+
8
+ def current_status
9
+ {
10
+ redis: {
11
+ ok: (Redis.current.ping == 'PONG'),
12
+ config: Redis.current.client.options,
13
+ },
14
+ resque_redis: {
15
+ ok: (Resque.redis.ping == 'PONG'),
16
+ config: Resque.redis.client.options,
17
+ },
18
+ uptime: (Time.now - Healthchecker::APPLICATION_STARTED_AT),
19
+ }
20
+ end
21
+
22
+
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Healthchecker
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Healthchecker</title>
5
+ <%= stylesheet_link_tag "healthchecker/application", media: "all" %>
6
+ <%= javascript_include_tag "healthchecker/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Healthchecker::Engine.routes.draw do
2
+
3
+ get '/status' => 'health#show'
4
+ get '/metrics' => 'metrics#show'
5
+ end
@@ -0,0 +1,29 @@
1
+ require "healthchecker/engine"
2
+ require 'healthchecker/base_check'
3
+ require 'healthchecker/redis_check'
4
+ require 'healthchecker/migration_check'
5
+ require 'healthchecker/database_check'
6
+ require 'healthchecker/cache_check'
7
+ require 'healthchecker/s3_check'
8
+ require 'healthchecker/solr_check'
9
+ require 'healthchecker/dynamodb_check'
10
+
11
+ module Healthchecker
12
+ APPLICATION_STARTED_AT = Time.now
13
+
14
+ mattr_accessor :checks
15
+ self.checks = []
16
+
17
+ def self.add_check(name_or_class, options={})
18
+ self.checks << lookup_class(name_or_class).new(options.merge(check: name_or_class))
19
+ end
20
+
21
+ def self.perform_checks
22
+ self.checks.map(&:perform_check).compact
23
+ end
24
+
25
+ def self.lookup_class(name_or_class)
26
+ return name_or_class if name_or_class.respond_to?(:new)
27
+ "Healthchecker::#{name_or_class.to_s.capitalize}Check".constantize
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module Healthchecker
2
+ class BaseCheck
3
+ attr_reader :options
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def check!; raise NotImplementedError; end
10
+
11
+ def perform_check
12
+ check!
13
+ rescue RuntimeError => e
14
+ [e.class, e.message, options]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class CacheCheck < Healthchecker::BaseCheck
5
+
6
+ def check!
7
+ return if Rails.cache.write(cache_key, 'ok', :expires_in => 1.second)
8
+ raise 'Unable to write to rails cache.'
9
+ end
10
+
11
+ def cache_key
12
+ options[:cache_key] || SecureRandom.hex
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class DatabaseCheck < Healthchecker::BaseCheck
5
+
6
+ def check!
7
+ return if ActiveRecord::Migrator.current_version
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class DynamodbCheck < BaseCheck
5
+
6
+ def client
7
+ options[:client] || Aws::Dynamodb::Client.new
8
+ end
9
+
10
+ def check!
11
+ client.list_tables
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+
3
+ module Healthchecker
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Healthchecker
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class MigrationCheck < Healthchecker::BaseCheck
5
+
6
+ def check!
7
+ ActiveRecord::Migration.check_pending!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class RedisCheck < Healthchecker::BaseCheck
5
+
6
+ def check!
7
+ client = options[:client] || Redis.new
8
+ result = client.ping
9
+ return if result == 'PONG'
10
+ raise "Redis returned #{result.inspect} instead of PONG"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class S3Check < Healthchecker::BaseCheck
5
+
6
+ def check!
7
+ options[:buckets].each {|bucket| check_bucket_access(bucket)}
8
+ nil
9
+ end
10
+
11
+ def client
12
+ options[:client] || Aws::S3::Client.new
13
+ end
14
+
15
+ def check_bucket_access(bucket)
16
+ object_key = options[:object_key] || "healthchecker/#{Time.now.to_i}.json"
17
+ client.put_object(body: 'ok', bucket: bucket, key: object_key)
18
+ raise "Could not read object from bucket '#{bucket}'" unless client.get_object(
19
+ bucket: bucket,
20
+ key: object_key,
21
+ ).body.read == 'ok'
22
+ client.delete_object(bucket: bucket, key: object_key)
23
+ end
24
+
25
+
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require 'healthchecker/base_check'
2
+
3
+ module Healthchecker
4
+ class SolrCheck < BaseCheck
5
+
6
+ def client
7
+ options[:rsolr_client] || Sunspot::Session.new.send(:connection)
8
+ end
9
+
10
+ def check!
11
+ ping_success = client.head("admin/ping", :headers => {"Cache-Control" => "If-None-Match"}).response[:status] == 200
12
+ raise "Could not connect to solr" unless ping_success
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Healthchecker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :healthchecker do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: healthchecker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Will Bryant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sunspot_rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Standardized, healthcheck end-point for rails apps
98
+ email:
99
+ - william@tout.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - Rakefile
106
+ - app/assets/javascripts/healthchecker/application.js
107
+ - app/assets/stylesheets/healthchecker/application.css
108
+ - app/controllers/healthchecker/application_controller.rb
109
+ - app/controllers/healthchecker/health_controller.rb
110
+ - app/controllers/healthchecker/metrics_controller.rb
111
+ - app/helpers/healthchecker/application_helper.rb
112
+ - app/views/layouts/healthchecker/application.html.erb
113
+ - config/routes.rb
114
+ - lib/healthchecker.rb
115
+ - lib/healthchecker/base_check.rb
116
+ - lib/healthchecker/cache_check.rb
117
+ - lib/healthchecker/database_check.rb
118
+ - lib/healthchecker/dynamodb_check.rb
119
+ - lib/healthchecker/engine.rb
120
+ - lib/healthchecker/migration_check.rb
121
+ - lib/healthchecker/redis_check.rb
122
+ - lib/healthchecker/s3_check.rb
123
+ - lib/healthchecker/solr_check.rb
124
+ - lib/healthchecker/version.rb
125
+ - lib/tasks/healthchecker_tasks.rake
126
+ homepage: http://github.com/Tout/healthchecker
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.9.3
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.8
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Standardized, healthcheck end-point for rails apps
150
+ test_files: []