Search in sources :

Example 76 with MBeanServerConnection

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

the class TestJMXGet method testDataNode.

/**
   * test JMX connection to DataNode..
   * @throws Exception 
   */
@Test
public void testDataNode() throws Exception {
    int numDatanodes = 2;
    cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
    cluster.waitActive();
    DFSTestUtil.createFile(cluster.getFileSystem(), new Path("/test"), fileSize, fileSize, blockSize, (short) 2, seed);
    JMXGet jmx = new JMXGet();
    String serviceName = "DataNode";
    jmx.setService(serviceName);
    jmx.init();
    try {
        DFSTestUtil.waitForMetric(jmx, "BytesWritten", fileSize);
    } catch (TimeoutException e) {
        assertEquals(String.format(WRONG_METRIC_VALUE_ERROR_MSG, "BytesWritten"), fileSize, Integer.parseInt(jmx.getValue("BytesWritten")));
    }
    cluster.shutdown();
    MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
    ObjectName query = new ObjectName("Hadoop:service=" + serviceName + ",*");
    Set<ObjectName> names = mbsc.queryNames(query, null);
    assertTrue("No beans should be registered for " + serviceName, names.isEmpty());
}
Also used : Path(org.apache.hadoop.fs.Path) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) JMXGet(org.apache.hadoop.hdfs.tools.JMXGet) MBeanServerConnection(javax.management.MBeanServerConnection) TimeoutException(java.util.concurrent.TimeoutException) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 77 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project druid by alibaba.

the class DruidStat method printDruidStat.

@SuppressWarnings("all")
public static void printDruidStat(Option option) throws Exception {
    PrintStream out = option.getPrintStream();
    String address = loadManagementAgentAndGetAddress(option.getPid());
    JMXServiceURL jmxUrl = new JMXServiceURL(address);
    JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl);
    MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
    if (option.printDataSourceData()) {
        List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.DATA_SOURCE);
        TabledDataPrinter.printDataSourceData(content, option);
    }
    if (option.printSqlData()) {
        List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.SQL);
        if (content == null) {
            out.println("无SqlStat统计数据,请检查是否已执行了SQL");
        } else {
            TabledDataPrinter.printSqlData(content, option);
        }
    }
    if (option.printActiveConn()) {
        List<List<String>> content = (List<List<String>>) invokeService(jmxConn, Option.ACTIVE_CONN);
        if (content == null || content.size() == 0) {
            out.println("目前无活动中的数据库连接");
        } else {
            TabledDataPrinter.printActiveConnStack(content, option);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) PrintStream(java.io.PrintStream) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 78 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project otter by alibaba.

the class JmxLoaderIntegration method test_simple.

@Test
public void test_simple() {
    MBeanServer mBeanServer = exporter.getServer();
    try {
        ObjectName objectName = new ObjectName("bean:name=otterControllor");
        MBeanInfo nodeInfo = mBeanServer.getMBeanInfo(objectName);
        System.out.println(nodeInfo);
        Object result = mBeanServer.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/mbean");
        Map environment = null;
        JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
        MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
        String domain = mbsc.getDefaultDomain();
        System.out.println(domain);
        result = mbsc.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
    } catch (Exception e) {
        want.fail(e.getMessage());
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MBeanInfo(javax.management.MBeanInfo) JMXConnector(javax.management.remote.JMXConnector) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection) RemoteException(java.rmi.RemoteException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Example 79 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-framework by spring-projects.

the class ConnectorServerFactoryBeanTests method checkServerConnection.

private void checkServerConnection(MBeanServer hostedServer) throws IOException, MalformedURLException {
    // Try to connect using client.
    JMXServiceURL serviceURL = new JMXServiceURL(ConnectorServerFactoryBean.DEFAULT_SERVICE_URL);
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
    assertNotNull("Client Connector should not be null", connector);
    // Get the MBean server connection.
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    assertNotNull("MBeanServerConnection should not be null", connection);
    // Test for MBean server equality.
    assertEquals("Registered MBean count should be the same", hostedServer.getMBeanCount(), connection.getMBeanCount());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 80 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project spring-framework by spring-projects.

the class MBeanServerConnectionFactoryBeanTests method testWithLazyConnectionAndNoAccess.

@Test
public void testWithLazyConnectionAndNoAccess() throws Exception {
    MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
    bean.setServiceUrl(serviceUrl);
    bean.setConnectOnStartup(false);
    bean.afterPropertiesSet();
    MBeanServerConnection connection = bean.getObject();
    assertTrue(AopUtils.isAopProxy(connection));
    bean.destroy();
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) 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