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(); } }
Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach();
Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
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); } }
VirtualMachine vm = VirtualMachine.attach(String.valueOf(pid)); try { Properties agentProps = vm.getAgentProperties(); connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS); agentProps = vm.getAgentProperties(); connectorAddress = agentProps.getProperty(PROPERTY_LOCAL_CONNECTOR_ADDRESS);
Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
String connectorAddress = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress", null); if(connectorAddress==null) { File managementAgentJarFile = new File(javaHome + File.separator + "lib" + File.separator + "management-agent.jar"); vm.loadAgent(managementAgentJarFile.getAbsolutePath()); connectorAddress = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress", null);
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); }
Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get( "com.sun.management.jmxremote.localConnectorAddress" );
public static LocalVirtualMachine getLocalVirtualMachine(int vmid) throws Exception { Map<Integer, LocalVirtualMachine> map = getAllVirtualMachines(); LocalVirtualMachine lvm = map.get(vmid); if (lvm == null) { // Check if the VM is attachable but not included in the list // if it's running with a different security context. // For example, Windows services running // local SYSTEM account are attachable if you have Adminstrator // privileges. boolean attachable = false; String address = null; String name = String.valueOf(vmid); // default display name to pid VirtualMachine vm = VirtualMachine.attach(name); attachable = true; Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach(); lvm = new LocalVirtualMachine(vmid, name, attachable, address); } return lvm; }
Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach();
Properties agentProps = vm.getAgentProperties(); String address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach();
@Override public Properties perform(VirtualMachine vm) throws IOException { return vm.getAgentProperties(); } }
protected int getServerPort() throws IOException { return Integer.parseInt(vm.getAgentProperties().getProperty("btrace.port", "-1")); }
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(); }
public static String loadJMXAgent(int port) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { System.setProperty("com.sun.management.jmxremote.port", Integer.toString(port)); String name = ManagementFactory.getRuntimeMXBean().getName(); VirtualMachine vm = VirtualMachine.attach(name.substring(0, name.indexOf('@'))); String lca = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress"); if (lca == null) { Path p = Paths.get(System.getProperty("java.home")).normalize(); if (!"jre".equals(p.getName(p.getNameCount()-1).toString().toLowerCase())) p = p.resolve("jre"); File f = p.resolve("lib").resolve("management-agent.jar").toFile(); if (!f.exists()) throw new IOException("Management agent not found"); vm.loadAgent(f.getCanonicalPath(), "com.sun.management.jmxremote"); lca = vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress"); } vm.detach(); return lca; }
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."); }
/** * 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("-----------------"); }
@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; }