okcomputer 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Code Climate](https://codeclimate.com/github/sportngin/okcomputer.png)](https://codeclimate.com/github/sportngin/okcomputer)
2
2
  [![Build Status](https://travis-ci.org/sportngin/okcomputer.png)](https://travis-ci.org/sportngin/okcomputer)
3
+ [![Coverage Status](https://coveralls.io/repos/sportngin/okcomputer/badge.png?branch=master)](https://coveralls.io/r/sportngin/okcomputer)
3
4
 
4
5
  # OK Computer
5
6
 
@@ -94,6 +95,12 @@ Checks are available as plain text (by default) or JSON by appending .json, e.g.
94
95
  * http://example.com/okcomputer.json
95
96
  * http://example.com/okcomputer/all.json
96
97
 
98
+ ## OkComputer NewRelic Ignore
99
+
100
+ If you use OKComputer for uptime checks, it will start to artificially bring your
101
+ request time down on NewRelic. To avoid that, check out
102
+ [https://github.com/sportngin/okcomputer-newrelic-ignore](this gem).
103
+
97
104
  ## Deprecations and Breaking Changes
98
105
 
99
106
  #### Deprecation of Check#call
@@ -1,5 +1,5 @@
1
1
  module OKComputer
2
- class DelayedJobBackedUpCheck < Check
2
+ class DelayedJobBackedUpCheck < SizeThresholdCheck
3
3
  attr_accessor :priority
4
4
  attr_accessor :threshold
5
5
 
@@ -17,27 +17,11 @@ module OKComputer
17
17
  def initialize(priority, threshold)
18
18
  self.priority = Integer(priority)
19
19
  self.threshold = Integer(threshold)
20
- end
21
-
22
- # Public: Check and report whether delayed jobs are backed up
23
- def check
24
- if backed_up?
25
- mark_failure
26
- mark_message "Delayed Jobs within priority '#{priority}' backed up! (#{count})"
27
- else
28
- mark_message "Delayed Jobs within priority '#{priority}' at reasonable level (#{count})"
29
- end
30
- end
31
-
32
- # Public: Whether delayed jobs are backed up
33
- #
34
- # Returns a Boolean
35
- def backed_up?
36
- count > threshold
20
+ self.name = "Delayed Jobs within priority '#{priority}'"
37
21
  end
38
22
 
39
23
  # Public: How many delayed jobs are pending within the given priority
40
- def count
24
+ def size
41
25
  Delayed::Job.where("priority <= ?", priority).where(:locked_at => nil, :last_error => nil).count
42
26
  end
43
27
  end
@@ -1,5 +1,5 @@
1
1
  module OKComputer
2
- class ResqueBackedUpCheck < Check
2
+ class ResqueBackedUpCheck < SizeThresholdCheck
3
3
  attr_accessor :queue
4
4
  attr_accessor :threshold
5
5
 
@@ -11,20 +11,11 @@ module OKComputer
11
11
  def initialize(queue, threshold)
12
12
  self.queue = queue
13
13
  self.threshold = Integer(threshold)
14
- end
15
-
16
- # Public: Check whether the given queue is backed up
17
- def check
18
- if count <= threshold
19
- mark_message "Resque queue '#{queue}' at reasonable level (#{count})"
20
- else
21
- mark_failure
22
- mark_message "Resque queue '#{queue}' backed up! (#{count})"
23
- end
14
+ self.name = "Resque queue '#{queue}'"
24
15
  end
25
16
 
26
17
  # Public: The number of jobs in the check's queue
27
- def count
18
+ def size
28
19
  Resque.size(queue)
29
20
  end
30
21
  end
@@ -0,0 +1,40 @@
1
+ module OKComputer
2
+ class SizeThresholdCheck < Check
3
+ attr_accessor :size_proc
4
+ attr_accessor :threshold
5
+
6
+ # Public: Initialize a check for a backed-up Resque queue
7
+ #
8
+ # name - the value that this check should be refered to as
9
+ # threshold - An Integer to compare the size object's count against to consider
10
+ # it backed up
11
+ # size_proc - The block/proc that returns an integer to compare against
12
+ #
13
+ # Examples
14
+ #
15
+ # SizeThresholdCheck.new("some queue", 2) do
16
+ # Queue.new("my_queue").size
17
+ # end
18
+ #
19
+ def initialize(name, threshold, &size_proc)
20
+ self.size_proc = size_proc
21
+ self.threshold = Integer(threshold)
22
+ self.name = name
23
+ end
24
+
25
+ # Public: Check whether the given queue is backed up
26
+ def check
27
+ if size <= threshold
28
+ mark_message " #{name} at reasonable level (#{size})"
29
+ else
30
+ mark_failure
31
+ mark_message "#{name} is over #{threshold} threshold! (#{size})"
32
+ end
33
+ end
34
+
35
+ # Public: The number of jobs in the check's queue
36
+ def size
37
+ Integer(size_proc.call)
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module OKComputer
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
data/lib/okcomputer.rb CHANGED
@@ -5,6 +5,7 @@ require "okcomputer/check_collection"
5
5
  require "okcomputer/registry"
6
6
 
7
7
  # and the built-in checks
8
+ require "okcomputer/built_in_checks/size_threshold_check"
8
9
  require "okcomputer/built_in_checks/active_record_check"
9
10
  require "okcomputer/built_in_checks/default_check"
10
11
  require "okcomputer/built_in_checks/mongoid_check"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okcomputer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-14 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: coveralls
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: ! "\n Inspired by the simplicity of Fitter Happier, but frustrated
63
79
  by its lack of\n flexibility, we built OK Computer. Create and register your
64
80
  own custom\n health checks, or choose from the built-in library of checks to
@@ -77,6 +93,7 @@ files:
77
93
  - lib/okcomputer/built_in_checks/mongoid_check.rb
78
94
  - lib/okcomputer/built_in_checks/resque_backed_up_check.rb
79
95
  - lib/okcomputer/built_in_checks/resque_down_check.rb
96
+ - lib/okcomputer/built_in_checks/size_threshold_check.rb
80
97
  - lib/okcomputer/check.rb
81
98
  - lib/okcomputer/check_collection.rb
82
99
  - lib/okcomputer/configuration.rb
@@ -102,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
119
  version: '0'
103
120
  segments:
104
121
  - 0
105
- hash: -1102877545554144384
122
+ hash: 2366679843974261042
106
123
  required_rubygems_version: !ruby/object:Gem::Requirement
107
124
  none: false
108
125
  requirements:
@@ -111,10 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
128
  version: '0'
112
129
  segments:
113
130
  - 0
114
- hash: -1102877545554144384
131
+ hash: 2366679843974261042
115
132
  requirements: []
116
133
  rubyforge_project:
117
- rubygems_version: 1.8.23
134
+ rubygems_version: 1.8.24
118
135
  signing_key:
119
136
  specification_version: 3
120
137
  summary: A simple, extensible health-check monitor