Search in sources :

Example 6 with MBeanInfo

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

the class JMXAccessorSetTask method getMBeanAttributeType.

/**
     * Get MBean Attribute from Mbean Server
     *
     * @param jmxServerConnection The JMX connection name
     * @param name The MBean name
     * @param attribute The attribute name
     * @return The type of the attribute
     * @throws Exception An error occurred
     */
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo[] attrs = minfo.getAttributes();
    for (int i = 0; mattrType == null && i < attrs.length; i++) {
        if (attribute.equals(attrs[i].getName()))
            mattrType = attrs[i].getType();
    }
    return mattrType;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 7 with MBeanInfo

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

the class Registry method getMethodInfo.

/**
     * Find the operation info for a method
     *
     * @param oname The bean name
     * @param opName The operation name
     * @return the operation info for the specified operation
     */
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName) {
    MBeanInfo info = null;
    try {
        info = server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info("Can't find metadata " + oname);
        return null;
    }
    MBeanOperationInfo[] attInfo = info.getOperations();
    for (int i = 0; i < attInfo.length; i++) {
        if (opName.equals(attInfo[i].getName())) {
            return attInfo[i];
        }
    }
    return null;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 8 with MBeanInfo

use of javax.management.MBeanInfo in project hive by apache.

the class TestLegacyMetrics method testMetricsMBean.

@Test
public void testMetricsMBean() throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ObjectName oname = new ObjectName("org.apache.hadoop.hive.common.metrics:type=MetricsMBean");
    MBeanInfo mBeanInfo = mbs.getMBeanInfo(oname);
    // check implementation class:
    assertEquals(MetricsMBeanImpl.class.getName(), mBeanInfo.getClassName());
    // check reset operation:
    MBeanOperationInfo[] oops = mBeanInfo.getOperations();
    boolean resetFound = false;
    for (MBeanOperationInfo op : oops) {
        if ("reset".equals(op.getName())) {
            resetFound = true;
            break;
        }
    }
    assertTrue(resetFound);
    // add metric with a non-null value:
    Attribute attr = new Attribute("fooMetric", Long.valueOf(-77));
    mbs.setAttribute(oname, attr);
    mBeanInfo = mbs.getMBeanInfo(oname);
    MBeanAttributeInfo[] attrinuteInfos = mBeanInfo.getAttributes();
    assertEquals(1, attrinuteInfos.length);
    boolean attrFound = false;
    for (MBeanAttributeInfo info : attrinuteInfos) {
        if ("fooMetric".equals(info.getName())) {
            assertEquals("java.lang.Long", info.getType());
            assertTrue(info.isReadable());
            assertTrue(info.isWritable());
            assertFalse(info.isIs());
            attrFound = true;
            break;
        }
    }
    assertTrue(attrFound);
    // check metric value:
    Object v = mbs.getAttribute(oname, "fooMetric");
    assertEquals(Long.valueOf(-77), v);
    // reset the bean:
    Object result = mbs.invoke(oname, "reset", new Object[0], new String[0]);
    assertNull(result);
    // the metric value must be zeroed:
    v = mbs.getAttribute(oname, "fooMetric");
    assertEquals(Long.valueOf(0), v);
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 9 with MBeanInfo

use of javax.management.MBeanInfo in project hive by apache.

the class MetricsMBeanImpl method getMBeanInfo.

@Override
public MBeanInfo getMBeanInfo() {
    if (dirtyAttributeInfoCache) {
        synchronized (metricsMap) {
            attributeInfos = new MBeanAttributeInfo[metricsMap.size()];
            int i = 0;
            for (String key : metricsMap.keySet()) {
                attributeInfos[i] = new MBeanAttributeInfo(key, metricsMap.get(key).getClass().getName(), key, true, true, /*writable*/
                false);
                i++;
            }
            dirtyAttributeInfoCache = false;
        }
    }
    return new MBeanInfo(this.getClass().getName(), "metrics information", attributeInfos, ctors, ops, notifs);
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 10 with MBeanInfo

use of javax.management.MBeanInfo in project jcollectd by collectd.

the class MBeanCollector method collect.

public void collect(MBeanQuery query, ObjectName name) throws Exception {
    MBeanServerConnection conn = _sender.getMBeanServerConnection();
    String plugin = query.getPlugin();
    if (plugin == null) {
        plugin = name.getDomain();
    }
    Map<String, MBeanAttributeInfo> attrInfo = null;
    if (_useDescriptors) {
        MBeanInfo info = conn.getMBeanInfo(name);
        attrInfo = new HashMap<String, MBeanAttributeInfo>();
        for (MBeanAttributeInfo ainfo : info.getAttributes()) {
            attrInfo.put(ainfo.getName(), ainfo);
        }
    }
    for (MBeanAttribute attr : query.getAttributes()) {
        String attrName = attr.getAttributeName();
        Object obj;
        try {
            obj = conn.getAttribute(name, attrName);
        } catch (Exception e) {
            //XXX remove attr for future collection e.g. UnsupportedOperation
            continue;
        }
        if (_useDescriptors) {
            //e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
            try {
                Descriptor descriptor = (Descriptor) _getDescriptor.invoke(attrInfo.get(attrName), (Object[]) null);
                Object type = descriptor.getFieldValue(_metricTypeField);
                if (TypesDB.NAME_COUNTER.equals(type)) {
                    if (attr.getTypeName().equals(TypesDB.NAME_GAUGE)) {
                        attr.setTypeName(TypesDB.NAME_COUNTER);
                    }
                    attr.setDataType(Network.DS_TYPE_COUNTER);
                }
            } catch (Exception e) {
            }
        }
        if (obj instanceof CompositeData) {
            CompositeData data = (CompositeData) obj;
            String key = attr.getCompositeKey();
            if (key == null) {
                //no key specified; collect all
                Set<String> keys = data.getCompositeType().keySet();
                for (String ckey : keys) {
                    obj = data.get(ckey);
                    if (!isNumber(obj)) {
                        continue;
                    }
                    dispatch(query, plugin, attrName + "." + ckey, name, attr, (Number) obj);
                }
                continue;
            } else {
                obj = data.get(key);
            }
        }
        if (!isNumber(obj)) {
            continue;
        }
        dispatch(query, plugin, attr.getName(), name, attr, (Number) obj);
    }
    _sender.flush();
}
Also used : MBeanInfo(javax.management.MBeanInfo) CompositeData(javax.management.openmbean.CompositeData) Descriptor(javax.management.Descriptor) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8