evented_bluepill 0.0.47 → 0.0.50
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/DESIGN.md +2 -2
- data/README.md +35 -37
- data/Rakefile +9 -0
- data/bin/bluepill +9 -102
- data/bin/evented_bluepill +13 -0
- data/evented_bluepill.gemspec +10 -6
- data/{lib → example}/example.rb +4 -7
- data/{lib → example}/runit_example.rb +2 -2
- data/{bin → example}/sample_forking_server +2 -2
- data/lib/bluepill.rb +3 -31
- data/lib/{bluepill → evented_bluepill}/application/client.rb +1 -1
- data/lib/evented_bluepill/application/server.rb +24 -0
- data/lib/{bluepill → evented_bluepill}/application.rb +14 -14
- data/lib/{bluepill → evented_bluepill}/controller.rb +30 -20
- data/lib/{bluepill → evented_bluepill}/dsl/app_proxy.rb +3 -3
- data/lib/{bluepill → evented_bluepill}/dsl/process_factory.rb +8 -5
- data/lib/{bluepill → evented_bluepill}/dsl/process_proxy.rb +3 -3
- data/lib/{bluepill → evented_bluepill}/dsl.rb +5 -2
- data/lib/{bluepill → evented_bluepill}/event.rb +1 -1
- data/lib/{bluepill → evented_bluepill}/group.rb +2 -2
- data/lib/{bluepill → evented_bluepill}/logger.rb +5 -2
- data/lib/evented_bluepill/options.rb +121 -0
- data/lib/{bluepill → evented_bluepill}/process.rb +12 -16
- data/lib/{bluepill → evented_bluepill}/process_conditions/always_true.rb +7 -3
- data/lib/evented_bluepill/process_conditions/cpu_usage.rb +25 -0
- data/lib/{bluepill → evented_bluepill}/process_conditions/http.rb +8 -3
- data/lib/evented_bluepill/process_conditions/mem_usage.rb +41 -0
- data/lib/evented_bluepill/process_conditions/process_condition.rb +72 -0
- data/lib/{bluepill → evented_bluepill}/process_conditions.rb +2 -2
- data/lib/{bluepill → evented_bluepill}/process_statistics.rb +10 -10
- data/lib/{bluepill → evented_bluepill}/socket.rb +2 -1
- data/lib/{bluepill → evented_bluepill}/system.rb +24 -21
- data/lib/{bluepill → evented_bluepill}/trigger.rb +4 -4
- data/lib/{bluepill → evented_bluepill}/triggers/flapping.rb +3 -8
- data/lib/evented_bluepill/util/rotational_array.rb +21 -0
- data/lib/evented_bluepill/version.rb +12 -0
- data/lib/evented_bluepill.rb +22 -0
- data/spec/always_true_spec.rb +19 -0
- data/spec/cpu_usage_spec.rb +28 -0
- data/spec/mem_usage_spec.rb +46 -0
- data/spec/process_condition_spec.rb +30 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/system_spec.rb +15 -0
- metadata +137 -122
- data/lib/bluepill/application/server.rb +0 -26
- data/lib/bluepill/condition_watch.rb +0 -61
- data/lib/bluepill/process_conditions/cpu_usage.rb +0 -20
- data/lib/bluepill/process_conditions/mem_usage.rb +0 -33
- data/lib/bluepill/process_conditions/process_condition.rb +0 -23
- data/lib/bluepill/util/rotational_array.rb +0 -74
- data/lib/bluepill/version.rb +0 -5
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Bluepill
|
4
|
-
module Application
|
5
|
-
module ServerMethods
|
6
|
-
|
7
|
-
def status
|
8
|
-
buffer = ""
|
9
|
-
self.processes.each do | process |
|
10
|
-
buffer << "#{process.name} #{process.state}\n" +
|
11
|
-
end
|
12
|
-
buffer
|
13
|
-
end
|
14
|
-
|
15
|
-
def restart
|
16
|
-
self.socket = Bluepill::Socket.new(name, base_dir).client
|
17
|
-
socket.send("restart\n", 0)
|
18
|
-
end
|
19
|
-
|
20
|
-
def stop
|
21
|
-
self.socket = Bluepill::Socket.new(name, base_dir).client
|
22
|
-
socket.send("stop\n", 0)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'coolio'
|
4
|
-
|
5
|
-
module Bluepill
|
6
|
-
class ConditionWatch < Coolio::TimerWatcher
|
7
|
-
attr_accessor :logger, :name, :process
|
8
|
-
attr_reader :every, :process_condition, :fires
|
9
|
-
|
10
|
-
def initialize(name, process, options = {})
|
11
|
-
@name = name
|
12
|
-
|
13
|
-
@logger = options.delete(:logger)
|
14
|
-
@fires = options.delete(:fires) || :restart
|
15
|
-
@every = options.delete(:every)
|
16
|
-
@times = options.delete(:times) || [1,1]
|
17
|
-
@times = [@times, @times] unless @times.is_a?(Array) # handles :times => 5
|
18
|
-
@process = process
|
19
|
-
|
20
|
-
self.clear_history!
|
21
|
-
|
22
|
-
@process_condition = ProcessConditions[@name].new(options)
|
23
|
-
|
24
|
-
super(@every, true)
|
25
|
-
end
|
26
|
-
|
27
|
-
def on_timer
|
28
|
-
self.record_value(self.process_condition.run(@process.actual_pid))
|
29
|
-
if self.fired?
|
30
|
-
@process.dispatch!(self.fires, self.to_s)
|
31
|
-
logger.info "#{self.name} dispatched: #{self.fires}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def record_value(value)
|
36
|
-
# TODO: record value in ProcessStatistics
|
37
|
-
@history[@history_index] = [value, @process_condition.check(value)]
|
38
|
-
@history_index = (@history_index + 1) % @history.size
|
39
|
-
self.logger.info(self.to_s)
|
40
|
-
end
|
41
|
-
|
42
|
-
def clear_history!
|
43
|
-
@last_ran_at = nil
|
44
|
-
@history = Array.new(@times[1])
|
45
|
-
@history_index = 0
|
46
|
-
end
|
47
|
-
|
48
|
-
def fired?
|
49
|
-
@history.select {|v| v && !v[1]}.size >= @times[0]
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_s
|
53
|
-
# TODO: this will be out of order because of the way history values are assigned
|
54
|
-
# use (@history[(@history_index - 1)..1] + @history[0..(@history_index - 1)]).
|
55
|
-
# collect {|v| "#{v[0]}#{v[1] ? '' : '*'}"}.join(", ")
|
56
|
-
# but that's gross so... it's gonna be out of order till we figure out a better way to get it in order
|
57
|
-
data = @history.collect {|v| "#{@process_condition.format_value(v[0])}#{v[1] ? '' : '*'}" if v}.compact.join(", ")
|
58
|
-
"#{@name}: [#{data}]"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Bluepill
|
4
|
-
module ProcessConditions
|
5
|
-
class CpuUsage < ProcessCondition
|
6
|
-
def initialize(options = {})
|
7
|
-
@below = options[:below]
|
8
|
-
end
|
9
|
-
|
10
|
-
def run(pid)
|
11
|
-
# third col in the ps axu output
|
12
|
-
System.cpu_usage(pid).to_f
|
13
|
-
end
|
14
|
-
|
15
|
-
def check(value)
|
16
|
-
value < @below
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Bluepill
|
4
|
-
module ProcessConditions
|
5
|
-
class MemUsage < ProcessCondition
|
6
|
-
MB = 1024 ** 2
|
7
|
-
FORMAT_STR = "%d%s"
|
8
|
-
MB_LABEL = "MB"
|
9
|
-
KB_LABEL = "KB"
|
10
|
-
|
11
|
-
def initialize(options = {})
|
12
|
-
@below = options[:below]
|
13
|
-
end
|
14
|
-
|
15
|
-
def run(pid)
|
16
|
-
# rss is on the 5th col
|
17
|
-
System.memory_usage(pid).to_f
|
18
|
-
end
|
19
|
-
|
20
|
-
def check(value)
|
21
|
-
value.kilobytes < @below
|
22
|
-
end
|
23
|
-
|
24
|
-
def format_value(value)
|
25
|
-
if value.kilobytes >= MB
|
26
|
-
FORMAT_STR % [(value / 1024).round, MB_LABEL]
|
27
|
-
else
|
28
|
-
FORMAT_STR % [value, KB_LABEL]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Bluepill
|
4
|
-
module ProcessConditions
|
5
|
-
class ProcessCondition
|
6
|
-
def initialize(options = {})
|
7
|
-
@options = options
|
8
|
-
end
|
9
|
-
|
10
|
-
def run(pid)
|
11
|
-
raise "Implement in subclass!"
|
12
|
-
end
|
13
|
-
|
14
|
-
def check(value)
|
15
|
-
raise "Implement in subclass!"
|
16
|
-
end
|
17
|
-
|
18
|
-
def format_value(value)
|
19
|
-
value
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Bluepill
|
4
|
-
module Util
|
5
|
-
class RotationalArray < Array
|
6
|
-
def initialize(size)
|
7
|
-
super(size)
|
8
|
-
|
9
|
-
@capacity = size
|
10
|
-
@counter = 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def push(value)
|
14
|
-
idx = rotational_idx(@counter)
|
15
|
-
self[idx] = value
|
16
|
-
|
17
|
-
@counter += 1
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
alias_method :<<, :push
|
22
|
-
|
23
|
-
def pop
|
24
|
-
raise "Cannot call pop on a rotational array"
|
25
|
-
end
|
26
|
-
|
27
|
-
def shift
|
28
|
-
raise "Cannot call shift on a rotational array"
|
29
|
-
end
|
30
|
-
|
31
|
-
def unshift
|
32
|
-
raise "Cannot call unshift on a rotational array"
|
33
|
-
end
|
34
|
-
|
35
|
-
def last
|
36
|
-
return if @counter.zero?
|
37
|
-
|
38
|
-
self[rotational_idx(@counter - 1)]
|
39
|
-
end
|
40
|
-
|
41
|
-
def first
|
42
|
-
return if @counter.zero?
|
43
|
-
return self[0] if @counter <= @capacity
|
44
|
-
|
45
|
-
self[rotational_idx(@counter)]
|
46
|
-
end
|
47
|
-
|
48
|
-
def clear
|
49
|
-
@counter = 0
|
50
|
-
super
|
51
|
-
end
|
52
|
-
|
53
|
-
def each(&block)
|
54
|
-
times = @counter >= @capacity ? @capacity : @counter
|
55
|
-
start = @counter >= @capacity ? rotational_idx(@counter) : 0
|
56
|
-
times.times do |i|
|
57
|
-
block.call(self[rotational_idx(start + i)])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
unless method_defined?(:nitems)
|
62
|
-
def nitems
|
63
|
-
compact.length
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def rotational_idx(idx)
|
70
|
-
idx % @capacity
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|