okcomputer 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce5b21b1d706641cf9b709167a93eddf24701338
4
- data.tar.gz: 045d6b22a4107d0b643318e3a721cbf1af256709
3
+ metadata.gz: 9c8082e5decec046c189e6ccd432ffcafafdd863
4
+ data.tar.gz: e943f74ef3075248aae292a370ffdcb3ed433dc4
5
5
  SHA512:
6
- metadata.gz: 79ed0bb362e58c18473688f2e0ffddd42a93de86654231964ecd4df798677af4c66c18ccf1895a5e69bcd5377c370033ede13b91c1cc5c867f0b42d04c8ab412
7
- data.tar.gz: 0ecb90b754c9d4c2f0d4e5ef68e1ca3814ff9d1569fac57ea582c54ff4d2396f828672796505363244ae0f2343ec2828a865c3f903b4f555976c2b0846b089be
6
+ metadata.gz: bbfa6ee07eba2834f5fb2066ba75f3bf371ff622cbfc669f72ae52438ec341edad9153a90a40ce1aa9ecd4403c7b7f0d69b79cb36afcaec61b21452291ccf7a6
7
+ data.tar.gz: 5586d90b4e6798e9ad61a68d159766a519f61352ac6b907ed8d82fddcdf0db776785862858d8940146c0f1100b2d272092a1acb72d1504091efeb71ad7a342dc
@@ -1,7 +1,12 @@
1
1
  module OkComputer
2
+ # Verifies that the Rails cache is set up and can speak with Memcached
3
+ # running on the given host (defaults to local).
2
4
  class CacheCheck < Check
5
+ attr_accessor :host
3
6
 
4
- ConnectionFailed = Class.new(StandardError)
7
+ def initialize(host=Socket.gethostname)
8
+ self.host = host
9
+ end
5
10
 
6
11
  # Public: Check whether the cache is active
7
12
  def check
@@ -14,9 +19,9 @@ module OkComputer
14
19
  # Public: Outputs stats string for cache
15
20
  def stats
16
21
  stats = Rails.cache.stats
17
- host = stats.select{|k,v| k =~ Regexp.new(Socket.gethostname) }.values[0]
18
- mem_used = to_megabytes host['bytes']
19
- mem_max = to_megabytes host['limit_maxbytes']
22
+ values = stats.select{|k,v| k =~ Regexp.new(host) }.values[0]
23
+ mem_used = to_megabytes values['bytes']
24
+ mem_max = to_megabytes values['limit_maxbytes']
20
25
  return "#{mem_used} / #{mem_max} MB, #{stats.count - 1} peers"
21
26
  rescue => e
22
27
  raise ConnectionFailed, e
@@ -28,5 +33,7 @@ module OkComputer
28
33
  def to_megabytes(bytes)
29
34
  bytes.to_i / (1024 * 1024)
30
35
  end
36
+
37
+ ConnectionFailed = Class.new(StandardError)
31
38
  end
32
39
  end
@@ -0,0 +1,33 @@
1
+ require "securerandom"
2
+
3
+ module OkComputer
4
+ # Verifies that Rails can write to and read from its cache.
5
+ class GenericCacheCheck < Check
6
+ # Public: Check whether cache can be written to and read from
7
+ def check
8
+ test_value.tap do |value|
9
+ Rails.cache.write(cache_key, value)
10
+ if value == Rails.cache.read(cache_key)
11
+ mark_message "Able to read and write"
12
+ else
13
+ mark_failure
14
+ mark_message "Value read from the cache does not match the value written"
15
+ end
16
+ end
17
+ rescue => error
18
+ mark_failure
19
+ mark_message "Connection failure: #{error}"
20
+ end
21
+
22
+ private
23
+
24
+ # Private: Generate a unique value each time we check
25
+ def test_value
26
+ SecureRandom.hex
27
+ end
28
+
29
+ def cache_key
30
+ "ock-generic-cache-check-#{Socket.gethostname}"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,72 @@
1
+ module OkComputer
2
+ # This class provides a check for a mongodb replica set via the Mongoid ORM.
3
+ #
4
+ # The check first refreshes the cluster status, which communicates with all
5
+ # the nodes, discovers any new ones, and figures out which node is the
6
+ # primary and which ones are the secondaries. Nodes that are recovering or
7
+ # unavailable are automatically removed from rotation. It's okay to do this
8
+ # fairly frequently.
9
+ #
10
+ # The second part of the check attempts to contact the primary node (to
11
+ # ensure writes are accepted) and a secondary node (to ensure reads
12
+ # can be distributed).
13
+ #
14
+ # This calls the
15
+ # {replSetGetStatus}[http://docs.mongodb.org/manual/reference/command/replSetGetStatus/]
16
+ # command on the admin database of each node. This provides further
17
+ # information as well as the replica set's name. This could potentially be
18
+ # parsed for more actionable information.
19
+ class MongoidReplicaSetCheck < OkComputer::Check
20
+ attr_accessor :session
21
+
22
+ # Public: Initialize a check for a Mongoid replica set
23
+ #
24
+ # session - The name of the Mongoid session to use. Defaults to the
25
+ # default session.
26
+ def initialize(session = :default)
27
+ self.session = Mongoid::Sessions.with_name(session)
28
+ end
29
+
30
+ # Public: Return the status of the mongodb replica set
31
+ def check
32
+ refresh
33
+ primary_status = self.primary_status
34
+ secondary_status = self.secondary_status
35
+ mark_message "Connected to #{session.cluster.nodes.count} nodes in mongodb replica set '#{primary_status['set']}'"
36
+ rescue ConnectionFailed => e
37
+ mark_failure
38
+ mark_message "Error: '#{e}'"
39
+ end
40
+
41
+ # Public: Refresh the cluster status
42
+ def refresh
43
+ session.cluster.refresh
44
+ rescue => e
45
+ raise ConnectionFailed, e
46
+ end
47
+
48
+ # Public: The status for the session's mongodb replica set primary
49
+ #
50
+ # Returns a hash with the status of the primary
51
+ def primary_status
52
+ session.cluster.with_primary do |primary|
53
+ primary.command(:admin, replSetGetStatus: 1)
54
+ end
55
+ rescue => e
56
+ raise ConnectionFailed, e
57
+ end
58
+
59
+ # Public: The status for the session's mongodb replica set secondary
60
+ #
61
+ # Returns a hash with the status of the secondary
62
+ def secondary_status
63
+ session.cluster.with_secondary do |secondary|
64
+ secondary.command(:admin, replSetGetStatus: 1)
65
+ end
66
+ rescue => e
67
+ raise ConnectionFailed, e
68
+ end
69
+
70
+ ConnectionFailed = Class.new(StandardError)
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module OkComputer
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/okcomputer.rb CHANGED
@@ -7,15 +7,17 @@ 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/cache_check"
10
11
  require "ok_computer/built_in_checks/default_check"
12
+ require "ok_computer/built_in_checks/delayed_job_backed_up_check"
13
+ require "ok_computer/built_in_checks/generic_cache_check"
11
14
  require "ok_computer/built_in_checks/mongoid_check"
15
+ require "ok_computer/built_in_checks/mongoid_replica_set_check"
12
16
  require "ok_computer/built_in_checks/resque_backed_up_check"
13
- require "ok_computer/built_in_checks/resque_failure_threshold_check"
14
17
  require "ok_computer/built_in_checks/resque_down_check"
15
- require "ok_computer/built_in_checks/delayed_job_backed_up_check"
16
- require "ok_computer/built_in_checks/sidekiq_latency_check"
18
+ require "ok_computer/built_in_checks/resque_failure_threshold_check"
17
19
  require "ok_computer/built_in_checks/ruby_version_check"
18
- require "ok_computer/built_in_checks/cache_check"
20
+ require "ok_computer/built_in_checks/sidekiq_latency_check"
19
21
 
20
22
  OkComputer::Registry.register "default", OkComputer::DefaultCheck.new
21
23
  OkComputer::Registry.register "database", OkComputer::ActiveRecordCheck.new
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.0.0
4
+ version: 1.1.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-20 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -71,7 +71,9 @@ files:
71
71
  - lib/ok_computer/built_in_checks/cache_check.rb
72
72
  - lib/ok_computer/built_in_checks/default_check.rb
73
73
  - lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
74
+ - lib/ok_computer/built_in_checks/generic_cache_check.rb
74
75
  - lib/ok_computer/built_in_checks/mongoid_check.rb
76
+ - lib/ok_computer/built_in_checks/mongoid_replica_set_check.rb
75
77
  - lib/ok_computer/built_in_checks/resque_backed_up_check.rb
76
78
  - lib/ok_computer/built_in_checks/resque_down_check.rb
77
79
  - lib/ok_computer/built_in_checks/resque_failure_threshold_check.rb
@@ -89,11 +91,7 @@ homepage: https://github.com/sportngin/okcomputer
89
91
  licenses:
90
92
  - MIT
91
93
  metadata: {}
92
- post_install_message: |
93
- OkComputer Namespace Change (v0.7.0)
94
- ------------------------------------
95
- OkComputer has changed its namespace from `OKComputer` (uppercase K) to `OkComputer` (lowercase k)
96
- as of version 0.7.0. Please update your configuration accordingly.
94
+ post_install_message:
97
95
  rdoc_options: []
98
96
  require_paths:
99
97
  - lib