srvmonitor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  .yardoc
2
+ *.gem
3
+
data/README.markdown CHANGED
@@ -1,6 +1,58 @@
1
1
  # Srvconfig
2
2
  Based on outpost (https://github.com/vinibaggio/outpost)
3
3
 
4
+ ## Example
5
+ ```ruby
6
+ require 'srvmonitor'
7
+ require 'srvmonitor/scouts'
8
+
9
+ # define your servers
10
+ server1 = SrvMonitor::Server.new(:name => 'first server', :description => 'web server', :host => '192.168.0.1', :method => :local, :user => 'deployer')
11
+ server2 = SrvMonitor::Server.new(:name => 'second server', :description => 'node server', :host => '192.168.0.2', :method => :local, :user => 'deployer')
12
+
13
+ # define your applications
14
+ railswatch = SrvMonitor::Application.create do
15
+ name 'Rails Watch'
16
+ scout SrvMonitor::Scouts::TimedHttp, :port => 80, :path => '/', :timeout => 15
17
+ report :up, :response_code => 200
18
+
19
+ server server1, :port => 3000, :method => :local
20
+ server server2, :method => :local
21
+ end
22
+
23
+ loadwatch = SrvMonitor::Application.create do
24
+ name 'Load Watch'
25
+ scout SrvMonitor::Scouts::LoadAverage
26
+ report :up, :load_average => { :less_than => 50 }
27
+
28
+ servers server1, server2, :method => :remote
29
+ end
30
+
31
+ # create the monitor
32
+ SrvMonitor::Monitor.create do
33
+ notifier SrvMonitor::Notifiers::Mailer, {
34
+ :delivery_method => 'smtp',
35
+ :address => 'smtp.gmail.com',
36
+ :port => '587',
37
+ :authentication => 'plain',
38
+ :username => 'username@gmail.com',
39
+ :password => 'password',
40
+ :enable_starttls_auto => true,
41
+ :to => 'you@gmail.com',
42
+ :status => :down }
43
+
44
+ alert :if => :down, :attempts => 5
45
+ applications railswatch, loadwatch
46
+
47
+ forever true
48
+ wait 5
49
+
50
+ run
51
+ end
52
+
53
+ ```
54
+
55
+
4
56
  ## License
5
57
 
6
58
  MIT License.
@@ -19,7 +19,12 @@ module SrvMonitor
19
19
  # Method that will be used as an expectation to evaluate load average
20
20
  def evaluate_load_average(scout, rules)
21
21
  rules.all? do |rule, comparison|
22
- scout.load_average.send(LOAD_AVERAGE_MAPPING[rule], comparison)
22
+ case rule
23
+ when :less_than
24
+ scout.load_average < comparison
25
+ when :more_than
26
+ scout.load_average > comparison
27
+ end
23
28
  end
24
29
  end
25
30
  end
@@ -48,11 +48,9 @@ module SrvMonitor
48
48
  end
49
49
  end
50
50
 
51
- # Issues a notification through email. This is a callback, called by
52
- # an Outpost instance.
53
- # @param [Outpost::Application, #read] outpost an instance of an outpost, containing
54
- # latest status, messages and reports that can be queried to build
55
- # a notification message.
51
+ # Issues a notification through email. This is a callback, called by an Outpost instance.
52
+ # @param [SrvMonitor::Monitor, #read] outpost an instance of an outpost, containing
53
+ # latest status, messages and reports that can be queried to build a notification message.
56
54
  def send(monitor)
57
55
  smtp_connect! if @delivery_method == :smtp
58
56
 
@@ -62,8 +60,6 @@ module SrvMonitor
62
60
  mail.subject = @subject
63
61
  mail.body = build_message(monitor)
64
62
 
65
- #mail.delivery_method @delivery_method
66
-
67
63
  mail.deliver
68
64
  end
69
65
 
@@ -1,5 +1,5 @@
1
1
  module SrvMonitor
2
- # Contain the status report of an Outpost execution. Holds the name,
2
+ # Contain the status report of an SrvMonitor execution. Holds the name,
3
3
  # description and status of the reported item.
4
4
  class Report
5
5
  # Summarizes the list of statuses in a single status only.
@@ -37,8 +37,10 @@ module SrvMonitor
37
37
  raise NotImplementedError, "expectation '#{expectation}' wasn't implemented by #{self.class.name}"
38
38
  end
39
39
 
40
- if self.class.expectations[expectation].call(self, value)
41
- statuses << status
40
+ begin
41
+ statuses << status if self.class.expectations[expectation].call(self, value)
42
+ rescue
43
+ statuses << :down
42
44
  end
43
45
  end
44
46
  end
@@ -6,7 +6,6 @@ module SrvMonitor
6
6
  extend SrvMonitor::Expectations::LoadAverage
7
7
 
8
8
  attr_reader :load_average
9
- #report_data :load_average
10
9
 
11
10
  # Configure the scout with given options.
12
11
  # @param [Hash] Options to setup the scout
@@ -33,6 +32,8 @@ module SrvMonitor
33
32
  def local_exec
34
33
  loadavg = File.open('/proc/loadavg').read
35
34
  @load_average = loadavg.split(' ').first.to_f
35
+ rescue
36
+ @load_average = nil
36
37
  end
37
38
 
38
39
  def remote_exec
@@ -40,6 +41,8 @@ module SrvMonitor
40
41
  loadavg = ssh.exec!('cat /proc/loadavg')
41
42
  @load_average = loadavg.split(' ').first.to_f
42
43
  end
44
+ rescue
45
+ @load_average = nil
43
46
  end
44
47
 
45
48
  end
@@ -11,7 +11,6 @@ module SrvMonitor
11
11
  extend SrvMonitor::Expectations::ResponseTime
12
12
 
13
13
  attr_reader :response_code, :response_body, :response_time
14
- #report_data :response_code, :response_body, :response_time
15
14
 
16
15
  # Configure the scout with given options.
17
16
  # @param [Hash] Options to setup the scout
@@ -29,17 +28,11 @@ module SrvMonitor
29
28
  end
30
29
 
31
30
  def execute
32
- previous_time = Time.now
33
- Timeout::timeout(@timeout) do
34
- case
35
- when remote? then remote_exec
36
- when local? then local_exec
37
- end
31
+ case
32
+ when remote? then remote_exec
33
+ when local? then local_exec
38
34
  end
39
- rescue Timeout::Error
40
- @response_time = (Time.now - previous_time).round
41
- @response_code = @response_body = nil
42
- rescue SocketError, Errno::ECONNREFUSED
35
+ rescue
43
36
  @response_code = @response_body = @response_time = nil
44
37
  end
45
38
 
@@ -52,20 +45,33 @@ module SrvMonitor
52
45
  private
53
46
  def local_exec
54
47
  previous_time = Time.now
55
- response = @http_class.get_response(@host, @path, @port)
56
- @response_time = (Time.now - previous_time) * 1000 # Miliseconds
57
- @response_code = response.code.to_i
58
- @response_body = response.body
48
+ Timeout::timeout(@timeout) do
49
+ response = @http_class.get_response(@host, @path, @port)
50
+ @response_time = (Time.now - previous_time) * 1000 # Miliseconds
51
+ @response_code = response.code.to_i
52
+ @response_body = response.body
53
+ rescue Timeout::Error
54
+ @response_time = (Time.now - previous_time).round
55
+ @response_code = @response_body = nil
56
+ rescue
57
+ @response_code = @response_body = @response_time = nil
59
58
  end
60
59
 
61
60
  # Runs the scout, connecting to the host and getting the response code, body and time.
62
61
  def remote_exec
62
+ previous_time = Time.now
63
+ Timeout::timeout(@timeout) do
63
64
  server.exec do |ssh|
64
65
  response = ssh.exec!("curl --write-out %{http_code}:%{time_total} --silent --output /dev/null #{ url }")
65
66
  @response_code = response.split(':').first.to_i
66
67
  @response_time = response.split(':').last.to_f * 1000
67
68
  @response_body = ssh.exec!("curl #{ url }")
68
69
  end
70
+ rescue Timeout::Error
71
+ @response_time = (Time.now - previous_time).round
72
+ @response_code = @response_body = nil
73
+ rescue
74
+ @response_code = @response_body = @response_time = nil
69
75
  end
70
76
 
71
77
  def url
@@ -1,5 +1,5 @@
1
1
  module SrvMonitor
2
- PATCH = 1
2
+ PATCH = 2
3
3
  MINOR = 0
4
4
  MAJOR = 0
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srvmonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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: 2011-09-12 00:00:00.000000000Z
12
+ date: 2011-09-21 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Server monitor.
15
15
  email: clickjogos@clickjogos.com.br