Sha256: 4c640f6e9723de9f68c0f97f346ff90a74ddbb03038e56bdc88343cfbf99e3b2
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
module 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[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'] }.uniq.compact end def self.get_nodes nodes = get_target_connections('Passenger') nodes.empty? ? [my_ip] : nodes end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
marty-1.1.8 | lib/diagnostic/node.rb |
marty-1.1.7 | lib/diagnostic/node.rb |
marty-1.1.6 | lib/diagnostic/node.rb |