Class: Metrux::Commands::PeriodicGauge::Agent
- Inherits:
-
Object
- Object
- Metrux::Commands::PeriodicGauge::Agent
- Defined in:
- lib/metrux/commands/periodic_gauge/agent.rb
Constant Summary collapse
- DEFAULT_INVERVAL =
60
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(command, registry, config) ⇒ Agent
constructor
A new instance of Agent.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Sleeper
Constructor Details
#initialize(command, registry, config) ⇒ Agent
Returns a new instance of Agent.
10 11 12 13 14 15 16 |
# File 'lib/metrux/commands/periodic_gauge/agent.rb', line 10 def initialize(command, registry, config) @command = command @registry = registry @interval = config.periodic_gauge_interval || DEFAULT_INVERVAL @logger = config.logger @thread = nil end |
Instance Method Details
#alive? ⇒ Boolean
40 41 42 |
# File 'lib/metrux/commands/periodic_gauge/agent.rb', line 40 def alive? @thread && @thread.alive? end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/metrux/commands/periodic_gauge/agent.rb', line 18 def start return false if alive? log('Starting...', :info) @thread = Thread.new do loop do log("sleeping for #{interval}s...") wait(interval) metrics.each(&method(:execute_metric)) end end true end |
#stop ⇒ Object
34 35 36 37 38 |
# File 'lib/metrux/commands/periodic_gauge/agent.rb', line 34 def stop log('Stopping...', :info) @thread.kill if @thread @thread = nil end |