Class: EngineYard::VisualVM::CLI

Inherits:
Thor
  • Object
show all
Includes:
EY::UtilityMethods, Helpers
Defined in:
lib/engineyard-visualvm/cli.rb

Constant Summary

Constants included from Helpers

Helpers::STARTING_PORT

Instance Method Summary collapse

Methods included from Helpers

#agent_jar_path, #environment, #fetch_public_ip, #find_executable?, #find_tools_jar, #host, included, #jmx_service_url, #jvm_arguments, next_free_port, #next_free_port, #port, port_available?, #socks_proxy?, #ssh?, #ssh_host, #user

Instance Method Details

#help(task = nil, *args) ⇒ Object



214
215
216
217
218
219
220
221
# File 'lib/engineyard-visualvm/cli.rb', line 214

def help(task = nil, *args)
  unless task
    puts "usage: ey-visualvm <task> [options|arguments]"
    puts "Make JMX and VisualVM more accessible to your server-side JVM."
    puts
  end
  super
end

#jvmargsObject



152
153
154
# File 'lib/engineyard-visualvm/cli.rb', line 152

def jvmargs
  puts jvm_arguments
end

#startObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/engineyard-visualvm/cli.rb', line 171

def start
  unless find_executable?("jvisualvm")
    warn "Could not find \`jvisualvm\'; do you need to install the JDK?"
    exit 1
  end

  visualvm_args = []

  if ssh?
    ssh_dest = ssh_host
    unless system "ssh #{ssh_dest} true"
      warn "Error establishing ssh connection; make sure you can `ssh #{ssh_dest}'."
      exit 3
    end

    if socks_proxy?
      proxy_port = next_free_port
      visualvm_args += ["-J-Dnetbeans.system_socks_proxy=localhost:#{proxy_port}", "-J-Djava.net.useSystemProxies=true"]
      @ssh_process = ChildProcess.build("ssh", "-ND", proxy_port.to_s, ssh_dest)
    else
      server_host, server_port = host, port
      @host, @port = "localhost", next_free_port
      @ssh_process = ChildProcess.build("ssh", "-NL", "#{@port}:#{@host}:#{server_port}", ssh_dest)
    end

    @ssh_process.start
  end

  visualvm_args += ["--openjmx", jmx_service_url.to_s]
  visualvm = ChildProcess.build("jvisualvm", *visualvm_args)
  visualvm.start

  loop do
    visualvm.exited? && break
    sleep 1
  end

  @ssh_process.stop if @ssh_process
rescue EY::Error => e
  warn e.message
  exit 2
end

#urlObject



157
158
159
# File 'lib/engineyard-visualvm/cli.rb', line 157

def url
  puts jmx_service_url
end

#versionObject



162
163
164
# File 'lib/engineyard-visualvm/cli.rb', line 162

def version
  puts "ey-visualvm version #{EngineYard::VisualVM::VERSION}"
end