Search in sources :

Example 6 with MBeanAttributeInfo

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

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

the class JMXAccessorQueryTask method bindAttributes.

protected void bindAttributes(MBeanServerConnection jmxServerConnection, String pname, ObjectName oname) {
    try {
        MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
        MBeanAttributeInfo[] attrs = minfo.getAttributes();
        Object value = null;
        for (int i = 0; i < attrs.length; i++) {
            if (!attrs[i].isReadable())
                continue;
            String attName = attrs[i].getName();
            if (attName.indexOf('=') >= 0 || attName.indexOf(':') >= 0 || attName.indexOf(' ') >= 0) {
                continue;
            }
            try {
                value = jmxServerConnection.getAttribute(oname, attName);
            } catch (Exception e) {
                if (isEcho())
                    handleErrorOutput("Error getting attribute " + oname + " " + pname + attName + " " + e.toString());
                continue;
            }
            if (value == null)
                continue;
            if ("modelerType".equals(attName))
                continue;
            createProperty(pname + attName, value);
        }
    } catch (Exception e) {
    // Ignore
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) BuildException(org.apache.tools.ant.BuildException)

Example 8 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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 9 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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)

Example 10 with MBeanAttributeInfo

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

the class MBeanCollector method queryAll.

private MBeanQuery queryAll(ObjectName name) throws Exception {
    MBeanQuery query = new MBeanQuery(name);
    MBeanInfo info = _sender.getMBeanServerConnection().getMBeanInfo(name);
    MBeanAttributeInfo[] attrs = info.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        query.addAttribute(new MBeanAttribute(attrs[i].getName()));
    }
    return query;
}
Also used : MBeanInfo(javax.management.MBeanInfo) 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