eye 0.5.1 → 0.5.2
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 +4 -4
- data/.gitignore +2 -0
- data/CHANGES.md +6 -0
- data/README.md +37 -35
- data/examples/puma.eye +1 -1
- data/examples/test.eye +32 -30
- data/examples/unicorn.eye +1 -1
- data/lib/eye.rb +1 -1
- data/lib/eye/checker.rb +24 -1
- data/lib/eye/checker/cpu.rb +4 -14
- data/lib/eye/checker/cputime.rb +2 -12
- data/lib/eye/checker/file_ctime.rb +2 -3
- data/lib/eye/checker/file_size.rb +8 -8
- data/lib/eye/checker/http.rb +2 -2
- data/lib/eye/checker/memory.rb +4 -14
- data/lib/eye/checker/runtime.rb +2 -12
- data/lib/eye/checker/socket.rb +1 -1
- data/lib/eye/cli.rb +6 -0
- data/lib/eye/cli/commands.rb +2 -3
- data/lib/eye/cli/render.rb +4 -4
- data/lib/eye/cli/server.rb +4 -4
- data/lib/eye/controller.rb +1 -1
- data/lib/eye/controller/load.rb +14 -13
- data/lib/eye/controller/send_command.rb +4 -4
- data/lib/eye/controller/status.rb +2 -1
- data/lib/eye/dsl.rb +1 -1
- data/lib/eye/dsl/child_process_opts.rb +2 -2
- data/lib/eye/dsl/opts.rb +5 -1
- data/lib/eye/dsl/validation.rb +2 -2
- data/lib/eye/group/chain.rb +2 -2
- data/lib/eye/notify.rb +3 -3
- data/lib/eye/process.rb +7 -7
- data/lib/eye/process/children.rb +60 -0
- data/lib/eye/process/commands.rb +40 -37
- data/lib/eye/process/config.rb +5 -5
- data/lib/eye/process/controller.rb +8 -8
- data/lib/eye/process/data.rb +4 -4
- data/lib/eye/process/monitor.rb +17 -17
- data/lib/eye/process/scheduler.rb +1 -1
- data/lib/eye/process/states.rb +3 -3
- data/lib/eye/process/system.rb +3 -3
- data/lib/eye/process/validate.rb +1 -1
- data/lib/eye/process/watchers.rb +6 -6
- data/lib/eye/server.rb +1 -1
- data/lib/eye/system.rb +4 -4
- data/lib/eye/system_resources.rb +3 -3
- data/lib/eye/trigger.rb +4 -6
- data/lib/eye/trigger/flapping.rb +2 -2
- data/lib/eye/trigger/stop_children.rb +14 -0
- metadata +4 -4
- data/lib/eye/process/child.rb +0 -60
- data/lib/eye/trigger/stop_childs.rb +0 -10
data/lib/eye/process/states.rb
CHANGED
@@ -61,8 +61,8 @@ class Eye::Process
|
|
61
61
|
after_transition any-:up => :up, :do => :add_watchers
|
62
62
|
after_transition :up => any-:up, :do => :remove_watchers
|
63
63
|
|
64
|
-
after_transition any-:up => :up, :do => :
|
65
|
-
after_transition any => [:unmonitored, :down], :do => :
|
64
|
+
after_transition any-:up => :up, :do => :add_children
|
65
|
+
after_transition any => [:unmonitored, :down], :do => :remove_children
|
66
66
|
|
67
67
|
after_transition :on => :crashed, :do => :on_crashed
|
68
68
|
end
|
@@ -80,4 +80,4 @@ class Eye::Process
|
|
80
80
|
info "switch :#{transition.event} [:#{transition.from_name} => :#{transition.to_name}] #{@state_reason ? "(reason: #{@state_reason})" : nil}"
|
81
81
|
end
|
82
82
|
|
83
|
-
end
|
83
|
+
end
|
data/lib/eye/process/system.rb
CHANGED
@@ -36,9 +36,9 @@ module Eye::Process::System
|
|
36
36
|
File.ctime(self[:pid_file_ex]) rescue Time.now
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def process_really_running?
|
40
40
|
res = Eye::System.check_pid_alive(self.pid)
|
41
|
-
debug "
|
41
|
+
debug "process_really_running?: (#{self.pid}) #{res.inspect}"
|
42
42
|
!!res[:result]
|
43
43
|
end
|
44
44
|
|
@@ -90,4 +90,4 @@ module Eye::Process::System
|
|
90
90
|
false
|
91
91
|
end
|
92
92
|
|
93
|
-
end
|
93
|
+
end
|
data/lib/eye/process/validate.rb
CHANGED
@@ -12,7 +12,7 @@ module Eye::Process::Validate
|
|
12
12
|
|
13
13
|
if config[:daemonize]
|
14
14
|
if spl =~ %r[sh#\-c|#&&#|;#]
|
15
|
-
raise Error, "#{config[:name]},
|
15
|
+
raise Error, "#{config[:name]}, daemonize does not support concats like '&&' in start_command"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/eye/process/watchers.rb
CHANGED
@@ -11,17 +11,17 @@ module Eye::Process::Watchers
|
|
11
11
|
check_alive
|
12
12
|
end
|
13
13
|
|
14
|
-
# monitor
|
14
|
+
# monitor children pids
|
15
15
|
if self[:monitor_children]
|
16
|
-
add_watcher(:
|
17
|
-
|
16
|
+
add_watcher(:check_children, self[:children_update_period]) do
|
17
|
+
add_or_update_children
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
# monitor conditional watchers
|
22
22
|
start_checkers
|
23
23
|
else
|
24
|
-
warn '
|
24
|
+
warn 'add_watchers failed, watchers are already present'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -35,7 +35,7 @@ private
|
|
35
35
|
def add_watcher(type, period = 2, subject = nil, &block)
|
36
36
|
return if @watchers[type]
|
37
37
|
|
38
|
-
debug "
|
38
|
+
debug "adding watcher: #{type}(#{period})"
|
39
39
|
|
40
40
|
timer = every(period.to_f) do
|
41
41
|
debug "check #{type}"
|
@@ -69,4 +69,4 @@ private
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
end
|
72
|
+
end
|
data/lib/eye/server.rb
CHANGED
data/lib/eye/system.rb
CHANGED
@@ -4,7 +4,7 @@ require 'etc'
|
|
4
4
|
|
5
5
|
module Eye::System
|
6
6
|
class << self
|
7
|
-
# Check that pid
|
7
|
+
# Check that pid really exits
|
8
8
|
# very fast
|
9
9
|
# return result hash
|
10
10
|
def check_pid_alive(pid)
|
@@ -19,7 +19,7 @@ module Eye::System
|
|
19
19
|
{:error => ex}
|
20
20
|
end
|
21
21
|
|
22
|
-
# Check that pid
|
22
|
+
# Check that pid really exits
|
23
23
|
# very fast
|
24
24
|
# return true/false
|
25
25
|
def pid_alive?(pid)
|
@@ -86,7 +86,7 @@ module Eye::System
|
|
86
86
|
|
87
87
|
rescue Timeout::Error => ex
|
88
88
|
if pid
|
89
|
-
warn "[#{cfg[:name]}]
|
89
|
+
warn "[#{cfg[:name]}] sending :KILL signal to <#{pid}> due to timeout (#{timeout}s)"
|
90
90
|
send_signal(pid, 9)
|
91
91
|
end
|
92
92
|
{:error => ex}
|
@@ -132,4 +132,4 @@ module Eye::System
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
end
|
135
|
+
end
|
data/lib/eye/system_resources.rb
CHANGED
@@ -15,8 +15,8 @@ class Eye::SystemResources
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
cache.
|
18
|
+
def children(parent_pid)
|
19
|
+
cache.children(parent_pid)
|
20
20
|
end
|
21
21
|
|
22
22
|
def start_time(pid) # unixtime
|
@@ -79,7 +79,7 @@ class Eye::SystemResources
|
|
79
79
|
rescue ArgumentError # when incorrect PID
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
82
|
+
def children(pid)
|
83
83
|
if pid
|
84
84
|
@ppids[pid] ||= Eye::Sigar.proc_list("State.Ppid.eq=#{pid}")
|
85
85
|
else
|
data/lib/eye/trigger.rb
CHANGED
@@ -3,11 +3,9 @@ class Eye::Trigger
|
|
3
3
|
|
4
4
|
autoload :Flapping, 'eye/trigger/flapping'
|
5
5
|
autoload :Transition, 'eye/trigger/transition'
|
6
|
-
autoload :
|
6
|
+
autoload :StopChildren, 'eye/trigger/stop_children'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
TYPES = {:flapping => 'Flapping', :transition => 'Transition', :stop_childs => 'StopChilds'}
|
8
|
+
TYPES = {:flapping => 'Flapping', :transition => 'Transition', :stop_children => 'StopChildren'}
|
11
9
|
|
12
10
|
attr_reader :message, :options, :process
|
13
11
|
|
@@ -23,7 +21,7 @@ class Eye::Trigger
|
|
23
21
|
|
24
22
|
def self.get_class(type)
|
25
23
|
klass = eval("Eye::Trigger::#{TYPES[type]}") rescue nil
|
26
|
-
raise "
|
24
|
+
raise "unknown trigger #{type}" unless klass
|
27
25
|
if deps = klass.depends_on
|
28
26
|
Array(deps).each { |d| require d }
|
29
27
|
end
|
@@ -86,7 +84,7 @@ class Eye::Trigger
|
|
86
84
|
end
|
87
85
|
|
88
86
|
def check(transition)
|
89
|
-
raise
|
87
|
+
raise NotImplementedError
|
90
88
|
end
|
91
89
|
|
92
90
|
def run_in_process_context(p)
|
data/lib/eye/trigger/flapping.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Eye::Trigger::Flapping < Eye::Trigger
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# trigger :flapping, :times => 10, :within => 1.minute,
|
4
|
+
# :retry_in => 10.minutes, :retry_times => 15
|
5
5
|
|
6
6
|
param :times, [Fixnum], true, 5
|
7
7
|
param :within, [Float, Fixnum], true
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Eye::Trigger::StopChildren < Eye::Trigger
|
2
|
+
|
3
|
+
# Kill process children when parent process crashed, or stopped:
|
4
|
+
#
|
5
|
+
# trigger :stop_children, :event => [:stopped, :crashed]
|
6
|
+
|
7
|
+
param :timeout, [Fixnum, Float], nil, 60
|
8
|
+
|
9
|
+
def check(trans)
|
10
|
+
debug 'stopping children'
|
11
|
+
process.children.pmap { |pid, c| c.stop }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Makarchev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -343,7 +343,7 @@ files:
|
|
343
343
|
- lib/eye/notify/jabber.rb
|
344
344
|
- lib/eye/notify/mail.rb
|
345
345
|
- lib/eye/process.rb
|
346
|
-
- lib/eye/process/
|
346
|
+
- lib/eye/process/children.rb
|
347
347
|
- lib/eye/process/commands.rb
|
348
348
|
- lib/eye/process/config.rb
|
349
349
|
- lib/eye/process/controller.rb
|
@@ -364,7 +364,7 @@ files:
|
|
364
364
|
- lib/eye/system_resources.rb
|
365
365
|
- lib/eye/trigger.rb
|
366
366
|
- lib/eye/trigger/flapping.rb
|
367
|
-
- lib/eye/trigger/
|
367
|
+
- lib/eye/trigger/stop_children.rb
|
368
368
|
- lib/eye/trigger/transition.rb
|
369
369
|
- lib/eye/utils.rb
|
370
370
|
- lib/eye/utils/alive_array.rb
|
data/lib/eye/process/child.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
module Eye::Process::Child
|
2
|
-
|
3
|
-
def add_childs
|
4
|
-
add_or_update_childs
|
5
|
-
end
|
6
|
-
|
7
|
-
def add_or_update_childs
|
8
|
-
return unless self[:monitor_children]
|
9
|
-
return unless self.up?
|
10
|
-
return if @updating_childs
|
11
|
-
@updating_childs = true
|
12
|
-
|
13
|
-
unless self.pid
|
14
|
-
warn 'Cant add childs, because no pid'
|
15
|
-
return
|
16
|
-
end
|
17
|
-
|
18
|
-
now_childs = Eye::SystemResources.childs(self.pid)
|
19
|
-
new_childs = []
|
20
|
-
exist_childs = []
|
21
|
-
|
22
|
-
now_childs.each do |child_pid|
|
23
|
-
if self.childs[child_pid]
|
24
|
-
exist_childs << child_pid
|
25
|
-
else
|
26
|
-
new_childs << child_pid
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
removed_childs = self.childs.keys - now_childs
|
31
|
-
|
32
|
-
if new_childs.present?
|
33
|
-
new_childs.each do |child_pid|
|
34
|
-
self.childs[child_pid] = Eye::ChildProcess.new(child_pid, self[:monitor_children], logger.prefix)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
if removed_childs.present?
|
39
|
-
removed_childs.each{|child_pid| remove_child(child_pid) }
|
40
|
-
end
|
41
|
-
|
42
|
-
h = {:new => new_childs.size, :removed => removed_childs.size, :exists => exist_childs.size }
|
43
|
-
debug "childs info: #{ h.inspect }"
|
44
|
-
|
45
|
-
@updating_childs = false
|
46
|
-
h
|
47
|
-
end
|
48
|
-
|
49
|
-
def remove_childs
|
50
|
-
if childs.present?
|
51
|
-
childs.keys.each{|child_pid| remove_child(child_pid) }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def remove_child(child_pid)
|
56
|
-
child = self.childs.delete(child_pid)
|
57
|
-
child.destroy if child && child.alive?
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|