okcomputer 1.1.0 → 1.2.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: 9c8082e5decec046c189e6ccd432ffcafafdd863
4
- data.tar.gz: e943f74ef3075248aae292a370ffdcb3ed433dc4
3
+ metadata.gz: 24238bddd672bb4db2ca97ec0abd4460faff2da6
4
+ data.tar.gz: fce0dba5d41e276557f3fbdbbc6824d91571d109
5
5
  SHA512:
6
- metadata.gz: bbfa6ee07eba2834f5fb2066ba75f3bf371ff622cbfc669f72ae52438ec341edad9153a90a40ce1aa9ecd4403c7b7f0d69b79cb36afcaec61b21452291ccf7a6
7
- data.tar.gz: 5586d90b4e6798e9ad61a68d159766a519f61352ac6b907ed8d82fddcdf0db776785862858d8940146c0f1100b2d272092a1acb72d1504091efeb71ad7a342dc
6
+ metadata.gz: 74b1aca6e40aecbea93a345fd8ebe66adceee698266edc9f547f8526457fb63aa66445ede8df6d745925aad9e87b0bfb0f3fbaf80bb31b85186907e4da481a30
7
+ data.tar.gz: eee8e54d589b97a9fd6773a8d08ffbaf4111972b4b6bf437161654b7b211ca9c360d9d2f4cc6d42fee108738f0c9f9a162f0b503a6a6ca49a0aa98186d1344e1
@@ -0,0 +1,39 @@
1
+ module OkComputer
2
+ # Display app version SHA
3
+ #
4
+ # * If `ENV["SHA"]` is set, uses that value.
5
+ # * Otherwise, checks for Capistrano's REVISION file in the app root.
6
+ # * Failing these, the check fails
7
+ class AppVersionCheck < Check
8
+ # Public: Return the application version
9
+ def check
10
+ mark_message "Version: #{version}"
11
+ rescue UnknownRevision
12
+ mark_failure
13
+ mark_message "Unable to determine version"
14
+ end
15
+
16
+ # Public: The application version
17
+ #
18
+ # Returns a String
19
+ def version
20
+ version_from_env || version_from_file || raise(UnknownRevision)
21
+ end
22
+
23
+ private
24
+
25
+ # Private: Version stored in environment variable
26
+ def version_from_env
27
+ ENV["SHA"]
28
+ end
29
+
30
+ # Private: Version stored in Capistrano revision file
31
+ def version_from_file
32
+ if File.exist?(Rails.root.join("REVISION"))
33
+ File.read(Rails.root.join("REVISION")).chomp
34
+ end
35
+ end
36
+
37
+ UnknownRevision = Class.new(StandardError)
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ module OkComputer
2
+ # This class performs a health check on an elasticsearch cluster using the
3
+ # {cluster health API}[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html].
4
+ #
5
+ # It reports the cluster's name, number of nodes, and status (green, yellow,
6
+ # or red). A cluster status of red is reported as a failure, since this means
7
+ # one or more primary shards are unavailable. Note that the app may still
8
+ # be able to perform some queries on the available indices/shards.
9
+ class ElasticsearchCheck < Check
10
+ attr_accessor :host
11
+ attr_accessor :request_timeout
12
+
13
+ # Public: Initialize a new elasticsearch check.
14
+ #
15
+ # host - The hostname of elasticsearch
16
+ # request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.
17
+ def initialize(host, request_timeout = 5)
18
+ self.host = host
19
+ self.request_timeout = request_timeout.to_i
20
+ end
21
+
22
+ # Public: Return the status of the elasticsearch cluster
23
+ def check
24
+ cluster_health = self.cluster_health
25
+
26
+ if cluster_health[:status] == 'red'
27
+ mark_failure
28
+ end
29
+
30
+ mark_message "Connected to elasticseach cluster '#{cluster_health[:cluster_name]}', #{cluster_health[:number_of_nodes]} nodes, status '#{cluster_health[:status]}'"
31
+ rescue ConnectionFailed => e
32
+ mark_failure
33
+ mark_message "Error: '#{e}'"
34
+ end
35
+
36
+ # Returns a hash from elasticsearch's cluster health API
37
+ def cluster_health
38
+ response = timeout(request_timeout) { health_url.read(read_timeout: request_timeout) }
39
+ JSON.parse(response, symbolize_names: true)
40
+ rescue => e
41
+ raise ConnectionFailed, e
42
+ end
43
+
44
+ def health_url
45
+ @health_url ||= URI.join(host, '_cluster/health')
46
+ end
47
+
48
+ ConnectionFailed = Class.new(StandardError)
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module OkComputer
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/okcomputer.rb CHANGED
@@ -7,10 +7,12 @@ require "ok_computer/registry"
7
7
  # and the built-in checks
8
8
  require "ok_computer/built_in_checks/size_threshold_check"
9
9
  require "ok_computer/built_in_checks/active_record_check"
10
+ require "ok_computer/built_in_checks/app_version_check"
10
11
  require "ok_computer/built_in_checks/cache_check"
11
12
  require "ok_computer/built_in_checks/default_check"
12
13
  require "ok_computer/built_in_checks/delayed_job_backed_up_check"
13
14
  require "ok_computer/built_in_checks/generic_cache_check"
15
+ require "ok_computer/built_in_checks/elasticsearch_check"
14
16
  require "ok_computer/built_in_checks/mongoid_check"
15
17
  require "ok_computer/built_in_checks/mongoid_replica_set_check"
16
18
  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.1.0
4
+ version: 1.2.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-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -68,9 +68,11 @@ files:
68
68
  - app/controllers/ok_computer/ok_computer_controller.rb
69
69
  - config/routes.rb
70
70
  - lib/ok_computer/built_in_checks/active_record_check.rb
71
+ - lib/ok_computer/built_in_checks/app_version_check.rb
71
72
  - lib/ok_computer/built_in_checks/cache_check.rb
72
73
  - lib/ok_computer/built_in_checks/default_check.rb
73
74
  - lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
75
+ - lib/ok_computer/built_in_checks/elasticsearch_check.rb
74
76
  - lib/ok_computer/built_in_checks/generic_cache_check.rb
75
77
  - lib/ok_computer/built_in_checks/mongoid_check.rb
76
78
  - lib/ok_computer/built_in_checks/mongoid_replica_set_check.rb