use of javax.management.remote.JMXServiceURL in project warn-report by saaavsaaa.
the class TestAgentVMAttacher method test.
// consult: http://ayufox.iteye.com/blog/653214
/*
* HotSpotDiagnosticMXBean
* ClassLoadingMXBean
* CompilationMXBean
* GarbageCollectorMXBean
* MemoryManagerMXBean
* MemoryPoolMXBean
* OperatingSystemMXBean
* RuntimeMXBean
* ThreadMXBeanisolatering
* */
@Test
public void test() throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
// args[0]传入的是某个jvm进程的pid
String targetPid = "9527";
VirtualMachine virtualmachine = VirtualMachine.attach(targetPid);
// 让JVM加载jmx Agent
String javaHome = virtualmachine.getSystemProperties().getProperty("java.home");
String jmxAgent = javaHome + File.separator + "lib" + File.separator + "management-agent.jar";
virtualmachine.loadAgent(jmxAgent, "com.sun.management.jmxremote");
// 获得连接地址
Properties properties = virtualmachine.getAgentProperties();
String address = (String) properties.get("com.sun.management.jmxremote.localConnectorAddress");
// Detach
virtualmachine.detach();
// 通过jxm address来获取RuntimeMXBean对象,从而得到虚拟机运行时相关信息
JMXServiceURL url = new JMXServiceURL(address);
JMXConnector connector = JMXConnectorFactory.connect(url);
RuntimeMXBean rmxb = ManagementFactory.newPlatformMXBeanProxy(connector.getMBeanServerConnection(), "java.lang:type=Runtime", RuntimeMXBean.class);
// 得到目标虚拟机占用cpu时间
System.out.println(rmxb.getInputArguments());
}
use of javax.management.remote.JMXServiceURL in project cxf by apache.
the class MBServerConnectorFactory method createConnector.
public void createConnector() throws IOException {
if (server == null) {
server = MBeanServerHolder.INSTANCE;
}
// Create the JMX service URL.
JMXServiceURL url = new JMXServiceURL(serviceUrl);
// if the URL is localhost, start up an Registry
if (serviceUrl.indexOf("localhost") > -1 && url.getProtocol().compareToIgnoreCase("rmi") == 0) {
try {
int port = getURLLocalHostPort(serviceUrl);
try {
LocateRegistry.createRegistry(port);
} catch (Exception ex) {
// the registry may had been created
LocateRegistry.getRegistry(port);
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, "CREATE_REGISTRY_FAULT_MSG", new Object[] { ex });
}
}
// Create the connector server now.
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, server);
if (threaded) {
// Start the connector server asynchronously (in a separate thread).
Thread connectorThread = new Thread() {
public void run() {
try {
connectorServer.start();
} catch (IOException ex) {
LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG", new Object[] { ex });
}
}
};
connectorThread.setName("JMX Connector Thread [" + serviceUrl + "]");
connectorThread.setDaemon(daemon);
connectorThread.start();
} else {
// Start the connector server in the same thread.
connectorServer.start();
}
if (LOG.isLoggable(Level.INFO)) {
LOG.info("JMX connector server started: " + connectorServer);
}
}
use of javax.management.remote.JMXServiceURL in project fabric8 by jboss-fuse.
the class RestJsonSchemaJMXTest method connectToMBserver.
private void connectToMBserver() throws IOException {
jmxServerURL = jmxServerURL == null ? DEFAULT_JMXSERVICE_URL : jmxServerURL;
JMXServiceURL url = new JMXServiceURL(jmxServerURL);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
mbsc = jmxc.getMBeanServerConnection();
}
use of javax.management.remote.JMXServiceURL in project fabric8 by jboss-fuse.
the class ProvisionSupport method getMBean.
public static Object getMBean(final Container container, final ObjectName mbeanName, final Class clazz, final long timeout) throws Exception {
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(EXECUTOR);
completionService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
long time = 0;
while (time <= timeout) {
try {
JMXServiceURL url = new JMXServiceURL(container.getJmxUrl());
Map env = new HashMap();
String[] creds = { "admin", "admin" };
env.put(JMXConnector.CREDENTIALS, creds);
JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
mbsc.getObjectInstance(mbeanName);
return JMX.newMBeanProxy(mbsc, mbeanName, clazz, true);
} catch (Exception e) {
Thread.sleep(2000L);
time += 2000L;
}
}
return null;
}
});
return completionService.poll(timeout, TimeUnit.MILLISECONDS).get();
}
use of javax.management.remote.JMXServiceURL in project ysoserial by frohoff.
the class JBoss method makeVersionedConnection.
private static VersionedConnection makeVersionedConnection(Channel c) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, MalformedURLException {
VersionedConnection vc;
Class<?> vcf = Class.forName("org.jboss.remotingjmx.VersionedConectionFactory");
Method vcCreate = vcf.getDeclaredMethod("createVersionedConnection", Channel.class, Map.class, JMXServiceURL.class);
vcCreate.setAccessible(true);
vc = (VersionedConnection) vcCreate.invoke(null, c, new HashMap(), new JMXServiceURL("service:jmx:remoting-jmx://"));
return vc;
}
Aggregations