Class: ManageIQ::PostgresHaAdmin::FailoverMonitor
- Inherits:
-
Object
- Object
- ManageIQ::PostgresHaAdmin::FailoverMonitor
- Includes:
- Logging
- Defined in:
- lib/manageiq/postgres_ha_admin/failover_monitor.rb
Constant Summary collapse
- FAILOVER_ATTEMPTS =
10
- DB_CHECK_FREQUENCY =
120
- FAILOVER_CHECK_FREQUENCY =
60
Instance Attribute Summary collapse
-
#config_handlers ⇒ Object
readonly
Returns the value of attribute config_handlers.
-
#db_check_frequency ⇒ Object
Returns the value of attribute db_check_frequency.
-
#failover_attempts ⇒ Object
Returns the value of attribute failover_attempts.
-
#failover_check_frequency ⇒ Object
Returns the value of attribute failover_check_frequency.
Instance Method Summary collapse
- #active_servers_conninfo(handler, server_store) ⇒ Object
- #add_handler(handler) ⇒ Object
-
#initialize(config_path = "") ⇒ FailoverMonitor
constructor
A new instance of FailoverMonitor.
- #monitor ⇒ Object
- #monitor_loop ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config_path = "") ⇒ FailoverMonitor
Returns a new instance of FailoverMonitor.
15 16 17 18 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 15 def initialize(config_path = "") initialize_settings(config_path) @config_handlers = [] end |
Instance Attribute Details
#config_handlers ⇒ Object (readonly)
Returns the value of attribute config_handlers.
13 14 15 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 13 def config_handlers @config_handlers end |
#db_check_frequency ⇒ Object
Returns the value of attribute db_check_frequency.
12 13 14 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 12 def db_check_frequency @db_check_frequency end |
#failover_attempts ⇒ Object
Returns the value of attribute failover_attempts.
12 13 14 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 12 def failover_attempts @failover_attempts end |
#failover_check_frequency ⇒ Object
Returns the value of attribute failover_check_frequency.
12 13 14 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 12 def failover_check_frequency @failover_check_frequency end |
Instance Method Details
#active_servers_conninfo(handler, server_store) ⇒ Object
62 63 64 65 66 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 62 def active_servers_conninfo(handler, server_store) servers = server_store.connection_info_list current_params = handler.read servers.map! { |info| current_params.merge(info) } end |
#add_handler(handler) ⇒ Object
20 21 22 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 20 def add_handler(handler) @config_handlers << [handler, ServerStore.new] end |
#monitor ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 24 def monitor config_handlers.each do |handler, server_store| begin connection = pg_connection(handler.read) if connection server_store.update_servers(connection, handler.name) connection.finish next end log_settings server_store.log_current_server_store(handler.name) logger.error("#{log_prefix(__callee__)} Primary Database is not available for #{handler.name}. Starting to execute failover...") handler.do_before_failover new_conn_info = execute_failover(handler, server_store) # Upon success, we pass a connection hash handler.do_after_failover(new_conn_info) if new_conn_info rescue => e logger.error("#{log_prefix(__callee__)} Received #{e.class} error while monitoring #{handler.name}: #{e.}") logger.error(e.backtrace) end end end |
#monitor_loop ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/manageiq/postgres_ha_admin/failover_monitor.rb', line 50 def monitor_loop loop do begin monitor rescue => err logger.error("#{log_prefix(__callee__)} #{err.class}: #{err}") logger.error(err.backtrace.join("\n")) end sleep(db_check_frequency) end end |