Search in sources :

Example 61 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project hbase by apache.

the class TestJMXListener method testStart.

@Test
public void testStart() throws Exception {
    JMXConnector connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
    MBeanServerConnection mb = connector.getMBeanServerConnection();
    String domain = mb.getDefaultDomain();
    Assert.assertTrue("default domain is not correct", !domain.isEmpty());
    connector.close();
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 62 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project hbase by apache.

the class TestStochasticBalancerJmxMetrics method readJmxMetrics.

/**
   * Read the attributes from Hadoop->HBase->Master->Balancer in JMX
   * @throws IOException 
   */
private Set<String> readJmxMetrics() throws IOException {
    JMXConnector connector = null;
    ObjectName target = null;
    MBeanServerConnection mb = null;
    try {
        connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
        mb = connector.getMBeanServerConnection();
        Hashtable<String, String> pairs = new Hashtable<>();
        pairs.put("service", "HBase");
        pairs.put("name", "Master");
        pairs.put("sub", "Balancer");
        target = new ObjectName("Hadoop", pairs);
        MBeanInfo beanInfo = mb.getMBeanInfo(target);
        Set<String> existingAttrs = new HashSet<>();
        for (MBeanAttributeInfo attrInfo : beanInfo.getAttributes()) {
            existingAttrs.add(attrInfo.getName());
        }
        return existingAttrs;
    } catch (Exception e) {
        LOG.warn("Failed to get bean!!! " + target, e);
        if (mb != null) {
            Set<ObjectInstance> instances = mb.queryMBeans(null, null);
            Iterator<ObjectInstance> iterator = instances.iterator();
            System.out.println("MBean Found:");
            while (iterator.hasNext()) {
                ObjectInstance instance = iterator.next();
                System.out.println("Class Name: " + instance.getClassName());
                System.out.println("Object Name: " + instance.getObjectName());
            }
        }
    } finally {
        if (connector != null) {
            try {
                connector.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) MBeanInfo(javax.management.MBeanInfo) Hashtable(java.util.Hashtable) ObjectInstance(javax.management.ObjectInstance) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) Iterator(java.util.Iterator) MBeanServerConnection(javax.management.MBeanServerConnection) HashSet(java.util.HashSet)

Example 63 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project camel by apache.

the class ManagedSEDeployableContainer method isJMXTestRunnerMBeanRegistered.

private boolean isJMXTestRunnerMBeanRegistered(final String host, final int port, int waitTime) throws DeploymentException {
    // Taken from org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext
    final String jmxServiceUrl = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
    try (JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL(jmxServiceUrl), null)) {
        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        return new Await(waitTime, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                mbsc.getObjectInstance(new ObjectName(JMXTestRunnerMBean.OBJECT_NAME));
                LOGGER.fine("JMXTestRunnerMBean registered with the remote MBean server at: " + jmxServiceUrl);
                return true;
            }
        }).start();
    } catch (IOException e) {
        throw new DeploymentException("Could not verify JMXTestRunnerMBean registration", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) IOException(java.io.IOException) Await(org.apache.camel.itest.springboot.arquillian.container.util.Await) MBeanServerConnection(javax.management.MBeanServerConnection) Callable(java.util.concurrent.Callable) ObjectName(javax.management.ObjectName)

Example 64 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jvm-tools by aragozin.

the class JmxConnectionInfo method connectJmx.

@SuppressWarnings("resource")
private MBeanServerConnection connectJmx(String host, int port, Map<String, Object> props) {
    try {
        String proto = System.getProperty("jmx.service.protocol", "rmi");
        final String uri = "rmi".equals(proto) ? "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" : "service:jmx:" + proto + "://" + host + ":" + port;
        JMXServiceURL jmxurl = new JMXServiceURL(uri);
        JMXConnector conn = props == null ? JMXConnectorFactory.connect(jmxurl) : JMXConnectorFactory.connect(jmxurl, props);
        // TODO credentials
        MBeanServerConnection mserver = conn.getMBeanServerConnection();
        return mserver;
    } catch (MalformedURLException e) {
        commandHost.fail("JMX Connection failed: " + e.toString(), e);
    } catch (IOException e) {
        commandHost.fail("JMX Connection failed: " + e.toString(), e);
    }
    return null;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 65 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jvm-tools by aragozin.

the class CaptureCheck method capture.

@Test
public void capture() throws FileNotFoundException, IOException {
    File dump = new File(taget);
    if (dump.getParentFile() != null) {
        dump.getParentFile().mkdirs();
    }
    UniversalEventWriter writer = ThreadEventCodec.createEventWriter(new FileOutputStream(dump));
    MyEventWriter twriter = TypedEventWriterProxy.decorate(writer).pass(ThreadSnapshotEvent.class).pass(GarbageCollectionEvent.class).facade(MyEventWriter.class);
    MBeanServerConnection conn = AttachManager.getJmxConnection(PID);
    GcEventSubscriber subscriber = new GcEventSubscriber(conn, new SimpleGcEventEncoder(twriter));
    if (!subscriber.subscribe()) {
        // polling fallback
        subscriber.schedule(500);
    }
    ThreadDumpSampler tdumper = new ThreadDumpSampler();
    ThreadMXBean threadMXBean = ThreadMXBeanEx.BeanHelper.connectThreadMXBean(conn);
    if (threadMXBean.isThreadContentionMonitoringSupported()) {
        threadMXBean.setThreadContentionMonitoringEnabled(true);
    }
    tdumper.connect(threadMXBean);
    long deadline = System.currentTimeMillis() + captureTime;
    ThreadEventAdapter threadWriter = new ThreadEventAdapter(twriter);
    while (System.currentTimeMillis() < deadline) {
        tdumper.collect(threadWriter);
    }
    twriter.close();
    System.out.println("Dump complete [" + dump.getPath() + "] " + dump.length() + " bytes");
    int tc = 0;
    int ntc = 0;
    EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream(dump));
    for (Event e : reader) {
        if (e instanceof ThreadSnapshotEvent) {
            ++tc;
        } else {
            ++ntc;
        }
    }
    System.out.println("Thread events: " + tc + " Non thread events: " + ntc);
}
Also used : SimpleGcEventEncoder(org.gridkit.jvmtool.gcmon.SimpleGcEventEncoder) ThreadMXBean(java.lang.management.ThreadMXBean) UniversalEventWriter(org.gridkit.jvmtool.event.UniversalEventWriter) FileInputStream(java.io.FileInputStream) GcEventSubscriber(org.gridkit.jvmtool.gcmon.GcEventSubscriber) ThreadSnapshotEvent(org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent) FileOutputStream(java.io.FileOutputStream) GarbageCollectionEvent(org.gridkit.jvmtool.gcmon.GarbageCollectionEvent) ThreadSnapshotEvent(org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent) Event(org.gridkit.jvmtool.event.Event) GarbageCollectionEvent(org.gridkit.jvmtool.gcmon.GarbageCollectionEvent) File(java.io.File) MBeanServerConnection(javax.management.MBeanServerConnection) ThreadDumpSampler(org.gridkit.jvmtool.stacktrace.ThreadDumpSampler) Test(org.junit.Test)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7