Class: Bosh::Monitor::Runner
- Inherits:
-
Object
- Object
- Bosh::Monitor::Runner
- Includes:
- YamlHelper
- Defined in:
- lib/bosh/monitor/runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #analyze_agents ⇒ Object
- #connect_to_mbus ⇒ Object
-
#initialize(config_file) ⇒ Runner
constructor
A new instance of Runner.
- #log_stats ⇒ Object
- #poll_director ⇒ Object
- #run ⇒ Object
- #setup_timers ⇒ Object
- #start_http_server ⇒ Object
- #stop(soft = false) ⇒ Object
Methods included from YamlHelper
Constructor Details
#initialize(config_file) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 14 15 16 17 |
# File 'lib/bosh/monitor/runner.rb', line 9 def initialize(config_file) Bhm.config = load_yaml_file(config_file) @logger = Bhm.logger @director = Bhm.director @intervals = Bhm.intervals @mbus = Bhm.mbus @agent_manager = Bhm.agent_manager end |
Class Method Details
.run(config_file) ⇒ Object
5 6 7 |
# File 'lib/bosh/monitor/runner.rb', line 5 def self.run(config_file) new(config_file).run end |
Instance Method Details
#analyze_agents ⇒ Object
107 108 109 110 111 |
# File 'lib/bosh/monitor/runner.rb', line 107 def analyze_agents # N.B. Yes, his will block event loop, # possibly consider deferring @agent_manager.analyze_agents end |
#connect_to_mbus ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bosh/monitor/runner.rb', line 63 def connect_to_mbus NATS.on_error do |e| unless @shutting_down if e.kind_of?(NATS::ConnectError) handle_em_error(e) else log_exception(e) end end end = { :uri => @mbus.endpoint, :user => @mbus.user, :pass => @mbus.password, :autostart => false } Bhm.nats = NATS.connect() do @logger.info("Connected to NATS at `#{@mbus.endpoint}'") end end |
#log_stats ⇒ Object
56 57 58 59 60 61 |
# File 'lib/bosh/monitor/runner.rb', line 56 def log_stats n_deployments = pluralize(@agent_manager.deployments_count, "deployment") n_agents = pluralize(@agent_manager.agents_count, "agent") @logger.info("Managing #{n_deployments}, #{n_agents}") @logger.info("Agent heartbeats received = %s" % [ @agent_manager.heartbeats_received ]) end |
#poll_director ⇒ Object
100 101 102 103 104 105 |
# File 'lib/bosh/monitor/runner.rb', line 100 def poll_director @logger.debug "Getting deployments from director..." Fiber.new { fetch_deployments }.resume Bhm.set_varz("deployments_count", @agent_manager.deployments_count) Bhm.set_varz("agents_count", @agent_manager.agents_count) end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bosh/monitor/runner.rb', line 19 def run @logger.info("HealthMonitor starting...") EM.kqueue if EM.kqueue? EM.epoll if EM.epoll? EM.error_handler { |e| handle_em_error(e) } EM.run do connect_to_mbus @director_monitor = DirectorMonitor.new(Bhm) @director_monitor.subscribe @agent_manager.setup_events setup_timers start_http_server @logger.info "BOSH HealthMonitor #{Bhm::VERSION} is running..." end end |
#setup_timers ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bosh/monitor/runner.rb', line 44 def setup_timers EM.next_tick do poll_director EM.add_periodic_timer(@intervals.poll_director) { poll_director } EM.add_periodic_timer(@intervals.log_stats) { log_stats } EM.add_timer(@intervals.poll_grace_period) do EM.add_periodic_timer(@intervals.analyze_agents) { analyze_agents } end end end |
#start_http_server ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bosh/monitor/runner.rb', line 86 def start_http_server @logger.info "HTTP server is starting on port #{Bhm.http_port}..." @http_server = Thin::Server.new("0.0.0.0", Bhm.http_port, :signals => false) do Thin::Logging.silent = true use Rack::Auth::Basic do |user, password| [ user, password ] == [ Bhm.http_user, Bhm.http_password ] end map "/" do run Bhm::ApiController.new end end @http_server.start! end |
#stop(soft = false) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/bosh/monitor/runner.rb', line 37 def stop(soft=false) @logger.info("HealthMonitor shutting down...") @http_server.stop! if @http_server EM.stop exit(0) unless soft end |