class AppPerfAgent::Worker

Public Class Methods

new() click to toggle source
# File lib/app_perf_agent/worker.rb, line 3
def initialize
  @running = false
end

Public Instance Methods

collect() click to toggle source
# File lib/app_perf_agent/worker.rb, line 34
def collect
  AppPerfAgent::Plugin.plugins.each do |plugin|
    items = plugin.call
    items.map {|i| AppPerfAgent.logger.debug i }
    Array(items).each do |item|
      key, value, tags = item
      metric = ["metric", Time.now.to_f, key, value, tags || {}]
      dispatcher.add_event(metric)
    end
  end
end
dispatcher() click to toggle source
# File lib/app_perf_agent/worker.rb, line 11
def dispatcher
  @dispatcher ||= AppPerfAgent::Dispatcher.new
end
load_plugins() click to toggle source
# File lib/app_perf_agent/worker.rb, line 7
def load_plugins
  AppPerfAgent::Plugin.load_plugins
end
start() click to toggle source
# File lib/app_perf_agent/worker.rb, line 19
def start
  @running = true

  while @running
    collect if dispatcher.queue_empty?

    if dispatcher.ready?
      dispatcher.dispatch
      dispatcher.reset
    end

    sleep 1
  end
end
stop() click to toggle source
# File lib/app_perf_agent/worker.rb, line 15
def stop
  @running = false
end