okcomputer 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2e2e1fbf0bd12e43eeed9987395392fefc5820
|
4
|
+
data.tar.gz: 071f6f634691d45b44c5f134c2d3b87534834199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36ef20a1ceae3441cb1ed24f5b78d1596b51724aad107a62f5b5850901b0138a1fa3e686307469749247e91ac129a0c8c574f3d152c6f5633d9aea34a66be658
|
7
|
+
data.tar.gz: 8f6dd78954876861034bd82052159cd7b759bfa4a7b7e25845a4d90ea86908e57c78e579bb9928510f44b3dc2b1b25e7af206045cba2050dd8351ac15f794271
|
@@ -6,17 +6,17 @@ module OkComputer
|
|
6
6
|
# or red). A cluster status of red is reported as a failure, since this means
|
7
7
|
# one or more primary shards are unavailable. Note that the app may still
|
8
8
|
# be able to perform some queries on the available indices/shards.
|
9
|
-
class ElasticsearchCheck <
|
10
|
-
|
11
|
-
attr_accessor :request_timeout
|
9
|
+
class ElasticsearchCheck < HttpCheck
|
10
|
+
attr_reader :host
|
12
11
|
|
13
12
|
# Public: Initialize a new elasticsearch check.
|
14
13
|
#
|
15
14
|
# host - The hostname of elasticsearch
|
16
15
|
# request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.
|
17
16
|
def initialize(host, request_timeout = 5)
|
18
|
-
|
19
|
-
|
17
|
+
@host = URI(host)
|
18
|
+
health_url = URI("#{host}/_cluster/health")
|
19
|
+
super(health_url, request_timeout)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Public: Return the status of the elasticsearch cluster
|
@@ -28,23 +28,15 @@ module OkComputer
|
|
28
28
|
end
|
29
29
|
|
30
30
|
mark_message "Connected to elasticseach cluster '#{cluster_health[:cluster_name]}', #{cluster_health[:number_of_nodes]} nodes, status '#{cluster_health[:status]}'"
|
31
|
-
rescue
|
31
|
+
rescue => e
|
32
32
|
mark_failure
|
33
33
|
mark_message "Error: '#{e}'"
|
34
34
|
end
|
35
35
|
|
36
36
|
# Returns a hash from elasticsearch's cluster health API
|
37
37
|
def cluster_health
|
38
|
-
response =
|
38
|
+
response = perform_request
|
39
39
|
JSON.parse(response, symbolize_names: true)
|
40
|
-
rescue => e
|
41
|
-
raise ConnectionFailed, e
|
42
40
|
end
|
43
|
-
|
44
|
-
def health_url
|
45
|
-
@health_url ||= URI.join(host, '_cluster/health')
|
46
|
-
end
|
47
|
-
|
48
|
-
ConnectionFailed = Class.new(StandardError)
|
49
41
|
end
|
50
42
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
|
3
|
+
module OkComputer
|
4
|
+
# Performs a health check by reading a URL over HTTP.
|
5
|
+
# A successful response is considered passing.
|
6
|
+
# To implement your own pass/fail criteria, inherit from this
|
7
|
+
# class, override #check, and call #perform_request to get the
|
8
|
+
# response body.
|
9
|
+
class HttpCheck < Check
|
10
|
+
ConnectionFailed = Class.new(StandardError)
|
11
|
+
|
12
|
+
attr_accessor :url
|
13
|
+
attr_accessor :request_timeout
|
14
|
+
|
15
|
+
# Public: Initialize a new HTTP check.
|
16
|
+
#
|
17
|
+
# url - The URL to check
|
18
|
+
# request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.
|
19
|
+
def initialize(url, request_timeout = 5)
|
20
|
+
self.url = URI(url)
|
21
|
+
self.request_timeout = request_timeout.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Return the status of the HTTP check
|
25
|
+
def check
|
26
|
+
if perform_request
|
27
|
+
mark_message "HTTP check successful"
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
mark_message "Error: '#{e}'"
|
31
|
+
mark_failure
|
32
|
+
end
|
33
|
+
|
34
|
+
# Public: Actually performs the request against the URL.
|
35
|
+
# Returns response body if the request was successful.
|
36
|
+
# Otherwise raises a HttpCheck::ConnectionFailed error.
|
37
|
+
def perform_request
|
38
|
+
timeout(request_timeout) do
|
39
|
+
url.read(read_timeout: request_timeout)
|
40
|
+
end
|
41
|
+
rescue => e
|
42
|
+
raise ConnectionFailed, e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OkComputer
|
2
|
+
# This class performs a health check on Solr instance using the
|
3
|
+
# admin/ping handler.
|
4
|
+
class SolrCheck < HttpCheck
|
5
|
+
attr_reader :host
|
6
|
+
|
7
|
+
# Public: Initialize a new Solr check.
|
8
|
+
#
|
9
|
+
# host - The hostname of Solr
|
10
|
+
# request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.
|
11
|
+
def initialize(host, request_timeout = 5)
|
12
|
+
@host = URI(host)
|
13
|
+
ping_url ||= URI("#{host}/admin/ping")
|
14
|
+
super(ping_url, request_timeout)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Return the status of Solr
|
18
|
+
def check
|
19
|
+
if ping?
|
20
|
+
mark_message "Solr ping reported success"
|
21
|
+
else
|
22
|
+
mark_failure
|
23
|
+
mark_message "Solr ping reported failure"
|
24
|
+
end
|
25
|
+
rescue => e
|
26
|
+
mark_failure
|
27
|
+
mark_message "Error: '#{e}'"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Returns true if Solr's ping returned OK, otherwise false
|
31
|
+
def ping?
|
32
|
+
response = perform_request
|
33
|
+
!!(response =~ %r(<str name="status">OK</str>))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ok_computer/version.rb
CHANGED
data/lib/okcomputer.rb
CHANGED
@@ -6,6 +6,8 @@ require "ok_computer/registry"
|
|
6
6
|
|
7
7
|
# and the built-in checks
|
8
8
|
require "ok_computer/built_in_checks/size_threshold_check"
|
9
|
+
require "ok_computer/built_in_checks/http_check"
|
10
|
+
|
9
11
|
require "ok_computer/built_in_checks/active_record_check"
|
10
12
|
require "ok_computer/built_in_checks/app_version_check"
|
11
13
|
require "ok_computer/built_in_checks/cache_check"
|
@@ -13,6 +15,7 @@ require "ok_computer/built_in_checks/default_check"
|
|
13
15
|
require "ok_computer/built_in_checks/delayed_job_backed_up_check"
|
14
16
|
require "ok_computer/built_in_checks/generic_cache_check"
|
15
17
|
require "ok_computer/built_in_checks/elasticsearch_check"
|
18
|
+
require "ok_computer/built_in_checks/solr_check"
|
16
19
|
require "ok_computer/built_in_checks/mongoid_check"
|
17
20
|
require "ok_computer/built_in_checks/mongoid_replica_set_check"
|
18
21
|
require "ok_computer/built_in_checks/resque_backed_up_check"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: okcomputer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Byrne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
|
75
75
|
- lib/ok_computer/built_in_checks/elasticsearch_check.rb
|
76
76
|
- lib/ok_computer/built_in_checks/generic_cache_check.rb
|
77
|
+
- lib/ok_computer/built_in_checks/http_check.rb
|
77
78
|
- lib/ok_computer/built_in_checks/mongoid_check.rb
|
78
79
|
- lib/ok_computer/built_in_checks/mongoid_replica_set_check.rb
|
79
80
|
- lib/ok_computer/built_in_checks/resque_backed_up_check.rb
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- lib/ok_computer/built_in_checks/ruby_version_check.rb
|
83
84
|
- lib/ok_computer/built_in_checks/sidekiq_latency_check.rb
|
84
85
|
- lib/ok_computer/built_in_checks/size_threshold_check.rb
|
86
|
+
- lib/ok_computer/built_in_checks/solr_check.rb
|
85
87
|
- lib/ok_computer/check.rb
|
86
88
|
- lib/ok_computer/check_collection.rb
|
87
89
|
- lib/ok_computer/configuration.rb
|