bmc-daemon-lib 0.3.16 → 0.3.18
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/Gemfile.lock +2 -16
- data/bmc-daemon-lib.gemspec +1 -2
- data/lib/bmc-daemon-lib/conf.rb +56 -29
- data/lib/bmc-daemon-lib/logger_pool.rb +3 -38
- data/lib/bmc-daemon-lib/mq_consumer.rb +1 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e5609f9590972c691a3756c1af6bd9ad1ee0282
|
4
|
+
data.tar.gz: 6a3ee2207696ebc991abb0992a8334f5db0e0856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94186c5a6810b5c363bc6991ed5a8fc4d83cda7db8a3bcdb36442a2793efb411aa47e1dc2c957a90d6d810318556baf9f07dae00e81861c568f9115ce22ac1e9
|
7
|
+
data.tar.gz: 2c04229dd313885efd3b7cebc8202f8074d4fc46f6e01fe6e86b75445452ac17859f41397fc43a70d36754945c2f7fbad71a1b169a66584f89b787f268b3cb76
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bmc-daemon-lib (0.3.
|
4
|
+
bmc-daemon-lib (0.3.18)
|
5
5
|
chamber (~> 2.9)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.3.0)
|
11
10
|
chamber (2.9.1)
|
12
11
|
hashie (~> 3.3)
|
13
12
|
thor (~> 0.19.1)
|
14
13
|
diff-lcs (1.2.5)
|
15
|
-
hashie (3.4.
|
16
|
-
parser (2.3.1.2)
|
17
|
-
ast (~> 2.2)
|
18
|
-
powerpack (0.1.1)
|
19
|
-
rainbow (2.1.0)
|
14
|
+
hashie (3.4.6)
|
20
15
|
rake (11.2.2)
|
21
16
|
rspec (3.5.0)
|
22
17
|
rspec-core (~> 3.5.0)
|
@@ -31,15 +26,7 @@ GEM
|
|
31
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
27
|
rspec-support (~> 3.5.0)
|
33
28
|
rspec-support (3.5.0)
|
34
|
-
rubocop (0.42.0)
|
35
|
-
parser (>= 2.3.1.1, < 3.0)
|
36
|
-
powerpack (~> 0.1)
|
37
|
-
rainbow (>= 1.99.1, < 3.0)
|
38
|
-
ruby-progressbar (~> 1.7)
|
39
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
40
|
-
ruby-progressbar (1.8.1)
|
41
29
|
thor (0.19.1)
|
42
|
-
unicode-display_width (1.1.1)
|
43
30
|
|
44
31
|
PLATFORMS
|
45
32
|
ruby
|
@@ -49,7 +36,6 @@ DEPENDENCIES
|
|
49
36
|
bundler (~> 1.6)
|
50
37
|
rake
|
51
38
|
rspec
|
52
|
-
rubocop
|
53
39
|
|
54
40
|
BUNDLED WITH
|
55
41
|
1.12.5
|
data/bmc-daemon-lib.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
# Project version
|
4
|
-
spec.version = "0.3.
|
4
|
+
spec.version = "0.3.18"
|
5
5
|
|
6
6
|
# Project description
|
7
7
|
spec.name = "bmc-daemon-lib"
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "rubocop"
|
27
26
|
|
28
27
|
# Runtime dependencies
|
29
28
|
spec.add_runtime_dependency "chamber", "~> 2.9"
|
data/lib/bmc-daemon-lib/conf.rb
CHANGED
@@ -78,10 +78,6 @@ module BmcDaemonLib
|
|
78
78
|
Encoding.default_internal = "utf-8"
|
79
79
|
Encoding.default_external = "utf-8"
|
80
80
|
|
81
|
-
# Init New Relic, Rollbar
|
82
|
-
# prepare_newrelic
|
83
|
-
#prepare_rollbar if self.feature?(:rollbar)
|
84
|
-
|
85
81
|
# Try to access any key to force parsing of the files
|
86
82
|
self[:dummy]
|
87
83
|
|
@@ -108,21 +104,30 @@ module BmcDaemonLib
|
|
108
104
|
path.reduce(Conf) { |m, key| m && m[key.to_s] }
|
109
105
|
end
|
110
106
|
|
111
|
-
def self.
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
107
|
+
def self.logfile pipe
|
108
|
+
# Build logfile from Conf
|
109
|
+
logfile = self.logfile_path(pipe)
|
110
|
+
return nil if logfile.nil?
|
111
|
+
|
112
|
+
# Check that we'll be able to create logfiles
|
113
|
+
if File.exists?(logfile)
|
114
|
+
# File is there, is it writable ?
|
115
|
+
unless File.writable?(logfile)
|
116
|
+
log :conf, "logging [#{pipe}] disabled: file not writable [#{logfile}]"
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
else
|
120
|
+
# No file here, can we create it ?
|
121
|
+
logdir = File.dirname(logfile)
|
122
|
+
unless File.writable?(logdir)
|
123
|
+
log :conf, "logging [#{pipe}] disabled: directory not writable [#{logdir}]"
|
124
|
+
return nil
|
125
|
+
end
|
126
|
+
end
|
123
127
|
|
124
|
-
#
|
125
|
-
|
128
|
+
# OK, return a clean file path
|
129
|
+
log :conf, "logging [#{pipe}] to [#{logfile}]"
|
130
|
+
return logfile
|
126
131
|
end
|
127
132
|
|
128
133
|
def self.feature? name
|
@@ -178,16 +183,14 @@ module BmcDaemonLib
|
|
178
183
|
def self.prepare_newrelic
|
179
184
|
# Disable if no config present
|
180
185
|
return unless self.feature?(:newrelic)
|
186
|
+
|
187
|
+
# Ok, let's start
|
181
188
|
section = self[:newrelic]
|
189
|
+
log :conf, "prepare NewRelic"
|
182
190
|
|
183
191
|
# Enable GC profiler
|
184
192
|
GC::Profiler.enable
|
185
193
|
|
186
|
-
# Set logfile, license, monitor mode
|
187
|
-
ENV["NEW_RELIC_LOG"] = logfile_path(:newrelic)
|
188
|
-
ENV["NEW_RELIC_LICENSE_KEY"] = section[:license].to_s
|
189
|
-
ENV["NEW_RELIC_MONITOR_MODE"] = "true"
|
190
|
-
|
191
194
|
# Build NewRelic app_name if not provided as-is
|
192
195
|
if !section[:app_name]
|
193
196
|
stack = []
|
@@ -197,10 +200,15 @@ module BmcDaemonLib
|
|
197
200
|
text = stack.join('-')
|
198
201
|
section[:app_name] = "#{text}; #{text}-#{host}"
|
199
202
|
end
|
200
|
-
ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s
|
201
203
|
|
202
|
-
#
|
203
|
-
|
204
|
+
# Start the agent
|
205
|
+
NewRelic::Agent.manual_start({
|
206
|
+
agent_enabled: true,
|
207
|
+
log: LoggerPool.instance.get(:newrelic),
|
208
|
+
env: @app_env,
|
209
|
+
license_key: section[:license].to_s,
|
210
|
+
app_name: section[:app_name].to_s,
|
211
|
+
})
|
204
212
|
end
|
205
213
|
|
206
214
|
def self.prepare_rollbar
|
@@ -212,7 +220,9 @@ module BmcDaemonLib
|
|
212
220
|
return
|
213
221
|
end
|
214
222
|
|
223
|
+
# Ok, let's start
|
215
224
|
section = self[:rollbar]
|
225
|
+
log :conf, "prepare Rollbar"
|
216
226
|
|
217
227
|
# Configure
|
218
228
|
Rollbar.configure do |config|
|
@@ -220,8 +230,7 @@ module BmcDaemonLib
|
|
220
230
|
config.access_token = section[:token].to_s
|
221
231
|
config.code_version = @app_version
|
222
232
|
config.environment = @app_env
|
223
|
-
|
224
|
-
config.logger = LoggerPool.instance.get :rollbar
|
233
|
+
config.logger = LoggerPool.instance.get(:rollbar)
|
225
234
|
config.use_async = true
|
226
235
|
end
|
227
236
|
|
@@ -231,7 +240,7 @@ module BmcDaemonLib
|
|
231
240
|
|
232
241
|
def self.log origin, message
|
233
242
|
printf(
|
234
|
-
"%s %-
|
243
|
+
"%s %-14s %s \n",
|
235
244
|
Time.now.strftime("%Y-%m-%d %H:%M:%S"),
|
236
245
|
origin,
|
237
246
|
message
|
@@ -248,6 +257,24 @@ module BmcDaemonLib
|
|
248
257
|
@files << File.expand_path(path) if path && File.readable?(path)
|
249
258
|
end
|
250
259
|
|
260
|
+
def self.logfile_path pipe
|
261
|
+
# Access configuration
|
262
|
+
path = self.at :logs, :path
|
263
|
+
specific = self.at :logs, pipe
|
264
|
+
default = self.at :logs, :default
|
265
|
+
|
266
|
+
# Ignore if explicitely disabled
|
267
|
+
return nil if specific.nil?
|
268
|
+
return nil if specific == false
|
269
|
+
|
270
|
+
# Fallback on default path if not provided,
|
271
|
+
specific ||= default
|
272
|
+
specific ||= "default.log"
|
273
|
+
|
274
|
+
# Build logfile_path
|
275
|
+
File.expand_path specific.to_s, path.to_s
|
276
|
+
end
|
277
|
+
|
251
278
|
private
|
252
279
|
|
253
280
|
def self.ensure_init
|
@@ -5,20 +5,20 @@ require "singleton"
|
|
5
5
|
module BmcDaemonLib
|
6
6
|
class LoggerPool
|
7
7
|
include Singleton
|
8
|
-
|
9
8
|
LOG_ROTATION = "daily"
|
10
9
|
|
11
10
|
def get pipe = nil
|
12
11
|
# If not provided, use :default
|
13
12
|
pipe = :default if pipe.to_s.empty?
|
14
13
|
|
14
|
+
# Instantiate a logger or return the existing one
|
15
15
|
@loggers ||= {}
|
16
16
|
@loggers[pipe] ||= create(pipe)
|
17
17
|
end
|
18
18
|
|
19
19
|
def create pipe
|
20
20
|
# Compute logfile or STDERR, and declare what we're doing
|
21
|
-
filename = logfile(pipe)
|
21
|
+
filename = Conf.logfile(pipe)
|
22
22
|
|
23
23
|
# Create the logger and return it
|
24
24
|
logger = Logger.new(filename, LOG_ROTATION) #, 10, 1024000)
|
@@ -29,42 +29,7 @@ module BmcDaemonLib
|
|
29
29
|
logger
|
30
30
|
|
31
31
|
rescue Errno::EACCES
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def logfile pipe
|
38
|
-
# Disabled if no valid config
|
39
|
-
#return nil unless Conf[:logs].is_a?(Hash) && Conf.at(:logs, pipe)
|
40
|
-
|
41
|
-
# Build logfile from Conf
|
42
|
-
logfile = Conf.logfile_path pipe
|
43
|
-
return nil if logfile.nil?
|
44
|
-
|
45
|
-
# Check that we'll be able to create logfiles
|
46
|
-
if File.exists?(logfile)
|
47
|
-
# File is there, is it writable ?
|
48
|
-
unless File.writable?(logfile)
|
49
|
-
log "logging [#{pipe}] to [#{logfile}] disabled: file not writable [#{logfile}]"
|
50
|
-
return nil
|
51
|
-
end
|
52
|
-
else
|
53
|
-
# No file here, can we create it ?
|
54
|
-
logdir = File.dirname(logfile)
|
55
|
-
unless File.writable?(logdir)
|
56
|
-
log "logging [#{pipe}] [#{logfile}] disabled: directory not writable [#{logdir}]"
|
57
|
-
return nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# OK, return a clean file path
|
62
|
-
log "logging [#{pipe}] to [#{logfile}]"
|
63
|
-
return logfile
|
64
|
-
end
|
65
|
-
|
66
|
-
def log message
|
67
|
-
Conf.log :logger, message
|
32
|
+
$stderr.puts "LoggerPool: create [#{pipe}]: access error"
|
68
33
|
end
|
69
34
|
|
70
35
|
end
|
@@ -47,6 +47,7 @@ module BmcDaemonLib
|
|
47
47
|
payload_bytesize = payload.bytesize
|
48
48
|
log_message MSG_RECV, msg_topic, msg_rkey, msg_data, {
|
49
49
|
app_id: metadata.app_id,
|
50
|
+
sent_at: msg_headers['sent_at'],
|
50
51
|
channel_tag: "#{@channel.id}.#{msg_tag}",
|
51
52
|
content_type: metadata.content_type,
|
52
53
|
delay_ms: extract_delay(msg_headers),
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmc-daemon-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: chamber
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|