private static String getJavaHome(BTraceTask btt) { try { VirtualMachine vm = VirtualMachine.attach(String.valueOf(btt.getPid())); return vm.getSystemProperties().getProperty("java.home"); } catch (AttachNotSupportedException e) { LOGGER.log(Level.SEVERE, null, e); } catch (IOException e) { LOGGER.log(Level.SEVERE, null, e); } return null; } }
String home = vm.getSystemProperties().getProperty("java.home");
@Override public int getTaskPort(BTraceTask task) { VirtualMachine vm = null; try { vm = VirtualMachine.attach(String.valueOf(task.getPid())); String portStr = vm.getSystemProperties().getProperty(PORT_PROPERTY); return portStr != null ? Integer.parseInt(portStr) : findFreePort(); } catch (AttachNotSupportedException ex) { Logger.getLogger(PortLocatorImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PortLocatorImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (vm != null) { try { vm.detach(); } catch (IOException e) { LOGGER.log(Level.SEVERE, null, e); } } } return findFreePort(); }
String home = vm.getSystemProperties().getProperty("java.home");
VirtualMachine vm = VirtualMachine.attach(vid); if(!vm.getSystemProperties().contains("demo.agent.installed")) { vm.loadAgent(agentPath); if(connectorAddress==null) { String javaHome = vm.getSystemProperties().getProperty("java.home"); File managementAgentJarFile = new File(javaHome + File.separator + "lib" + File.separator + "management-agent.jar"); vm.loadAgent(managementAgentJarFile.getAbsolutePath());
String home = vm.getSystemProperties().getProperty("java.home");
public static JMXServiceURL extractJMXServiceURLFromPid(String pid) throws IOException { try { VirtualMachine vm = VirtualMachine.attach(pid); try { String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); if (connectorAddress == null) { String agent = vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent); connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } return new JMXServiceURL(connectorAddress); } finally { vm.detach(); } } catch(Exception e) { throw new IOException(e); } }
return new LocalVirtualMachine( address, vm.getSystemProperties() );
try { vm = VirtualMachine.attach(name); if(magic.equals(vm.getSystemProperties().getProperty("magic"))) break getVM; } catch(Exception ex){} if(magic.equals(vm.getSystemProperties().getProperty("magic"))) break getVM; vm.detach();
String home = vm.getSystemProperties().getProperty("java.home"); Properties localProperties = vm.getSystemProperties(); this.address = ((String) localProperties .get("com.sun.management.jmxremote.localConnectorAddress"));
debugPrint("checking port availability: " + port); Properties serverVmProps = vm.getSystemProperties(); int serverPort = Integer.parseInt(serverVmProps.getProperty("btrace.port", "-1")); if (serverPort != -1) {
String home = vm.getSystemProperties().getProperty("java.home");
@Override public Properties perform(VirtualMachine vm) throws IOException { return vm.getSystemProperties(); } }
private void loadJmxAgent(com.sun.tools.attach.VirtualMachine vm) throws IOException { String agent = vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; try { vm.loadAgent(agent); } catch (Exception e) { LOGGER.warn("Error initializing JMX agent", e); } } }
@Override public Properties getSystemProperties() throws Exception { try { return withTimeout(() -> vm.getSystemProperties()); } catch (Exception e) { logger.error("Fetching systemprops from local app failed: {}", ExceptionUtil.getMessage(e)); throw e; } }
// attach to target VM VirtualMachine vm = VirtualMachine.attach("2177"); // get system properties in target VM Properties props = vm.getSystemProperties(); // construct path to management agent String home = props.getProperty("java.home"); String agent = home + File.separator + "lib" + File.separator + "your-agent-example.jar"; // load agent into target VM vm.loadAgent(agent, "com.sun.management.jmxremote.port=5000"); // detach vm.detach();
@SuppressWarnings("unused") private static String attachManagementAgent(VirtualMachine vm) throws IOException, AgentLoadException, AgentInitializationException { Properties localProperties = vm.getAgentProperties(); if (localProperties.containsKey("com.sun.management.jmxremote.localConnectorAddress")) { return ((String)localProperties.get("com.sun.management.jmxremote.localConnectorAddress")); } String jhome = vm.getSystemProperties().getProperty("java.home"); Object localObject = jhome + File.separator + "jre" + File.separator + "lib" + File.separator + "management-agent.jar"; File localFile = new File((String)localObject); if (!(localFile.exists())) { localObject = jhome + File.separator + "lib" + File.separator + "management-agent.jar"; localFile = new File((String)localObject); if (!(localFile.exists())) { throw new IOException("Management agent not found"); } } localObject = localFile.getCanonicalPath(); vm.loadAgent((String)localObject, "com.sun.management.jmxremote"); localProperties = vm.getAgentProperties(); return ((String)localProperties.get("com.sun.management.jmxremote.localConnectorAddress")); }
@Override public Properties call() throws Exception { VirtualMachine vm = null; try { vm = VirtualMachine.attach(id); return vm.getSystemProperties(); } finally { if (vm != null) { vm.detach(); } } } });
/** * For testing / investigation purposes. Dumps out as much information as possible * that can be onbtained from the jvm, without accessing JMX. */ public void dumpJvmInfo() throws IOException { System.out.println("--- vm infos ----"); System.out.println("id = "+vm.id()); System.out.println("displayName = "+vmd.displayName()); dump("agentProperties", vm.getAgentProperties()); dump("systemProps", vm.getSystemProperties()); System.out.println("-----------------"); }
public JMXConnector createJMXConnector(String id) throws IOException,AgentLoadException, AgentInitializationException, AttachNotSupportedException { // attach to the target application VirtualMachine vm = VirtualMachine.attach(id); // get the connector address String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); // no connector address, so we start the JMX agent if (connectorAddress == null) { String agent = vm.getSystemProperties() .getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent); // agent is started, get the connector address connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } // establish connection to connector server JMXServiceURL url = new JMXServiceURL(connectorAddress); return JMXConnectorFactory.connect(url); }