Class: AppPerfAgent::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/app_perf_agent/worker.rb

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



3
4
5
# File 'lib/app_perf_agent/worker.rb', line 3

def initialize
  @running = false
end

Instance Method Details

#collectObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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|
      type, name, label, value = item
      dispatcher.add_event(["metric", Time.now.to_f, {
        "type" => type,
        "name" => name,
        "label" => label,
        "value" => value
      }])
    end
  end
end

#dispatcherObject



11
12
13
# File 'lib/app_perf_agent/worker.rb', line 11

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

#load_pluginsObject



7
8
9
# File 'lib/app_perf_agent/worker.rb', line 7

def load_plugins
  AppPerfAgent::Plugin.load_plugins
end

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

#stopObject



15
16
17
# File 'lib/app_perf_agent/worker.rb', line 15

def stop
  @running = false
end