oml4r 2.9.3 → 2.9.4
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.
- data/lib/oml4r.rb +43 -37
- data/lib/oml4r/log4r/oml_outputter.rb +7 -1
- data/lib/oml4r/version.rb +1 -1
- metadata +2 -2
data/lib/oml4r.rb
CHANGED
@@ -37,9 +37,9 @@ module OML4R
|
|
37
37
|
@@logger = logger
|
38
38
|
end
|
39
39
|
|
40
|
-
class
|
41
|
-
class MissingArgumentException <
|
42
|
-
class ArgumentMismatchException <
|
40
|
+
class OML4RException < Exception; end
|
41
|
+
class MissingArgumentException < OML4RException; end
|
42
|
+
class ArgumentMismatchException < OML4RException; end
|
43
43
|
#
|
44
44
|
# Measurement Point Class
|
45
45
|
# Ruby applications using this module should sub-class this MPBase class
|
@@ -228,8 +228,14 @@ module OML4R
|
|
228
228
|
# It will then connect to the OML server (if requested on the command line), and
|
229
229
|
# send the initial instruction to setup the database and the tables for each MPs.
|
230
230
|
#
|
231
|
-
#
|
232
|
-
#
|
231
|
+
# param argv = the Array of command line arguments from the calling Ruby application
|
232
|
+
# param opts
|
233
|
+
# opts [String] :domain
|
234
|
+
# opts [String] :nodeID
|
235
|
+
# opts [String] :appName
|
236
|
+
# opts [Integer] :protocol
|
237
|
+
# opts [Proc] :afterParse
|
238
|
+
# param block = a block which defines the additional application-specific arguments
|
233
239
|
#
|
234
240
|
def self.init(argv, opts = {}, &block)
|
235
241
|
OML4R#{VERSION_STRING} [#{COPYRIGHT}")
|
@@ -240,21 +246,21 @@ module OML4R
|
|
240
246
|
OML4R.logger.warn "opts[:expID] and ENV['OML_EXP_ID'] are getting deprecated; please use opts[:domain] or ENV['OML_DOMAIN'] instead"
|
241
247
|
opts[:domain] ||= d
|
242
248
|
end
|
243
|
-
domain
|
249
|
+
opts[:domain] = ENV['OML_DOMAIN'] || opts[:domain]
|
244
250
|
|
245
251
|
# TODO: Same as above; here, though, :id might actually be the way to go; or
|
246
252
|
# perhaps instId?
|
247
253
|
#if opts[:id]
|
248
254
|
# raise 'OML4R: :id is not a valid option. Do you mean :nodeID?'
|
249
255
|
#end
|
250
|
-
nodeID
|
256
|
+
opts[:nodeID] = ENV['OML_NAME'] || opts[:nodeID] || opts[:id] || ENV['OML_ID']
|
251
257
|
#
|
252
258
|
# XXX: Same again; also, this is the responsibility of the developer, not the user
|
253
259
|
#if opts[:app]
|
254
260
|
# raise 'OML4R: :app is not a valid option. Do you mean :appName?'
|
255
261
|
#end
|
256
|
-
|
257
|
-
|
262
|
+
opts[:appName] ||= opts[:app]
|
263
|
+
opts[:protocol] ||= DEF_PROTOCOL
|
258
264
|
|
259
265
|
if ENV['OML_URL'] || opts[:omlURL] || opts[:url]
|
260
266
|
raise MissingArgumentException.new 'neither OML_URL, :omlURL nor :url are valid. Do you mean OML_COLLECT or :omlCollect?'
|
@@ -262,7 +268,7 @@ module OML4R
|
|
262
268
|
if ENV['OML_SERVER'] || opts[:omlServer]
|
263
269
|
OML4R.logger.warn "opts[:omlServer] and ENV['OML_SERVER'] are getting deprecated; please use opts[:collect] or ENV['OML_COLLECT'] instead"
|
264
270
|
end
|
265
|
-
|
271
|
+
opts[:collect] = ENV['OML_COLLECT'] || ENV['OML_SERVER'] || opts[:collect] || opts[:omlServer]
|
266
272
|
noop = opts[:noop] || false
|
267
273
|
|
268
274
|
if argv
|
@@ -271,10 +277,10 @@ module OML4R
|
|
271
277
|
# Include the definition of application's specific arguments
|
272
278
|
yield(op) if block
|
273
279
|
# Include the definition of OML specific arguments
|
274
|
-
op.on("--oml-id id", "Name to identify this app instance [#{nodeID || 'undefined'}]") { |name| nodeID = name }
|
275
|
-
op.on("--oml-domain domain", "Name of experimental domain [#{domain || 'undefined'}] *EXPERIMENTAL*") { |name| domain = name }
|
276
|
-
op.on("--oml-collect uri", "URI of server to send measurements to") { |u| omlCollectUri = u }
|
277
|
-
op.on("--oml-protocol p", "Protocol number [#{OML4R::DEF_PROTOCOL}]") { |l| protocol = l.to_i }
|
280
|
+
op.on("--oml-id id", "Name to identify this app instance [#{opts[:nodeID] || 'undefined'}]") { |name| opts[:nodeID] = name }
|
281
|
+
op.on("--oml-domain domain", "Name of experimental domain [#{opts[:domain] || 'undefined'}] *EXPERIMENTAL*") { |name| opts[:domain] = name }
|
282
|
+
op.on("--oml-collect uri", "URI of server to send measurements to") { |u| opts[:omlCollectUri] = u }
|
283
|
+
op.on("--oml-protocol p", "Protocol number [#{OML4R::DEF_PROTOCOL}]") { |l| opts[:protocol] = l.to_i }
|
278
284
|
op.on("--oml-log-level l", "Log level used (info: 1 .. debug: 0)") { |l| OML4R.logger.level = l.to_i }
|
279
285
|
op.on("--oml-noop", "Do not collect measurements") { noop = true }
|
280
286
|
op.on("--oml-exp-id domain", "Obsolescent equivalent to --oml-domain domain") { |name|
|
@@ -282,12 +288,12 @@ module OML4R
|
|
282
288
|
OML4R.logger.warn "Option --oml-exp-id is getting deprecated; please use '--oml-domain #{domain}' instead"
|
283
289
|
}
|
284
290
|
op.on("--oml-file localPath", "Obsolescent equivalent to --oml-collect file:localPath") { |name|
|
285
|
-
omlCollectUri = "file:#{name}"
|
286
|
-
OML4R.logger.warn "Option --oml-file is getting deprecated; please use '--oml-collect #{omlCollectUri}' instead"
|
291
|
+
opts[:omlCollectUri] = "file:#{name}"
|
292
|
+
OML4R.logger.warn "Option --oml-file is getting deprecated; please use '--oml-collect #{opts[:omlCollectUri]}' instead"
|
287
293
|
}
|
288
294
|
op.on("--oml-server uri", "Obsolescent equivalent to --oml-collect uri") {|u|
|
289
|
-
omlCollectUri = u
|
290
|
-
OML4R.logger.warn "Option --oml-server is getting deprecated; please use '--oml-collect #{omlCollectUri}' instead"
|
295
|
+
opts[:omlCollectUri] = "tcp:#{u}"
|
296
|
+
OML4R.logger.warn "Option --oml-server is getting deprecated; please use '--oml-collect #{opts[:omlCollectUri]}' instead"
|
291
297
|
}
|
292
298
|
op.on_tail("--oml-help", "Show this message") { $stderr.puts op; exit }
|
293
299
|
# XXX: This should be set by the application writer, not the command line
|
@@ -296,46 +302,52 @@ module OML4R
|
|
296
302
|
# Now parse the command line
|
297
303
|
OML4R.logger.debug "ARGV: #{argv.inspect}"
|
298
304
|
rest = op.parse(argv)
|
305
|
+
if opts[:afterParse]
|
306
|
+
# give the app a chance to fix missing parameters
|
307
|
+
opts[:afterParse].call(opts)
|
308
|
+
end
|
299
309
|
return if noop
|
300
310
|
end
|
301
311
|
|
302
|
-
unless nodeID
|
312
|
+
unless opts[:nodeID]
|
303
313
|
begin
|
304
314
|
# Create a default nodeID by concatinating the local hostname with the process ID
|
305
315
|
hostname = nil
|
306
316
|
begin
|
307
|
-
hostname = Socket.gethostbyname(Socket.gethostname)[0]
|
317
|
+
#hostname = Socket.gethostbyname(Socket.gethostname)[0]
|
318
|
+
hostname = Socket.gethostname
|
308
319
|
rescue Exception
|
309
320
|
begin
|
310
|
-
hostname = `hostname`
|
321
|
+
hostname = (`hostname`).chop
|
311
322
|
rescue Exception; end
|
312
323
|
end
|
313
324
|
if hostname
|
314
|
-
nodeID = "#{hostname}-#{Process.pid}"
|
325
|
+
opts[:nodeID] = "#{hostname}-#{Process.pid}"
|
315
326
|
end
|
316
327
|
end
|
317
|
-
unless nodeID
|
328
|
+
unless opts[:nodeID]
|
318
329
|
raise MissingArgumentException.new 'OML4R: Missing values for parameter :nodeID (--oml-id)'
|
319
330
|
end
|
320
331
|
end
|
321
332
|
|
322
|
-
unless domain && appName
|
333
|
+
unless opts[:domain] && opts[:appName]
|
323
334
|
raise MissingArgumentException.new 'OML4R: Missing values for parameters :domain (--oml-domain), :nodeID (--oml-id), or :appName (in code)!'
|
324
335
|
end
|
325
336
|
|
326
|
-
|
327
337
|
unless opts[:create_default_channel] == false
|
328
338
|
# Set a default collection URI if nothing has been specified
|
329
|
-
unless omlCollectUri
|
330
|
-
|
331
|
-
|
339
|
+
unless opts[:omlCollectUri]
|
340
|
+
require 'time'
|
341
|
+
opts[:omlCollectUri] = "file:#{opts[:appName]}_#{Time.now.iso8601}"
|
342
|
+
#opts[:omlCollectUri] = "file:-"
|
343
|
+
OML4R.logger.info "Collection URI is #{opts[:omlCollectUri]}"
|
332
344
|
end
|
333
|
-
create_channel(:default, omlCollectUri)
|
345
|
+
create_channel(:default, opts[:omlCollectUri])
|
334
346
|
end
|
335
347
|
|
336
348
|
# Handle the defined Measurement Points
|
337
349
|
startTime = Time.now
|
338
|
-
Channel.init_all(domain, nodeID, appName, startTime, protocol)
|
350
|
+
Channel.init_all(opts[:domain], opts[:nodeID], opts[:appName], startTime, opts[:protocol])
|
339
351
|
rest || []
|
340
352
|
end
|
341
353
|
|
@@ -376,12 +388,6 @@ module OML4R
|
|
376
388
|
return @@channels[key] = self.new(url, domain)
|
377
389
|
end
|
378
390
|
|
379
|
-
# def self._create(key, domain, url)
|
380
|
-
# out = _connect(url)
|
381
|
-
# @@channels[key] = self.new(url, domain, out)
|
382
|
-
# end
|
383
|
-
|
384
|
-
|
385
391
|
def self.[](name = :default, domain = :default)
|
386
392
|
key = "#{name}:#{domain}"
|
387
393
|
unless (@@channels.key?(key))
|
@@ -566,7 +572,7 @@ module OML4R
|
|
566
572
|
loop do
|
567
573
|
sleep 5
|
568
574
|
begin
|
569
|
-
@out =
|
575
|
+
@out = _connect(@url)
|
570
576
|
@header_sent = false
|
571
577
|
OML4R.logger.info "Reconnected to '#{@url}'"
|
572
578
|
return _send(msg)
|
@@ -3,6 +3,13 @@
|
|
3
3
|
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
4
|
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
5
|
# ------------------
|
6
|
+
#
|
7
|
+
# = oml_outputter.rb
|
8
|
+
#
|
9
|
+
# == Description
|
10
|
+
#
|
11
|
+
# Log4r outputter which turn logging events into an OML stream
|
12
|
+
#
|
6
13
|
|
7
14
|
require 'log4r/outputter/outputter'
|
8
15
|
require 'oml4r'
|
@@ -23,7 +30,6 @@ module Log4r
|
|
23
30
|
param :data
|
24
31
|
end
|
25
32
|
|
26
|
-
|
27
33
|
# Initialise an outputter which turns logging messages
|
28
34
|
# into an OML stream
|
29
35
|
#
|
data/lib/oml4r/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oml4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.
|
4
|
+
version: 2.9.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! '["Simple OML client library for Ruby"]'
|
15
15
|
email:
|