Module: EngineYard::VisualVM::Helpers
- Included in:
- CLI
- Defined in:
- lib/engineyard-visualvm/cli.rb
Constant Summary collapse
- STARTING_PORT =
5900
Class Method Summary collapse
- .included(base) ⇒ Object
- .next_free_port(start = STARTING_PORT) ⇒ Object
- .port_available?(port) ⇒ Boolean
Instance Method Summary collapse
- #agent_jar_path ⇒ Object
- #environment ⇒ Object
-
#fetch_public_ip(environment) ⇒ Object
Return the public IP or instance hostname assigned to an environment (which may or may not be a booted cluster of instances) Displays error and exits if no public IP assigned to the environment.
- #find_executable?(exe) ⇒ Boolean
- #find_tools_jar ⇒ Object
- #host ⇒ Object
- #jmx_service_url ⇒ Object
- #jvm_arguments ⇒ Object
- #next_free_port ⇒ Object
- #port ⇒ Object
- #socks_proxy? ⇒ Boolean
- #ssh? ⇒ Boolean
- #ssh_host ⇒ Object
- #user ⇒ Object
Class Method Details
.included(base) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/engineyard-visualvm/cli.rb', line 16 def self.included(base) unless base.instance_methods.map(&:to_s).include?("options") base.class_eval do def @_opts ||= { :host => "localhost" } end end end end |
.next_free_port(start = STARTING_PORT) ⇒ Object
39 40 41 42 43 |
# File 'lib/engineyard-visualvm/cli.rb', line 39 def self.next_free_port(start = STARTING_PORT) (start...start+100).each do |i| return i if port_available?(i) end end |
.port_available?(port) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/engineyard-visualvm/cli.rb', line 26 def self.port_available?(port) begin tcps = TCPServer.new("127.0.0.1", port) true rescue Errno::EADDRINUSE false ensure tcps.close if tcps end end |
Instance Method Details
#agent_jar_path ⇒ Object
112 113 114 |
# File 'lib/engineyard-visualvm/cli.rb', line 112 def agent_jar_path File.('../agent.jar', __FILE__) end |
#environment ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/engineyard-visualvm/cli.rb', line 45 def environment @environment ||= begin fetch_environment([:environment], [:account]).tap {|env| @user = env.username @host = fetch_public_ip(env) } rescue EY::Error raise if [:environment] nil end end |
#fetch_public_ip(environment) ⇒ Object
Return the public IP or instance hostname assigned to an environment (which may or may not be a booted cluster of instances) Displays error and exits if no public IP assigned to the environment
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/engineyard-visualvm/cli.rb', line 128 def fetch_public_ip(environment) if environment.load_balancer_ip_address return environment.load_balancer_ip_address end if environment.instances.length == 1 && environment.instances.first.public_hostname return environment.instances.first.public_hostname end warn "#{environment.account.name}/#{environment.name} has no assigned public IP address or hostname." nil end |
#find_executable?(exe) ⇒ Boolean
106 107 108 109 110 |
# File 'lib/engineyard-visualvm/cli.rb', line 106 def find_executable?(exe) ENV['PATH'].split(File::PATH_SEPARATOR).detect do |path| File.exist?(File.join(path, exe)) end end |
#find_tools_jar ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/engineyard-visualvm/cli.rb', line 116 def find_tools_jar java_home = `java -classpath #{agent_jar_path} org.jruby.ext.jmx.agent.JavaHome` [File.('./lib/tools.jar', java_home), File.('../lib/tools.jar', java_home)].detect do |path| File.readable?(path) end end |
#host ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/engineyard-visualvm/cli.rb', line 73 def host @host ||= begin match = /(.*)?@(.*)/.match [:host] if match @user = match[1] match[2] else @user = nil [:host] end end end |
#jmx_service_url ⇒ Object
102 103 104 |
# File 'lib/engineyard-visualvm/cli.rb', line 102 def jmx_service_url "service:jmx:rmi://#{host}:#{port}/jndi/rmi://#{host}:#{port}/jmxrmi" end |
#jvm_arguments ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/engineyard-visualvm/cli.rb', line 94 def jvm_arguments tools_jar = find_tools_jar args = "-Dorg.jruby.jmx.agent.port=#{next_free_port} -javaagent:#{agent_jar_path}" args = "-Dorg.jruby.jmx.agent.hostname=#{host} #{args}" if host != "localhost" args = "-Xbootclasspath/a:#{tools_jar} #{args}" if tools_jar args end |
#next_free_port ⇒ Object
86 87 88 |
# File 'lib/engineyard-visualvm/cli.rb', line 86 def next_free_port Helpers.next_free_port(port) end |
#port ⇒ Object
90 91 92 |
# File 'lib/engineyard-visualvm/cli.rb', line 90 def port @port ||= Numeric === [:port] && [:port] || STARTING_PORT end |
#socks_proxy? ⇒ Boolean
65 66 67 |
# File 'lib/engineyard-visualvm/cli.rb', line 65 def socks_proxy? [:socks] end |
#ssh? ⇒ Boolean
61 62 63 |
# File 'lib/engineyard-visualvm/cli.rb', line 61 def ssh? environment || (host && user) || [:ssh] || [:socks] end |
#ssh_host ⇒ Object
69 70 71 |
# File 'lib/engineyard-visualvm/cli.rb', line 69 def ssh_host user ? "#{user}@#{host}" : host end |
#user ⇒ Object
57 58 59 |
# File 'lib/engineyard-visualvm/cli.rb', line 57 def user @user end |