Module: Htmon::Agent

Extended by:
Agent
Included in:
Agent
Defined in:
lib/htmon/agent.rb,
lib/htmon/agent/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#checksObject



11
12
13
# File 'lib/htmon/agent.rb', line 11

def checks 
  @checks ||= []
end

#remoteObject



15
16
17
18
# File 'lib/htmon/agent.rb', line 15

def remote
  raise "Missing remote, fill ENV['htmon_api']" unless ENV['htmon_api']
  "#{ENV['htmon_api'].to_s.gsub(/\/$/,'')}/api/v1/metrics/"
end

#start(config: nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/htmon/agent.rb', line 20

def start config: nil
  load config
  logger = Logger.new(STDOUT)
  logger.info "Starting processing loop ..."
  loop do
    checks.each do |check|
      if check.launched_at.nil? or 
        (check.launched_at + check.interval).past?
        logger.debug "Fork check processing ..."
        Process.detach( fork { check.callback.call } )
        check.launched_at = Time.now
      end
    end
    sleep 0.2
  end
end