Search in sources :

Example 1 with MBeanServerConnection

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);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 2 with MBeanServerConnection

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());
}
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 3 with MBeanServerConnection

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();
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeInfoDialog(org.talend.designer.esb.runcontainer.ui.dialog.RuntimeInfoDialog) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 4 with MBeanServerConnection

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 });
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 5 with MBeanServerConnection

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 });
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)261 ObjectName (javax.management.ObjectName)154 JMXConnector (javax.management.remote.JMXConnector)141 JMXServiceURL (javax.management.remote.JMXServiceURL)110 IOException (java.io.IOException)62 Test (org.junit.Test)56 HashMap (java.util.HashMap)47 JMXConnectorServer (javax.management.remote.JMXConnectorServer)40 MBeanServer (javax.management.MBeanServer)31 MalformedObjectNameException (javax.management.MalformedObjectNameException)27 MalformedURLException (java.net.MalformedURLException)23 Attribute (javax.management.Attribute)23 Map (java.util.Map)18 MBeanInfo (javax.management.MBeanInfo)17 ArrayList (java.util.ArrayList)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 NotificationListener (javax.management.NotificationListener)13 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)13 List (java.util.List)12 Set (java.util.Set)12