Class: TyrantManager::Commands::ReplicationStatus

Inherits:
TyrantManager::Command show all
Defined in:
lib/tyrant_manager/commands/replication_status.rb

Overview

Report on the replication status of the server(s)

Instance Attribute Summary

Attributes inherited from TyrantManager::Command

#manager, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TyrantManager::Command

#after, #before, #command_name, #error, find, inherited, #initialize, list, #logger

Constructor Details

This class inherits a constructor from TyrantManager::Command

Class Method Details

.command_nameObject



15
16
17
# File 'lib/tyrant_manager/commands/replication_status.rb', line 15

def self.command_name
  'replication-status'
end

Instance Method Details

#runObject



19
20
21
22
23
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
49
50
# File 'lib/tyrant_manager/commands/replication_status.rb', line 19

def run
  manager.each_instance( options['instances'] ) do |instance|
    if instance.running? and instance.is_slave? then
      s_stat = instance.stat
      logger.info "#{instance.name} is replicating from #{s_stat['mhost']}:#{s_stat['mport']}"
        if m_conn = validate_master_connection( instance ) then
          if validate_master_master( instance.connection, m_conn ) then
            m_stat = m_conn.stat
            m_name = "#{s_stat['mhost']}:#{s_stat['mport']}"

            primary, failover = instance.connection, m_conn

            if m_stat['delay'] > s_stat['delay'] then
              primary, failover = m_conn, instance.connection
            end

            p_stat = primary.stat
            p_name = "#{manager.ip_of( primary.host )}:#{primary.port}"

            f_stat = failover.stat
            f_name = "#{manager.ip_of( failover.host )}:#{failover.port}"

            n_width = [ p_name.length, f_name.length ].max

            logger.info "  Primary master  : #{p_name} -> #{p_stat['rnum']} records, primary since #{(Time.now - ( Float(primary.stat['delay']))).strftime("%Y-%m-%d %H:%M:%S")}"
            logger.info "  Failover master : #{f_name} -> #{f_stat['rnum']} records, last replicated #{failover.stat['delay']} seconds ago"
          end
        end
      logger.info ""
    end
  end
end