use of javax.management.MBeanServerConnection in project jersey by jersey.
the class Main method main.
public static void main(String[] args) throws Exception {
// e.g. "service:jmx:rmi:///jndi/rmi://sysifos.cz.oracle.com:11112/jmxrmi"
final String jmxUrl = args[0];
// e.g. "org.glassfish.jersey.test.performance.interceptor.dynamic:type=DynamicallyBoundInterceptorResource,name=gets"
final String mBeanName = args[1];
// e.g. "OneMinuteRate"
final String mBeanAttrName = args[2];
// e.g. 50
final int sampleCount = Integer.parseInt(args[3]);
// e.g. "phishing.properties"
final String propertiesFile = args[4];
System.out.printf("JMX URL = %s\nMBean = %s\nattribute = %s\nsamples = %d\nfilename = %s\n" + "Going to connect...\n", jmxUrl, mBeanName, mBeanAttrName, sampleCount, propertiesFile);
final JMXServiceURL url = new JMXServiceURL(jmxUrl);
final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
final MBeanServerConnection mBeanServer = jmxc.getMBeanServerConnection();
final ObjectName mBeanObjectName = new ObjectName(mBeanName);
System.out.println("Connected...");
double totalSum = 0;
int samplesTaken = 0;
for (int i = 0; i < sampleCount; i++) {
Thread.sleep(5000);
Double sample = (Double) mBeanServer.getAttribute(mBeanObjectName, mBeanAttrName);
System.out.printf("OMR[%d]=%f\n", i, sample);
totalSum += sample;
samplesTaken++;
}
jmxc.close();
final double result = totalSum / samplesTaken;
writeResult(result, propertiesFile);
System.out.printf("\nAverage=%f\n", result);
}
use of javax.management.MBeanServerConnection in project hadoop by apache.
the class TestJMXGet method testNameNode.
/**
* test JMX connection to NameNode..
* @throws Exception
*/
@Test
public void testNameNode() throws Exception {
int numDatanodes = 2;
cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
cluster.waitActive();
DFSTestUtil.createFile(cluster.getFileSystem(), new Path("/test1"), fileSize, fileSize, blockSize, (short) 2, seed);
JMXGet jmx = new JMXGet();
String serviceName = "NameNode";
jmx.setService(serviceName);
// default lists namenode mbeans only
jmx.init();
assertTrue("error printAllValues", checkPrintAllValues(jmx));
//get some data from different source
try {
DFSTestUtil.waitForMetric(jmx, "NumLiveDataNodes", numDatanodes);
} catch (TimeoutException e) {
assertEquals(String.format(WRONG_METRIC_VALUE_ERROR_MSG, "NumLiveDataNodes"), numDatanodes, Integer.parseInt(jmx.getValue("NumLiveDataNodes")));
}
assertGauge("CorruptBlocks", Long.parseLong(jmx.getValue("CorruptBlocks")), getMetrics("FSNamesystem"));
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 tesb-studio-se by Talend.
the class OpenRuntimeInfoAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
MBeanServerConnection mbsc;
try {
mbsc = JMXUtil.createJMXconnection();
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//$NON-NLS-1$
String JOB_MBEAN = "TalendAgent:type=O.S. Informations";
ObjectName objectJob = new ObjectName(JOB_MBEAN);
MBeanInfo info = mbsc.getMBeanInfo(objectJob);
MBeanAttributeInfo[] attrInfo = info.getAttributes();
for (int i = 0; i < attrInfo.length; i++) {
try {
Map<String, String> attributeMap = new HashMap<String, String>();
String attributeName = attrInfo[i].getName();
//$NON-NLS-1$
attributeMap.put("name", attributeName);
String attributeDesc = attrInfo[i].getType();
//$NON-NLS-1$
attributeMap.put("desc", attributeDesc);
String attributeValue = mbsc.getAttribute(objectJob, attributeName).toString();
attributeMap.put(attributeName, attributeValue);
//$NON-NLS-1$
attributeMap.put("value", attributeValue);
list.add(attributeMap);
} catch (Exception e) {
e.printStackTrace();
}
}
RuntimeInfoDialog dlg = new RuntimeInfoDialog(list);
dlg.open();
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.management.MBeanServerConnection in project tesb-studio-se by Talend.
the class JMXUtil method rebootCleanAll.
public static void rebootCleanAll() throws Exception {
// need to re connect
MBeanServerConnection mbsc = createJMXconnection();
String SYS_MBEAN = "org.apache.karaf:type=system,name=" + instanceName;
ObjectName objectKar = new ObjectName(SYS_MBEAN);
mbsc.invoke(objectKar, "rebootCleanAll", new Object[] { String.valueOf(0) }, new String[] { STRING });
}
use of javax.management.MBeanServerConnection in project tesb-studio-se by Talend.
the class JMXUtil method reboot.
public static void reboot() throws Exception {
// need to re connect
MBeanServerConnection mbsc = createJMXconnection();
String SYS_MBEAN = "org.apache.karaf:type=system,name=" + instanceName;
ObjectName objectKar = new ObjectName(SYS_MBEAN);
mbsc.invoke(objectKar, "reboot", new Object[] { String.valueOf(0) }, new String[] { STRING });
}
Aggregations