Sha256: 3e93d16d5c49bd9b41545e11002f9a4620c8d0074640461094631dc236a6fda4

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 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|
          type, name, label, value = item
          dispatcher.add_event(["metric", Time.now.to_f, {
            "type" => type,
            "name" => name,
            "label" => label,
            "value" => value
          }])
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
app_perf_agent-0.0.4 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.3 lib/app_perf_agent/worker.rb
app_perf_agent-0.0.2 lib/app_perf_agent/worker.rb