class Panoptimon::Collector

Attributes

bus[R]
cmd[R]
config[R]
interval[R]
last_run_time[R]
name[R]

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

noise(mess) click to toggle source
# File lib/panoptimon/collector.rb, line 48
def noise(mess)
  logger.warn "collector/#{name} noise: #{mess.chomp}"
end
run() click to toggle source
# 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?() click to toggle source
# File lib/panoptimon/collector.rb, line 52
def running?
  @child.nil? ? false : true
end