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());
}
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);
}
}
}
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());
}
}
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());
}
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();
}
Aggregations