Search in sources :

Example 81 with ObjectInstance

use of javax.management.ObjectInstance 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 82 with ObjectInstance

use of javax.management.ObjectInstance in project spring-boot by spring-projects.

the class SpringApplicationAdminJmxAutoConfigurationTests method registeredWithProperty.

@Test
public void registeredWithProperty() throws Exception {
    load(ENABLE_ADMIN_PROP);
    ObjectName objectName = createDefaultObjectName();
    ObjectInstance objectInstance = this.mBeanServer.getObjectInstance(objectName);
    assertThat(objectInstance).as("Lifecycle bean should have been registered").isNotNull();
}
Also used : ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 83 with ObjectInstance

use of javax.management.ObjectInstance in project spring-boot by spring-projects.

the class InfinispanCacheStatisticsProvider method getObjectName.

@Override
protected ObjectName getObjectName(SpringCache cache) throws MalformedObjectNameException {
    ObjectName name = new ObjectName("org.infinispan:component=Statistics,type=Cache,name=\"" + cache.getName() + "(local)\",*");
    Set<ObjectInstance> instances = getMBeanServer().queryMBeans(name, null);
    if (instances.size() == 1) {
        return instances.iterator().next().getObjectName();
    }
    // None or more than one
    return null;
}
Also used : ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName)

Example 84 with ObjectInstance

use of javax.management.ObjectInstance in project neo4j by neo4j.

the class KernelProxy method allBeans.

protected List<Object> allBeans() {
    List<Object> beans = new ArrayList<Object>();
    Iterable<ObjectInstance> mbeans;
    try {
        mbeans = server.queryMBeans(mbeanQuery(), null);
    } catch (IOException handled) {
        return beans;
    }
    for (ObjectInstance instance : mbeans) {
        String className = instance.getClassName();
        Class<?> beanType = null;
        try {
            if (className != null) {
                beanType = Class.forName(className);
            }
        } catch (Exception ignored) {
        // fall through
        } catch (LinkageError ignored) {
        // fall through
        }
        if (beanType != null) {
            try {
                beans.add(BeanProxy.load(server, beanType, instance.getObjectName()));
            } catch (Exception ignored) {
            // fall through
            }
        }
    }
    return beans;
}
Also used : ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 85 with ObjectInstance

use of javax.management.ObjectInstance in project pulsar by yahoo.

the class MBeanStatsGenerator method generate.

private Collection<Metrics> generate() {
    List<Metrics> metricsCollection = new ArrayList<Metrics>();
    @SuppressWarnings("unchecked") Set<ObjectInstance> instances = mbs.queryMBeans(null, null);
    for (ObjectInstance instance : instances) {
        String beanName = instance.getObjectName().toString();
        // skip GC MBean to avoid recursion
        if (beanName.startsWith("java.lang:type=GarbageCollector")) {
            continue;
        }
        Metrics metrics = convert(instance);
        if (metrics != null) {
            metricsCollection.add(metrics);
        }
    }
    return metricsCollection;
}
Also used : ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance)

Aggregations

ObjectInstance (javax.management.ObjectInstance)172 ObjectName (javax.management.ObjectName)102 Test (org.junit.Test)38 MBeanServer (javax.management.MBeanServer)36 InstanceNotFoundException (javax.management.InstanceNotFoundException)28 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)16 MBeanInfo (javax.management.MBeanInfo)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)15 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 HashMap (java.util.HashMap)13 Attribute (javax.management.Attribute)13 HashSet (java.util.HashSet)12 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)11 Result (com.googlecode.jmxtrans.model.Result)11 Set (java.util.Set)11 ReflectionException (javax.management.ReflectionException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 Test (org.junit.jupiter.api.Test)10 MBeanServerConnection (javax.management.MBeanServerConnection)9