Search in sources :

Example 16 with CompositeData

use of javax.management.openmbean.CompositeData in project tomcat by apache.

the class JMXAccessorTask method createProperty.

/**
     * create result as property with name from property prefix When result is
     * an array and isSeparateArrayResults is true, resultproperty used as
     * prefix (<code>resultproperty.0-array.length</code> and store the
     * result array length at <code>resultproperty.length</code>. Other
     * option is that you delimit your result with a delimiter
     * (java.util.StringTokenizer is used).
     *
     * @param propertyPrefix Prefix for the property
     * @param result The result
     */
protected void createProperty(String propertyPrefix, Object result) {
    if (propertyPrefix == null)
        propertyPrefix = "";
    if (result instanceof CompositeDataSupport) {
        CompositeDataSupport data = (CompositeDataSupport) result;
        CompositeType compositeType = data.getCompositeType();
        Set<String> keys = compositeType.keySet();
        for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
            String key = iter.next();
            Object value = data.get(key);
            OpenType<?> type = compositeType.getType(key);
            if (type instanceof SimpleType<?>) {
                setProperty(propertyPrefix + "." + key, value);
            } else {
                createProperty(propertyPrefix + "." + key, value);
            }
        }
    } else if (result instanceof TabularDataSupport) {
        TabularDataSupport data = (TabularDataSupport) result;
        for (Iterator<Object> iter = data.keySet().iterator(); iter.hasNext(); ) {
            Object key = iter.next();
            for (Iterator<?> iter1 = ((List<?>) key).iterator(); iter1.hasNext(); ) {
                Object key1 = iter1.next();
                CompositeData valuedata = data.get(new Object[] { key1 });
                Object value = valuedata.get("value");
                OpenType<?> type = valuedata.getCompositeType().getType("value");
                if (type instanceof SimpleType<?>) {
                    setProperty(propertyPrefix + "." + key1, value);
                } else {
                    createProperty(propertyPrefix + "." + key1, value);
                }
            }
        }
    } else if (result.getClass().isArray()) {
        if (isSeparatearrayresults()) {
            int size = 0;
            for (int i = 0; i < Array.getLength(result); i++) {
                if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
                    size++;
                }
            }
            if (size > 0) {
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
            }
        }
    } else {
        String delim = getDelimiter();
        if (delim != null) {
            StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
            int size = 0;
            for (; tokenizer.hasMoreTokens(); ) {
                String token = tokenizer.nextToken();
                if (setProperty(propertyPrefix + "." + size, token)) {
                    size++;
                }
            }
            if (size > 0)
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
        } else {
            setProperty(propertyPrefix, result.toString());
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeData(javax.management.openmbean.CompositeData) SimpleType(javax.management.openmbean.SimpleType) StringTokenizer(java.util.StringTokenizer) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Iterator(java.util.Iterator) CompositeType(javax.management.openmbean.CompositeType)

Example 17 with CompositeData

use of javax.management.openmbean.CompositeData 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 18 with CompositeData

use of javax.management.openmbean.CompositeData in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getQueryStats.

@Override
public TabularData getQueryStats() {
    final List<CompositeData> result = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String query : statistics.getQueries()) {
        final QueryStats queryStats = new QueryStats(query, statistics.getQueryStatistics(query));
        result.add(queryStats.toCompositeData());
    }
    final TabularData td = QueryStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 19 with CompositeData

use of javax.management.openmbean.CompositeData in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getCacheRegionStats.

@Override
public TabularData getCacheRegionStats() {
    final List<CompositeData> list = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String region : statistics.getSecondLevelCacheRegionNames()) {
        final CacheRegionStats l2CacheStats = new CacheRegionStats(region, statistics.getSecondLevelCacheStatistics(region));
        list.add(l2CacheStats.toCompositeData());
    }
    final TabularData td = CacheRegionStats.newTabularDataInstance();
    td.putAll(list.toArray(new CompositeData[list.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 20 with CompositeData

use of javax.management.openmbean.CompositeData in project neo4j by neo4j.

the class Dbinfo method compositeDataAsMap.

private Map<?, ?> compositeDataAsMap(CompositeData item) {
    Map<String, Object> result = new HashMap<String, Object>();
    CompositeData compositeData = (CompositeData) item;
    for (String key : compositeData.getCompositeType().keySet()) {
        result.put(key, compositeData.get(key));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) JSONObject(org.neo4j.shell.util.json.JSONObject)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8