Sha256: e13015a6e078aaafa62348adf75e7c5eba056686acc4429886d2d62da333a05b

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module Marty::Diagnostic::Node
  def self.my_ip
    begin
      Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.ip_address
    rescue => e
      e.message
    end
  end

  def self.get_postgres_connections
    conn = ActiveRecord::Base.connection.execute('SELECT datname,'\
                                                 'application_name,'\
                                                 'state,'\
                                                 'pid,'\
                                                 'client_addr '\
                                                 'FROM pg_stat_activity')
    conn.each_with_object({}) do |conn, h|
      h[conn['datname']] ||= []
      h[conn['datname']] << conn.except('datname')
    end
  end

  def self.get_target_connections target
    get_postgres_connections[Marty::Diagnostic::Database.db_name].select{|conn|
      conn['application_name'].include?(target)
    }.map{|conn|
      conn['client_addr'] == '127.0.0.1' ? my_ip :
        conn['client_addr'] || '127.0.0.1'
    }
  end

  def self.get_nodes
    nodes = get_target_connections('Passenger').uniq.compact
    nodes.empty? ? [my_ip] : nodes
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
marty-2.1.5 other/marty/diagnostic/node.rb
marty-2.3.0 other/marty/diagnostic/node.rb
marty-2.1.4 other/marty/diagnostic/node.rb
marty-2.1.3 other/marty/diagnostic/node.rb
marty-2.1.2 other/marty/diagnostic/node.rb
marty-2.1.1 other/marty/diagnostic/node.rb
marty-2.1.0 other/marty/diagnostic/node.rb
marty-2.0.9 other/marty/diagnostic/node.rb
marty-2.0.8 other/marty/diagnostic/node.rb
marty-2.0.7 other/marty/diagnostic/node.rb
marty-2.0.6 other/marty/diagnostic/node.rb
marty-2.0.5 other/marty/diagnostic/node.rb
marty-2.0.4 other/marty/diagnostic/node.rb
marty-2.0.3 other/marty/diagnostic/node.rb
marty-2.0.2 other/marty/diagnostic/node.rb
marty-2.0.1 other/marty/diagnostic/node.rb
marty-2.0.0 other/marty/diagnostic/node.rb