bipbip 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bipbip.rb +1 -0
- data/lib/bipbip/agent.rb +32 -9
- data/lib/bipbip/plugin.rb +7 -3
- data/lib/bipbip/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27e9aa7d8a9f00d2940ec3dde1918556f32b5453
|
4
|
+
data.tar.gz: e73717090f198d321f70deab0dd4540d08addc33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b47fdeb97354d69730a3a3cf72cd8bcaa32f05622031e4a152dec618228ebb2027ebb6da37c2182afe87b84f2ee27df1e3fa7f993ca297dc5ee531ce7a589f04
|
7
|
+
data.tar.gz: ebe253a1196b617650450c467d3e4ff4194c3c7bfdd6dc9579967895eab62549420ead96d308b9568dbe461e8e5806e1cc32ee9da67b5ef7c1ee52cc7a6235f9
|
data/lib/bipbip.rb
CHANGED
data/lib/bipbip/agent.rb
CHANGED
@@ -2,22 +2,26 @@ module Bipbip
|
|
2
2
|
|
3
3
|
class Agent
|
4
4
|
|
5
|
+
PLUGIN_RESPAWN_DELAY = 5
|
6
|
+
|
5
7
|
attr_accessor :plugins
|
6
8
|
attr_accessor :storages
|
7
9
|
|
8
10
|
def initialize(config_file = nil)
|
9
11
|
@plugins = []
|
10
12
|
@storages = []
|
11
|
-
@plugin_pids = []
|
12
13
|
|
13
14
|
load_config(config_file) if config_file
|
14
15
|
end
|
15
16
|
|
16
17
|
def run
|
17
18
|
Bipbip.logger.info 'Startup...'
|
18
|
-
Bipbip.logger.warn 'No services configured' if @plugins.empty?
|
19
19
|
Bipbip.logger.warn 'No storages configured' if @storages.empty?
|
20
20
|
|
21
|
+
if @plugins.empty?
|
22
|
+
raise 'No services configured'
|
23
|
+
end
|
24
|
+
|
21
25
|
@storages.each do |storage|
|
22
26
|
@plugins.each do |plugin|
|
23
27
|
Bipbip.logger.info "Setting up plugin #{plugin.name} for storage #{storage.name}"
|
@@ -26,16 +30,24 @@ module Bipbip
|
|
26
30
|
end
|
27
31
|
|
28
32
|
['INT', 'TERM'].each { |sig| trap(sig) {
|
29
|
-
Thread.new
|
33
|
+
Thread.new do
|
34
|
+
interrupt
|
35
|
+
exit
|
36
|
+
end
|
30
37
|
} }
|
31
38
|
|
32
39
|
@plugins.each do |plugin|
|
33
40
|
Bipbip.logger.info "Starting plugin #{plugin.name} with config #{plugin.config}"
|
34
|
-
|
41
|
+
plugin.run(@storages)
|
35
42
|
end
|
36
43
|
|
37
|
-
|
38
|
-
|
44
|
+
@interrupted = false
|
45
|
+
until @interrupted
|
46
|
+
pid = Process.wait(-1)
|
47
|
+
plugin = plugin_by_pid(pid)
|
48
|
+
Bipbip.logger.error "Plugin #{plugin.name} with config #{plugin.config} died. Respawning..."
|
49
|
+
sleep(PLUGIN_RESPAWN_DELAY)
|
50
|
+
plugin.run(@storages)
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
@@ -78,14 +90,25 @@ module Bipbip
|
|
78
90
|
end
|
79
91
|
|
80
92
|
def interrupt
|
93
|
+
@interrupted = true
|
94
|
+
|
81
95
|
Bipbip.logger.info 'Interrupt, killing plugin processes...'
|
82
|
-
@
|
96
|
+
@plugins.each do |plugin|
|
97
|
+
Process.kill('TERM', plugin.pid) if Process.exists?(plugin.pid)
|
98
|
+
end
|
83
99
|
|
84
100
|
Bipbip.logger.info 'Waiting for all plugin processes to exit...'
|
85
101
|
Process.waitall
|
102
|
+
end
|
86
103
|
|
87
|
-
|
88
|
-
|
104
|
+
private
|
105
|
+
|
106
|
+
def plugin_by_pid(pid)
|
107
|
+
plugin = @plugins.find { |plugin| plugin.pid == pid }
|
108
|
+
if plugin.nil?
|
109
|
+
raise "Cannot find plugin with pid #{pid}"
|
110
|
+
end
|
111
|
+
plugin
|
89
112
|
end
|
90
113
|
end
|
91
114
|
end
|
data/lib/bipbip/plugin.rb
CHANGED
@@ -6,6 +6,7 @@ module Bipbip
|
|
6
6
|
attr_accessor :name
|
7
7
|
attr_accessor :config
|
8
8
|
attr_accessor :metric_group
|
9
|
+
attr_accessor :pid
|
9
10
|
|
10
11
|
def self.factory(name, config, frequency, metric_group = nil)
|
11
12
|
require "bipbip/plugin/#{Bipbip::Helper.name_to_filename(name)}"
|
@@ -15,12 +16,12 @@ module Bipbip
|
|
15
16
|
def initialize(name, config, frequency, metric_group = nil)
|
16
17
|
@name = name.to_s
|
17
18
|
@config = config.to_hash
|
18
|
-
@frequency = frequency.
|
19
|
+
@frequency = frequency.to_f
|
19
20
|
@metric_group = (metric_group || name).to_s
|
20
21
|
end
|
21
22
|
|
22
23
|
def run(storages)
|
23
|
-
|
24
|
+
@pid = fork do
|
24
25
|
['INT', 'TERM'].each { |sig| trap(sig) {
|
25
26
|
Thread.new { interrupt } if !@interrupted
|
26
27
|
} }
|
@@ -41,10 +42,13 @@ module Bipbip
|
|
41
42
|
interruptible_sleep (frequency - (Time.now - time))
|
42
43
|
end
|
43
44
|
rescue => e
|
44
|
-
Bipbip.logger.error "#{name} #{source_identifier}: Error
|
45
|
+
Bipbip.logger.error "#{name} #{source_identifier}: Error: #{e.message}"
|
45
46
|
interruptible_sleep retry_delay
|
46
47
|
retry_delay += frequency if retry_delay < frequency * 10
|
47
48
|
retry
|
49
|
+
rescue Exception => e
|
50
|
+
Bipbip.logger.error "#{name} #{source_identifier}: Fatal error: #{e.message}"
|
51
|
+
raise e
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
data/lib/bipbip/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bipbip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-10-
|
13
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: copperegg
|
@@ -138,6 +138,20 @@ dependencies:
|
|
138
138
|
- - "~>"
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '1.10'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: process_exists
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 0.1.3
|
148
|
+
type: :runtime
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - "~>"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 0.1.3
|
141
155
|
- !ruby/object:Gem::Dependency
|
142
156
|
name: rake
|
143
157
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
235
|
version: '0'
|
222
236
|
requirements: []
|
223
237
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.4.
|
238
|
+
rubygems_version: 2.4.2
|
225
239
|
signing_key:
|
226
240
|
specification_version: 4
|
227
241
|
summary: Gather services data and store in CopperEgg
|