Class: Panoptimon::Collector
- Inherits:
-
Object
- Object
- Panoptimon::Collector
- Includes:
- Logger
- Defined in:
- lib/panoptimon/collector.rb
Instance Attribute Summary collapse
-
#bus ⇒ Object
readonly
Returns the value of attribute bus.
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#last_run_time ⇒ Object
readonly
Returns the value of attribute last_run_time.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(args) ⇒ Collector
constructor
A new instance of Collector.
- #noise(mess) ⇒ Object
- #run ⇒ Object
- #running? ⇒ Boolean
Methods included from Logger
Constructor Details
#initialize(args) ⇒ Collector
Returns a new instance of Collector.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/panoptimon/collector.rb', line 12 def initialize (args) cmd = args.delete(:command) or raise "must have 'command' argument" @cmd = cmd.class == Array ? cmd : Shellwords.shellsplit(cmd) ->(exe) { raise "no such file '#{exe}'" unless File.exist?(exe) raise "command '#{exe}' is not executable" unless File.executable?(exe) }.call(@cmd[0]) # TODO or maybe args[:interpreter] @bus = args.delete(:bus) or raise "must have 'bus' argument" args.each { |k,v| instance_variable_set("@#{k}", v) } @name ||= 'unnamed' @config ||= {} @interval = config[:interval] ||= 60 @last_run_time = Time.at(-@interval) end |
Instance Attribute Details
#bus ⇒ Object (readonly)
Returns the value of attribute bus.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def bus @bus end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def cmd @cmd end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def config @config end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def interval @interval end |
#last_run_time ⇒ Object (readonly)
Returns the value of attribute last_run_time.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def last_run_time @last_run_time end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/panoptimon/collector.rb', line 11 def name @name end |
Instance Method Details
#noise(mess) ⇒ Object
48 49 50 |
# File 'lib/panoptimon/collector.rb', line 48 def noise(mess) logger.warn "collector/#{name} noise: #{mess.chomp}" end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/panoptimon/collector.rb', line 29 def run cmdc = @cmd + [JSON.generate(config)] @last_run_time = Time.now # TODO .to_i ? logger.info {"run command: #{cmdc}"} @child = EM.popen3b(cmdc, CollectorSink, self) @child.on_unbind { |status, errmess| logger.error {"collector #{name} failed: #{status}" + (errmess.nil? ? '' : "\n #{errmess.chomp.split(/\n/).join("\n ")}") } if(not(status.nil?) and status != 0) @child = nil } logger.debug "timeout is: #{config[:timeout]}" # XXX afaict, eventmachine just did not implement this: # @child.set_comm_inactivity_timeout(config[:timeout]) end |
#running? ⇒ Boolean
52 53 54 |
# File 'lib/panoptimon/collector.rb', line 52 def running? @child.nil? ? false : true end |