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