Refine search
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); } }
private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map, Map<Integer, LocalVirtualMachine> existingVmMap) List<VirtualMachineDescriptor> vms = VirtualMachine.list(); for (VirtualMachineDescriptor vmd : vms) try VirtualMachine vm = VirtualMachine.attach(vmd); attachable = true; Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach();
private void attachAgent(final String targetJvmPid, final String agentJarPath, final String cfg) throws Exception { VirtualMachine vmObj = null; try { vmObj = VirtualMachine.attach(targetJvmPid); if (vmObj != null) { vmObj.loadAgent(agentJarPath, cfg); } } finally { if (null != vmObj) { vmObj.detach(); } } }
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; } }
@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")); }
String options = sb.toString(); Integer pid = pids.get(0); final VirtualMachine vm = VirtualMachine.attach("" + pid); log.log(Level.INFO, "Loading agent with command " + options + " as agent " + agentFile.getCanonicalPath()); vm.loadAgent(agentFile.getCanonicalPath(), options); server.accept(); shell = server.getShell(); for (Integer pid : pids) { log.log(Level.INFO, "Attaching to remote process " + pid); VirtualMachine vm = VirtualMachine.attach("" + pid); String options = sb.toString(); log.log(Level.INFO, "Loading agent with command " + options + " as agent " + agentFile.getCanonicalPath()); vm.loadAgent(agentFile.getCanonicalPath(), options); Properties config = new Properties(); for (String property : properties) { int index = property.indexOf('='); if (index == -1) { config.setProperty(property, ""); } else { config.setProperty(property.substring(0, index), property.substring(index + 1));
List<VirtualMachineDescriptor> vms = VirtualMachine.list(); for (VirtualMachineDescriptor desc : vms) { VirtualMachine vm; try { vm = VirtualMachine.attach(desc); } catch (AttachNotSupportedException e) { continue; } Properties props = vm.getAgentProperties(); String connectorAddress = props.getProperty("com.sun.management.jmxremote.localConnectorAddress"); if (connectorAddress == null) { continue; } JMXServiceURL url = new JMXServiceURL(connectorAddress); JMXConnector connector = JMXConnectorFactory.connect(url); try { MBeanServerConnection mbeanConn = connector.getMBeanServerConnection(); Set<ObjectName> beanSet = mbeanConn.queryNames(null, null); ... } finally { jmxConnector.close(); } }
VirtualMachine vm = VirtualMachine.attach(String.valueOf(pid)); try { Properties agentProps = vm.getAgentProperties(); connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS); vm.startLocalManagementAgent(); agentProps = vm.getAgentProperties(); connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS); vm.detach();
@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(); }
for(VirtualMachineDescriptor d : VirtualMachine.list()) { String remoteUniqueId = VirtualMachine.attach(d).getSystemProperties().getProperty("processSettings.unique.id"); if(remoteUniqueId != null && remoteUniqueId.equals(uniqueId)) String agent = virtualMachine.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; virtualMachine.loadAgent(agent); final Object portObject = virtualMachine.getAgentProperties(). get("com.sun.management.jmxremote.localConnectorAddress");
// 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();
private String getJmxUrlForProcessRegex(String processRegex) throws com.sun.tools.attach.AttachNotSupportedException, IOException { for (com.sun.tools.attach.VirtualMachineDescriptor vmd : com.sun.tools.attach.VirtualMachine.list()) { if (vmd.displayName().matches(processRegex)) { com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(vmd); String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); // If jmx agent is not running in VM, load it and return the connector url if (connectorAddress == null) { loadJmxAgent(vm); // agent is started, get the connector address connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } return connectorAddress; } } throw new IOException( "No match found. Available JVMs can be listed with the `list_jvms` command."); }
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); } } }
VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(PID); try { Properties props = vm.getAgentProperties(); System.out.println(props.getProperty("sun.jdwp.listenerAddress")); } finally { vm.detach(); }
@Override protected String getJmxUrl() { String address = null; try { address = withTimeout(() -> vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS)); } catch (Exception e) { //ignore } if (address==null) { try { address = withTimeout(() -> vm.startLocalManagementAgent()); } catch (Exception e) { logger.error("Error starting local management agent", e); } } return address; }
private static String getProperty(String id, String property) { VirtualMachine vm = null; try { vm = VirtualMachine.attach(id); String value = (String)vm.getSystemProperties().get(property); return value; } catch (AttachNotSupportedException e) { return null; } catch (IOException e) { return null; } finally { if (vm != null) { try { vm.detach(); } catch (IOException e) { // ignore; } } } }
public static LocalVirtualMachine getDelegateMachine(VirtualMachine vm) throws IOException { // privileges. boolean attachable = false; String address = null; String name = String.valueOf(vm.id()); // default display name to pid attachable = true; Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach(); return new LocalVirtualMachine(Integer.parseInt(vm.id()), name, attachable, address); }
vm = VirtualMachine.attach( String.valueOf( pid ) ); Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get( "com.sun.management.jmxremote.localConnectorAddress" ); address = vm.startLocalManagementAgent(); return new LocalVirtualMachine( address, vm.getSystemProperties() ); vm.detach();
public static void loadAgent() { logger.info("dynamically loading javaagent"); String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName(); int p = nameOfRunningVM.indexOf('@'); String pid = nameOfRunningVM.substring(0, p); try { VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(jarFilePath, ""); vm.detach(); } catch (Exception e) { throw new RuntimeException(e); } }
throw new IllegalArgumentException("Install : invalid pid " +id); vm = VirtualMachine.attach(Integer.toString(pid)); } else { List<VirtualMachineDescriptor> vmds = VirtualMachine.list(); for (VirtualMachineDescriptor vmd: vmds) { String displayName = vmd.displayName(); vm = VirtualMachine.attach(vmd); return; vm = VirtualMachine.attach(vmd); return;