phantom-manager 0.0.2 → 0.0.3
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 +8 -8
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/monitors/memory.rb +1 -1
- data/lib/monitors/processes.rb +1 -1
- data/lib/monitors/restart_listener.rb +1 -1
- data/lib/monitors/violations_recorders/memory.rb +2 -2
- data/lib/monitors/violations_recorders/processes.rb +1 -1
- data/lib/nginx/manager.rb +4 -4
- data/lib/phantom/collector.rb +1 -1
- data/lib/phantom/manager/version.rb +1 -1
- data/lib/phantom/manager.rb +1 -1
- data/lib/phantom/process.rb +1 -1
- data/lib/utils/cfg.rb +20 -10
- data/spec/lib/monitors/memory_spec.rb +4 -4
- data/spec/lib/monitors/processes_spec.rb +1 -1
- data/spec/lib/monitors/violations_recorders/memory_spec.rb +6 -6
- data/spec/lib/monitors/violations_recorders/processes_spec.rb +3 -3
- data/spec/lib/nginx/manager_spec.rb +2 -2
- data/spec/lib/phantom/collector_spec.rb +2 -2
- data/spec/lib/utils/cfg_spec.rb +15 -0
- data/spec/shared_spec.rb +2 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTMwOTMzODZlNjhlMzhiYTZiODM1ZTZlZGNkMTk4Y2JmODY4MjlmMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmI1Nzk1ZWQwNDcwMzA5OWJmZDE1YTk1MDg4Y2MzYjIxNGNlYzBjMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTU4MDg4MGUyOTFhZDE2YjFmYjA1OTQ2NjQyMTQzNjQxMWI2ZWI4ZTMxNDAz
|
10
|
+
YWJlYjRhNjM5OTg5NTJhYzQ1MWZhYzMyNTE3ZWU5Zjc2NzBmMTAyYzQyYzE1
|
11
|
+
Njg3YzA4ZGI5MGQyZmM1ZmE0ZjEwZGEwNjM3ZGZjY2U4YjVlMGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDRjYmYzNjdkMWUyODkxZGVhNzRkMjkwMjIxMmUxNjNkMDE3YjM1YWRiZGUw
|
14
|
+
ZDY1ODZiY2RhOTE3ODE1YTA1ODVmY2ZkMTMwMGMyOGE4ODVmYWViMmFkMjVj
|
15
|
+
ODI5ZjViMTBmOTUyYWExOGUzYzNmOTBmMDU3NTIzOTViMGJhYmE=
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/monitors/memory.rb
CHANGED
data/lib/monitors/processes.rb
CHANGED
@@ -6,7 +6,7 @@ module Monitors
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def retries_limit
|
9
|
-
|
9
|
+
Cfg.memory_retries
|
10
10
|
end
|
11
11
|
|
12
12
|
def process_attr
|
@@ -14,7 +14,7 @@ module Monitors
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def process_is_violating?(process)
|
17
|
-
process.memory_usage >
|
17
|
+
process.memory_usage > Cfg.memory_limit
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
data/lib/nginx/manager.rb
CHANGED
@@ -31,12 +31,12 @@ module Nginx
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def port_defined?(port)
|
34
|
-
File.readlines(
|
34
|
+
File.readlines(Cfg.nginx_conf).grep(/#{port}/).size > 0
|
35
35
|
end
|
36
36
|
|
37
37
|
def switch_nginx_configs
|
38
38
|
$logger.info "switching nginx configurations"
|
39
|
-
`mv #{
|
39
|
+
`mv #{Cfg.new_nginx_conf} #{Cfg.nginx_conf}`
|
40
40
|
end
|
41
41
|
|
42
42
|
def reload_nginx
|
@@ -45,8 +45,8 @@ module Nginx
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def modify_nginx
|
48
|
-
File.open(
|
49
|
-
File.foreach(
|
48
|
+
File.open(Cfg.new_nginx_conf, "w") do |ofile|
|
49
|
+
File.foreach(Cfg.nginx_conf) do |iline|
|
50
50
|
yield ofile, iline
|
51
51
|
end
|
52
52
|
end
|
data/lib/phantom/collector.rb
CHANGED
data/lib/phantom/manager.rb
CHANGED
data/lib/phantom/process.rb
CHANGED
data/lib/utils/cfg.rb
CHANGED
@@ -2,17 +2,27 @@ require 'ostruct'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
class Cfg
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def method_missing(method_sym, *arguments, &block)
|
8
|
+
cfg.send(method_sym, *arguments, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def cfg
|
12
|
+
@cfg ||= Cfg.load
|
11
13
|
end
|
12
|
-
obj = OpenStruct.new hash
|
13
|
-
obj.new_nginx_conf = "#{obj.nginx_conf}.new"
|
14
14
|
|
15
|
-
|
15
|
+
def load
|
16
|
+
cfg = File.expand_path($options[:config])
|
17
|
+
env = $options[:env]
|
18
|
+
hash = YAML.load(File.open(cfg))[env]
|
19
|
+
hash.each do |k,v|
|
20
|
+
hash[k] = v.to_i if v =~ /^\d+$/
|
21
|
+
end
|
22
|
+
obj = OpenStruct.new hash
|
23
|
+
obj.new_nginx_conf = "#{obj.nginx_conf}.new"
|
24
|
+
|
25
|
+
@cfg = obj
|
26
|
+
end
|
16
27
|
end
|
17
28
|
end
|
18
|
-
Cfg.load
|
@@ -9,22 +9,22 @@ module Monitors
|
|
9
9
|
|
10
10
|
before do
|
11
11
|
Phantom::Collector.stub(:running_phantoms_shell_output).and_return(phantoms_ps_shell_output)
|
12
|
-
|
13
|
-
|
12
|
+
Cfg.memory_limit = 110000
|
13
|
+
Cfg.memory_retries = 3
|
14
14
|
end
|
15
15
|
|
16
16
|
describe :perform_check do
|
17
17
|
context "below memory_retries" do
|
18
18
|
it "should not restart processes" do
|
19
19
|
Phantom::Manager.should_not_receive(:restart)
|
20
|
-
(
|
20
|
+
( Cfg.memory_retries - 1 ).times { subject.perform_check }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context "at memory_retries" do
|
25
25
|
it "should restart process" do
|
26
26
|
Phantom::Manager.should_receive(:restart).once
|
27
|
-
|
27
|
+
Cfg.memory_retries.times { subject.perform_check }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -13,8 +13,8 @@ module Monitors
|
|
13
13
|
|
14
14
|
describe :is_violating? do
|
15
15
|
|
16
|
-
let(:violating_memory) {
|
17
|
-
let(:valid_memory) {
|
16
|
+
let(:violating_memory) { Cfg.memory_limit + 10}
|
17
|
+
let(:valid_memory) { Cfg.memory_limit - 10}
|
18
18
|
|
19
19
|
context "violating process" do
|
20
20
|
|
@@ -24,7 +24,7 @@ module Monitors
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return true" do
|
27
|
-
(
|
27
|
+
(Cfg.memory_retries-1).times do
|
28
28
|
subject.is_violating?(@p).should be_false
|
29
29
|
end
|
30
30
|
|
@@ -40,7 +40,7 @@ module Monitors
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should return false" do
|
43
|
-
|
43
|
+
Cfg.memory_retries.times do
|
44
44
|
subject.is_violating?(@p).should be_false
|
45
45
|
end
|
46
46
|
end
|
@@ -49,7 +49,7 @@ module Monitors
|
|
49
49
|
|
50
50
|
it "reset violations if valid memory detected one" do
|
51
51
|
@p.memory_usage = violating_memory
|
52
|
-
(
|
52
|
+
(Cfg.memory_retries-1).times do
|
53
53
|
subject.is_violating?(@p).should be_false
|
54
54
|
end
|
55
55
|
|
@@ -58,7 +58,7 @@ module Monitors
|
|
58
58
|
subject.is_violating?(@p).should be_false
|
59
59
|
|
60
60
|
@p.memory_usage = violating_memory
|
61
|
-
(
|
61
|
+
(Cfg.memory_retries-1).times do
|
62
62
|
subject.is_violating?(@p).should be_false
|
63
63
|
end
|
64
64
|
subject.is_violating?(@p).should be_true
|
@@ -18,11 +18,11 @@ module Monitors
|
|
18
18
|
Phantom::Collector.stub(:missing_ports).and_return([8004])
|
19
19
|
@p = Phantom::Process.new
|
20
20
|
@p.port = 8004
|
21
|
-
|
21
|
+
Cfg.processes_check_retries = 3
|
22
22
|
end
|
23
23
|
|
24
24
|
context "below retries limit" do
|
25
|
-
let(:retries) {
|
25
|
+
let(:retries) {Cfg.processes_check_retries - 1}
|
26
26
|
|
27
27
|
it "should return false" do
|
28
28
|
retries.times do
|
@@ -34,7 +34,7 @@ module Monitors
|
|
34
34
|
|
35
35
|
context "equals retries limit" do
|
36
36
|
|
37
|
-
let(:retries) {
|
37
|
+
let(:retries) {Cfg.processes_check_retries}
|
38
38
|
|
39
39
|
it "should return false" do
|
40
40
|
(retries-1).times do
|
@@ -36,11 +36,11 @@ module Nginx
|
|
36
36
|
subject {Manager}
|
37
37
|
|
38
38
|
def port_defined?(port)
|
39
|
-
File.readlines(
|
39
|
+
File.readlines(Cfg.nginx_conf).grep(/#{port}/).size > 0
|
40
40
|
end
|
41
41
|
|
42
42
|
before do
|
43
|
-
File.open(
|
43
|
+
File.open(Cfg.nginx_conf, "w") do |f|
|
44
44
|
f.puts(INITIAL_CONF)
|
45
45
|
end
|
46
46
|
|
@@ -6,8 +6,8 @@ module Phantom
|
|
6
6
|
subject {Collector}
|
7
7
|
|
8
8
|
before do
|
9
|
-
|
10
|
-
|
9
|
+
Cfg.phantom_processes_number = 5
|
10
|
+
Cfg.phantom_base_port = 8002
|
11
11
|
subject.stub(:running_phantoms_shell_output).and_return(phantoms_ps_shell_output)
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'utils/cfg'
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
describe Cfg do
|
6
|
+
subject {Cfg}
|
7
|
+
|
8
|
+
it "should be able to set" do
|
9
|
+
Cfg.rails_root= "some path"
|
10
|
+
Cfg.rails_root.should eq "some path"
|
11
|
+
Cfg.rails_root= "another path"
|
12
|
+
Cfg.rails_root.should eq "another path"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/shared_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'utils/logger'
|
2
2
|
require 'utils/cfg'
|
3
|
-
|
4
|
-
|
3
|
+
Cfg.nginx_conf = File.expand_path('../files/nginx.conf', __FILE__)
|
4
|
+
Cfg.new_nginx_conf = File.expand_path('../files/nginx.conf.new', __FILE__)
|
5
5
|
|
6
6
|
$logger = Logger.new(nil)
|
7
7
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom-manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erez Rabih
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- spec/lib/phantom/collector_spec.rb
|
103
103
|
- spec/lib/phantom/manager_spec.rb
|
104
104
|
- spec/lib/phantom/process_spec.rb
|
105
|
+
- spec/lib/utils/cfg_spec.rb
|
105
106
|
- spec/lib/utils/limited_array_spec.rb
|
106
107
|
- spec/lib/utils/lock_spec.rb
|
107
108
|
- spec/lib/utils/shell_spec.rb
|
@@ -145,6 +146,7 @@ test_files:
|
|
145
146
|
- spec/lib/phantom/collector_spec.rb
|
146
147
|
- spec/lib/phantom/manager_spec.rb
|
147
148
|
- spec/lib/phantom/process_spec.rb
|
149
|
+
- spec/lib/utils/cfg_spec.rb
|
148
150
|
- spec/lib/utils/limited_array_spec.rb
|
149
151
|
- spec/lib/utils/lock_spec.rb
|
150
152
|
- spec/lib/utils/shell_spec.rb
|