Sha256: 499d2a6709053a502bbb8ee771578c8e7685d73741272a687fa04ba6892c84c3

Contents?: true

Size: 883 Bytes

Versions: 5

Compression:

Stored size: 883 Bytes

Contents

module AppPerfAgent
  class Worker
    def initialize
      @running = false
    end

    def load_plugins
      AppPerfAgent::Plugin.load_plugins
    end

    def dispatcher
      @dispatcher ||= AppPerfAgent::Dispatcher.new
    end

    def stop
      @running = false
    end

    def start
      @running = true

      while @running
        collect if dispatcher.queue_empty?

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

        sleep 1
      end
    end

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
app_perf_agent-0.0.9 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.8 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.7 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.6 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.5 lib/app_perf_agent/worker.rb