servicemonitor 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/bin/servicemonitor +3 -5
- data/lib/MonitorType/Dir.rb +5 -6
- data/lib/MonitorType/Drive.rb +50 -0
- data/lib/MonitorType/FluidDb.rb +7 -7
- data/lib/MonitorType/Process.rb +41 -35
- metadata +37 -3
data/README.md
CHANGED
data/bin/servicemonitor
CHANGED
@@ -19,11 +19,9 @@ require "helper_functions"
|
|
19
19
|
#Don't buffer stdout
|
20
20
|
$stdout.sync = true
|
21
21
|
|
22
|
-
if ARGV.length
|
23
|
-
|
24
|
-
|
25
|
-
abort( "Usage: monitor <path to dsl>" )
|
26
|
-
end
|
22
|
+
abort( "Usage: servicemonitor <path to dsl>" ) if ARGV.length != 1
|
23
|
+
|
24
|
+
dslName = ARGV[0]
|
27
25
|
|
28
26
|
#Need to remove file name extension
|
29
27
|
ENV["APP_NAME"] = File.basename( dslName ) if ENV["APP_NAME"].nil?
|
data/lib/MonitorType/Dir.rb
CHANGED
@@ -2,7 +2,7 @@ require "MonitorType/Threshold"
|
|
2
2
|
|
3
3
|
#A directory class for checking how many files are in a directory
|
4
4
|
class MonitorType_Dir<MonitorType_Threshold
|
5
|
-
|
5
|
+
|
6
6
|
#Extract parameters
|
7
7
|
#
|
8
8
|
# @param [String] path Path to directory to check
|
@@ -13,16 +13,16 @@ class MonitorType_Dir<MonitorType_Threshold
|
|
13
13
|
raise MonitorTypeParameterMissingError.new(string)
|
14
14
|
end
|
15
15
|
@path = @params[:path]
|
16
|
-
|
16
|
+
|
17
17
|
@context_sentence = "Checking number of files in, #{@path}"
|
18
18
|
end
|
19
19
|
|
20
20
|
|
21
21
|
def setup
|
22
22
|
inputDir = Dir.new( @path )
|
23
|
-
|
23
|
+
@path = inputDir.path
|
24
24
|
@params[:dir] = inputDir
|
25
|
-
|
25
|
+
|
26
26
|
rescue Errno::ENOENT => e
|
27
27
|
string = "***** Directory does not exist, #{@path}.\n"
|
28
28
|
string = "#{string}***** Create the directory, #{@path}, and try again.\n"
|
@@ -34,7 +34,7 @@ class MonitorType_Dir<MonitorType_Threshold
|
|
34
34
|
string = "#{string}***** eg, rm #{@path} && mkdir #{@path}"
|
35
35
|
raise MonitorTypeExceptionHandled.new(string)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def getValue
|
39
39
|
return Dir.glob( "#{@path}/*" ).length
|
40
40
|
end
|
@@ -43,4 +43,3 @@ end
|
|
43
43
|
def dir( params )
|
44
44
|
$a.add( MonitorType_Dir.new( params ) )
|
45
45
|
end
|
46
|
-
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "MonitorType/Threshold"
|
2
|
+
require "sys/filesystem"
|
3
|
+
include Sys
|
4
|
+
|
5
|
+
class MonitorType_Drive<MonitorType_Threshold
|
6
|
+
|
7
|
+
def extractParams
|
8
|
+
if @params[:path].nil? then
|
9
|
+
string = "*** Drive parameter missing, drive\n"
|
10
|
+
string = "#{string}*** :drive => <name of the drive to be monitored>"
|
11
|
+
raise MonitorTypeParameterMissingError.new(string)
|
12
|
+
end
|
13
|
+
@path = @params[:path]
|
14
|
+
|
15
|
+
log "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}"
|
16
|
+
|
17
|
+
if @params[:min].nil? then
|
18
|
+
string = "*** Min parameter missing, min\n"
|
19
|
+
string = "#{string}*** :min => <the minimum amount of free space on the drive to be monitored>"
|
20
|
+
raise MonitorTypeParameterMissingError.new(string)
|
21
|
+
end
|
22
|
+
|
23
|
+
log "*** Max value will be ignored, setting to nil" unless @params[:max].nil?
|
24
|
+
@max = nil
|
25
|
+
|
26
|
+
@context_sentence = "Checking that available drive space is greater than min, #{@process_name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
begin
|
31
|
+
#Check that the path exists
|
32
|
+
drive = Filesystem.stat(@path)
|
33
|
+
|
34
|
+
rescue=>e
|
35
|
+
string = "*** Unable to mount the specifed path\n"
|
36
|
+
string = "#{string}*** path: #{@path}\n"
|
37
|
+
string = "#{string}*** Please fix the error and run again\n"
|
38
|
+
raise MonitorTypeExceptionHandled.new("Unable to mount path: #{@path}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def getValue
|
43
|
+
return ((Filesystem.stat(@path).blocks_available.to_f / Filesystem.stat(@path).blocks.to_f) * 100).round(2)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def process(params)
|
49
|
+
$a.add(MonitorType_Drive.new(params))
|
50
|
+
end
|
data/lib/MonitorType/FluidDb.rb
CHANGED
@@ -8,7 +8,7 @@ require "MonitorType/Threshold"
|
|
8
8
|
# => check that the number is not greater than 2
|
9
9
|
|
10
10
|
class MonitorType_FluidDb<MonitorType_Threshold
|
11
|
-
|
11
|
+
|
12
12
|
#Extract parameters
|
13
13
|
#
|
14
14
|
# @param [String] uri Connection string to db
|
@@ -27,18 +27,18 @@ class MonitorType_FluidDb<MonitorType_Threshold
|
|
27
27
|
string = "#{string}*** Please fix the uri and run again"
|
28
28
|
raise MonitorTypeParameterMissingError.new(string)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
if @params[:sql].nil? then
|
32
32
|
string = "*** FluidDb parameter missing, sql"
|
33
33
|
string = "#{string}*** :sql => <sql statement, producing a single column, single row which yeidls a number>"
|
34
34
|
raise MonitorTypeParameterMissingError.new(string)
|
35
35
|
end
|
36
36
|
@sql = @params[:sql]
|
37
|
-
|
37
|
+
|
38
38
|
@context_sentence = "Checking result of sql query, #{@sql}"
|
39
|
-
|
39
|
+
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
#Create the connection to the db, and get the value
|
43
43
|
#This ensures that all params are correct.
|
44
44
|
def setup
|
@@ -49,13 +49,13 @@ class MonitorType_FluidDb<MonitorType_Threshold
|
|
49
49
|
string = "*** FluidDb encountered an error while connecting to the db\n"
|
50
50
|
string = "#{string}*** Error: #{e.message}\n"
|
51
51
|
string = "#{string}*** uri: #{@uri}\n"
|
52
|
-
string = "#{string}*** Please
|
52
|
+
string = "#{string}*** Please fix the error and run again\n"
|
53
53
|
raise MonitorTypeExceptionHandled.new(string)
|
54
54
|
end
|
55
55
|
|
56
56
|
@params[:fluidDb] = @fluidDb
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def getValue
|
60
60
|
begin
|
61
61
|
return @fluidDb.queryForValue( @sql, [] )
|
data/lib/MonitorType/Process.rb
CHANGED
@@ -1,48 +1,54 @@
|
|
1
1
|
require "MonitorType/Threshold"
|
2
|
+
require "helper_functions"
|
3
|
+
|
4
|
+
InvalidProcessNameError = Class.new(StandardError)
|
2
5
|
|
3
6
|
#A class for checking if a Process is running in Unix based systems
|
4
7
|
class MonitorType_Process<MonitorType_Threshold
|
5
8
|
|
9
|
+
#Extract parameters
|
10
|
+
#
|
11
|
+
# @param [String] :process_name THe name of the process to monitor
|
12
|
+
def extractParams
|
13
|
+
if @params[:process_name].nil? then
|
14
|
+
string = "*** Process Name parameter missing, process_name\n"
|
15
|
+
string = "#{string}*** :process_name => <name of the process to be monitored>"
|
16
|
+
raise MonitorTypeParameterMissingError.new(string)
|
17
|
+
end
|
18
|
+
@process_name = @params[:process_name]
|
19
|
+
|
20
|
+
log "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}"
|
21
|
+
|
22
|
+
unless (@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0 then
|
23
|
+
string = "*** Process Name parameter doest not match the required pattern, #{@process_name}\n"
|
24
|
+
string = "#{string}*** :process_name => <plain string, or a string with one or more characters enclosed in square brackets, i.e. 'foo', '[f]oo' or '[foo]'>"
|
25
|
+
raise InvalidProcessNameError.new(string)
|
26
|
+
end
|
27
|
+
|
28
|
+
log "*** Min value will be ignored, setting to 1" unless (params[:min].nil? || params[:min] == 0)
|
29
|
+
@min = 1
|
30
|
+
|
31
|
+
log "*** Max value will be ignored, setting to nil" unless params[:max].nil?
|
32
|
+
@max = nil
|
33
|
+
|
34
|
+
@context_sentence = "Checking that process is running, #{@process_name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
self.sanitise
|
39
|
+
rescue MonitorTypeExceptionHandled => e
|
40
|
+
puts e.message
|
41
|
+
abort
|
42
|
+
end
|
43
|
+
|
6
44
|
def sanitise
|
7
45
|
#Ensure that the process name contains a single character surrounded by square brackets
|
8
46
|
@process_name = @process_name.insert(0,'[').insert(2,']') unless @process_name =~ /^.*\[.+\].*/
|
9
47
|
end
|
10
48
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if params[:process_name].nil? then
|
15
|
-
puts "*** Process Name parameter missing, process_name"
|
16
|
-
puts "*** :process_name => <name of the process to be monitored>"
|
17
|
-
abort
|
18
|
-
end
|
19
|
-
@process_name = params[:process_name]
|
20
|
-
|
21
|
-
puts "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}"
|
22
|
-
|
23
|
-
unless (@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0 then
|
24
|
-
puts "*** Process Name parameter doest not match the required pattern, #{@process_name}"
|
25
|
-
puts "*** :process_name => <plain string, or a string with one or more characters enclosed in square brackets, i.e. 'foo', '[f]oo' or '[foo]'>"
|
26
|
-
abort
|
27
|
-
end
|
28
|
-
|
29
|
-
puts "*** Min value will be ignored, setting to 1" unless (params[:min].nil? || params[:min] == 0)
|
30
|
-
@min = 1
|
31
|
-
|
32
|
-
puts "*** Max value will be ignored, setting to nil" unless params[:max].nil?
|
33
|
-
@max = nil
|
34
|
-
|
35
|
-
@context_sentence = "Checking that process is running, #{@process_name}"
|
36
|
-
|
37
|
-
self.sanitise
|
38
|
-
rescue MonitorTypeExceptionHandled => e
|
39
|
-
puts e.message
|
40
|
-
abort
|
41
|
-
end
|
42
|
-
|
43
|
-
def getValue
|
44
|
-
return `ps aux | grep #{@process_name}`.length
|
45
|
-
end
|
49
|
+
def getValue
|
50
|
+
return `ps aux | grep #{@process_name}`.length
|
51
|
+
end
|
46
52
|
|
47
53
|
end
|
48
54
|
|
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.
|
4
|
+
version: 0.0.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: parse-cron
|
16
|
+
requirement: &70139175033600 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139175033600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: beanstalk-client
|
27
|
+
requirement: &70139175033160 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70139175033160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fluiddb
|
38
|
+
requirement: &70139175032720 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70139175032720
|
14
47
|
description: The fastest way to reliably monitor your system.
|
15
48
|
email: guy@guyirvine.com
|
16
49
|
executables:
|
@@ -24,6 +57,7 @@ files:
|
|
24
57
|
- lib/MonitorManager.rb
|
25
58
|
- lib/MonitorType/Beanstalk.rb
|
26
59
|
- lib/MonitorType/Dir.rb
|
60
|
+
- lib/MonitorType/Drive.rb
|
27
61
|
- lib/MonitorType/FluidDb.rb
|
28
62
|
- lib/MonitorType/Process.rb
|
29
63
|
- lib/MonitorType/Threshold.rb
|