servicemonitor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/servicemonitor CHANGED
@@ -8,6 +8,7 @@ require "Alert"
8
8
  require "Alert/Email"
9
9
  require "MonitorType"
10
10
  require "MonitorType/Threshold"
11
+ require "MonitorType/Beanstalk"
11
12
  require "MonitorType/Dir"
12
13
  require "MonitorType/FluidDb"
13
14
  require "MonitorManager"
@@ -1,25 +1,35 @@
1
1
 
2
2
  class MonitorManager
3
- def initialize
4
- @list = Array.new
5
- end
6
-
7
- def add( monitor )
8
- @list.push monitor
9
- end
10
-
11
- def run
3
+ def initialize
4
+ @list = Array.new
5
+ end
6
+
7
+ def add( monitor )
8
+ @list.push monitor
9
+ end
10
+
11
+ def run
12
12
  while true do
13
- @list.each do |m|
14
- begin
15
- m.sanitise
16
- m.run
13
+ @list.each do |m|
14
+ begin
15
+ m.sanitise
16
+ m.run
17
17
  rescue MonitorTypeExceptionHandled => e
18
- m.alert( e.message )
19
- end
18
+ m.alert( e.message )
20
19
  end
21
- sleep 0.5
20
+ end
21
+ sleep 0.5
22
22
  end
23
- end
23
+
24
+ rescue Interrupt => e
25
+ puts "Exiting on request ..."
26
+
27
+ rescue Exception => e
28
+ puts e.class.name
29
+ puts "*** This is really unexpected."
30
+ messageLoop = false
31
+ puts "Message: " + e.message
32
+ puts e.backtrace
33
+ end
24
34
  end
25
35
 
@@ -0,0 +1,30 @@
1
+ require "beanstalk-client"
2
+ require "MonitorType/Threshold"
3
+
4
+ class MonitorType_Beanstalk<MonitorType_Threshold
5
+
6
+ def sanitise
7
+ @beanstalk = Beanstalk::Pool.new([@connection_string])
8
+ end
9
+
10
+ def initialize( name, queue, params )
11
+ super( name, params )
12
+ @connection_string = params[:beanstalk] || "localhost:11300"
13
+ @queue = queue
14
+ self.sanitise
15
+ rescue MonitorTypeExceptionHandled => e
16
+ puts e.message
17
+ abort()
18
+ end
19
+
20
+ def process
21
+ tubeStats = @beanstalk.stats_tube(@queue)
22
+
23
+ self.check( tubeStats["current-jobs-ready"], "Checking number of jobs in queue, #{@queue}" )
24
+ end
25
+ end
26
+
27
+ def beanstalk( name, queue, params )
28
+ $a.add( MonitorType_Beanstalk.new( name, queue, params ) )
29
+ end
30
+
@@ -20,7 +20,7 @@ class MonitorType_FluidDb<MonitorType_Threshold
20
20
  def process
21
21
  value = @fluidDb.queryForValue( @sql, [] )
22
22
 
23
- self.check( value.to_i, "Checking result of sql query, @{sql}" )
23
+ self.check( value, "Checking result of sql query, #{@sql}" )
24
24
  end
25
25
  end
26
26
 
@@ -8,6 +8,7 @@ class MonitorType_Threshold<MonitorType
8
8
  end
9
9
 
10
10
  def check( value, context_sentence )
11
+ value = value.to_i
11
12
  if !@min.nil? && value < @min then
12
13
  self.alert( "#{context_sentence}\nMinimum threshold exceeded. Minimum: #{@min}, Actual: #{value}" )
13
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servicemonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ files:
21
21
  - lib/Alert/Email.rb
22
22
  - lib/Alert.rb
23
23
  - lib/MonitorManager.rb
24
+ - lib/MonitorType/Beanstalk.rb
24
25
  - lib/MonitorType/Dir.rb
25
26
  - lib/MonitorType/FluidDb.rb
26
27
  - lib/MonitorType/Threshold.rb