Search in sources :

Example 56 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomee by apache.

the class EjbdJmxTest method test.

@Test
public void test() throws Exception {
    System.setProperty("openejb.jmx.active", "true");
    final MBeanServer server = LocalMBeanServer.get();
    OpenEJB.init(new Properties());
    final Properties p = new Properties();
    p.put("server", "org.apache.openejb.server.ejbd.EjbServer");
    p.put("bind", "127.0.0.1");
    p.put("port", "0");
    p.put("disabled", "false");
    p.put("threads", "10");
    p.put("backlog", "200");
    p.put("discovery", "ejb:ejbd://{bind}:{port}");
    final ServerService service = ServiceManager.manage("ejbd", p, new EjbServer());
    service.init(p);
    service.start();
    ServiceManager.register("ejbd", service, server);
    ObjectName invocationsName = new ObjectName("openejb:type=ServerService,name=ejbd");
    MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
    for (MBeanAttributeInfo info : beanInfo.getAttributes()) {
        System.out.println(info);
    }
    service.stop();
    OpenEJB.destroy();
}
Also used : MBeanInfo(javax.management.MBeanInfo) ServerService(org.apache.openejb.server.ServerService) Properties(java.util.Properties) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 57 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project cdap by caskdata.

the class OperationalStatsHttpHandler method getStats.

/**
   * Reads operational stats collected using the {@link OperationalStats} extension mechanism with the specified
   * property key and value, grouped by the specified groupByKey.
   *
   * @param propertyKey the key that must be contained with the specified value in the stat to be returned
   * @param propertyValue the value that the specified key must have in the stat to be returned
   * @param groupByKey an additional key in the stat's property to group the stats by
   * @return a {@link Map} of the group to a {@link Map} of stats of that group
   * @throws Exception when there are errors reading stats using JMX
   */
@VisibleForTesting
Map<String, Map<String, Object>> getStats(String propertyKey, String propertyValue, String groupByKey) throws Exception {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey), "Property should not be null or empty.");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyValue), "Property value should not be null or empty.");
    Hashtable<String, String> properties = new Hashtable<>();
    // we want stats with the specified value for the specified key, so set them in the properties
    properties.put(propertyKey, propertyValue);
    // since we want to group by the groupKey, we want to fetch all groups
    properties.put(groupByKey, "*");
    ObjectName objectName = new ObjectName(OperationalStatsUtils.JMX_DOMAIN, properties);
    Map<String, Map<String, Object>> result = new HashMap<>();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (ObjectName name : mbs.queryNames(objectName, null)) {
        String group = name.getKeyProperty(groupByKey);
        MBeanInfo mBeanInfo = mbs.getMBeanInfo(name);
        Map<String, Object> stats = new HashMap<>();
        for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
            stats.put(attributeInfo.getName(), mbs.getAttribute(name, attributeInfo.getName()));
        }
        result.put(group, stats);
        LOG.trace("Found stats of group {} as {}", group, stats);
    }
    return result;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) HashMap(java.util.HashMap) Map(java.util.Map) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 58 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) MBeanInfo(javax.management.MBeanInfo) Hashtable(java.util.Hashtable) ObjectInstance(javax.management.ObjectInstance) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) Iterator(java.util.Iterator) MBeanServerConnection(javax.management.MBeanServerConnection) HashSet(java.util.HashSet)

Example 59 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project flink by apache.

the class JMXReporterTest method testHistogramReporting.

/**
	 * Tests that histograms are properly reported via the JMXReporter.
	 */
@Test
public void testHistogramReporting() throws Exception {
    MetricRegistry registry = null;
    String histogramName = "histogram";
    try {
        Configuration config = new Configuration();
        config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "jmx_test");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
        registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
        TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
        TestingHistogram histogram = new TestingHistogram();
        metricGroup.histogram(histogramName, histogram);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
        MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
        MBeanAttributeInfo[] attributeInfos = info.getAttributes();
        assertEquals(11, attributeInfos.length);
        assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count"));
        assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean"));
        assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev"));
        assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max"));
        assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min"));
        assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median"));
        assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile"));
        assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile"));
    } finally {
        if (registry != null) {
            registry.shutdown();
        }
    }
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MBeanInfo(javax.management.MBeanInfo) TestingHistogram(org.apache.flink.runtime.metrics.util.TestingHistogram) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 60 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomcat by apache.

the class Registry method getType.

// -------------------- Helpers  --------------------
/**
     * Get the type of an attribute of the object, from the metadata.
     *
     * @param oname The bean name
     * @param attName The attribute name
     * @return null if metadata about the attribute is not found
     * @since 1.1
     */
public String getType(ObjectName oname, String attName) {
    String type = null;
    MBeanInfo info = null;
    try {
        info = server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info("Can't find metadata for object" + oname);
        return null;
    }
    MBeanAttributeInfo[] attInfo = info.getAttributes();
    for (int i = 0; i < attInfo.length; i++) {
        if (attName.equals(attInfo[i].getName())) {
            type = attInfo[i].getType();
            return type;
        }
    }
    return null;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7