server_health_check 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +55 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/server_health_check/version.rb +3 -0
- data/lib/server_health_check.rb +77 -0
- data/server_health_check.gemspec +32 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72039c4ebebff1777a10496fdb2ecafa05a754de
|
4
|
+
data.tar.gz: 2c498566a2cc648c8c8378cb3764a4842c75f62d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e3db55aeb1171251a5b722526b0eb5f66c848a2462b9d6dd8de6092dfcb90c90a4e560f55c021819fdcf1b80bd3b5e137a2fbf6cbacce84ba592f65b4b59d88
|
7
|
+
data.tar.gz: 2449cc678f11d91129dfd4da561dca35f39c448a51d9b55dfb92adcfcbb3290063d97032920287a57a55975ee02259d67a0e56297366a003463a4cc99a64b557
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
Include:
|
4
|
+
- '**/Rakefile'
|
5
|
+
|
6
|
+
StringLiterals:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
LineLength:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
ClassLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
AbcSize:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
UnusedBlockArgument:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
UnusedMethodArgument:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
GuardClause:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
SpaceInsideHashLiteralBraces:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Documentation:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Lambda:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
BlockDelimiters:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
ConditionalAssignment:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
RedundantBlockCall:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
CyclomaticComplexity:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
PerceivedComplexity:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
RescueModifier:
|
55
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# ServerHealthCheck
|
2
|
+
|
3
|
+
This gem provides a standard set of health checks for web services
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'server_health_check'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install server_health_check
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class SomeController
|
25
|
+
def show
|
26
|
+
health_check = ServerHealthCheck.new
|
27
|
+
health_check.active_record!
|
28
|
+
health_check.redis!(host: 'optional', port: 1234)
|
29
|
+
health_check.aws_creds!
|
30
|
+
health_check.aws_s3!('yakmail-inbound')
|
31
|
+
health_check.check! do
|
32
|
+
# app-specific code that wouldn't belong in the gem
|
33
|
+
# return true or false
|
34
|
+
end
|
35
|
+
http_status = health_check.ok? ? 200 : 500
|
36
|
+
render status: http_status, json: {status: health_check.results}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
Run rake to run tests before committing code
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "server_health_check"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "server_health_check/version"
|
2
|
+
|
3
|
+
class ServerHealthCheck
|
4
|
+
OK = 'OK'.freeze
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@results = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def redis!(host: nil, port: 6379)
|
11
|
+
host ||= ENV['REDIS_HOST'] || 'localhost'
|
12
|
+
@results[:redis] = 'The Redis gem is not loaded'
|
13
|
+
redis = Redis.new(host: host, port: port)
|
14
|
+
begin
|
15
|
+
redis.ping
|
16
|
+
@results[:redis] = OK
|
17
|
+
true
|
18
|
+
rescue Redis::CannotConnectError => e
|
19
|
+
@results[:redis] = e.to_s
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_record!
|
25
|
+
if ActiveRecord::Base.connected?
|
26
|
+
@results[:active_record] = OK
|
27
|
+
true
|
28
|
+
else
|
29
|
+
@results[:active_record] = "Failed: unable to connect to database"
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def aws_s3!(bucket = nil)
|
35
|
+
bucket = Aws::S3::Bucket.new(bucket)
|
36
|
+
if bucket.exists?
|
37
|
+
@results[:S3] = OK
|
38
|
+
true
|
39
|
+
else
|
40
|
+
@results[:S3] = "Failed: bucket does not exists"
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def aws_creds!
|
46
|
+
aws = Aws::S3::Client.new
|
47
|
+
begin
|
48
|
+
aws.list_buckets
|
49
|
+
@results[:AWS] = OK
|
50
|
+
true
|
51
|
+
rescue Aws::S3::Errors::InvalidAccessKeyId, Aws::S3::Errors::SignatureDoesNotMatch, NoMethodError => e
|
52
|
+
@results[:AWS] = e.to_s
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def check!
|
58
|
+
success = yield
|
59
|
+
if success
|
60
|
+
@results[:check] = OK
|
61
|
+
true
|
62
|
+
else
|
63
|
+
@results[:check] = "Failed"
|
64
|
+
false
|
65
|
+
end
|
66
|
+
rescue => e
|
67
|
+
@results[:check] = e.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def ok?
|
71
|
+
@results.all? do |key, value|
|
72
|
+
value == OK
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
attr_reader :results
|
77
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'server_health_check/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "server_health_check"
|
8
|
+
spec.version = ServerHealthCheck::VERSION
|
9
|
+
spec.authors = ["Quenten Griffith"]
|
10
|
+
spec.email = ["qgriffith@on-site.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Healthcheck for web apps.}
|
13
|
+
spec.description = %q{Health check for web apps checking things like active record, redis, and AWS.}
|
14
|
+
spec.homepage = ""
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: server_health_check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Quenten Griffith
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Health check for web apps checking things like active record, redis,
|
56
|
+
and AWS.
|
57
|
+
email:
|
58
|
+
- qgriffith@on-site.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/server_health_check.rb
|
73
|
+
- lib/server_health_check/version.rb
|
74
|
+
- server_health_check.gemspec
|
75
|
+
homepage: ''
|
76
|
+
licenses: []
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.5.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Healthcheck for web apps.
|
99
|
+
test_files: []
|