Search in sources :

Example 1 with QueryResult

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.

the class QueryCommand method execute.

@Override
protected void execute(MBeanServerConnection mbeanServerConnection) throws MBeanServerQueryException, IOException {
    if (domainOnlyFlag && (filter == null || filter.isEmpty())) {
        for (String eachDomain : mbeanServerConnection.getDomains()) {
            LOG.info(eachDomain);
        }
        return;
    }
    MBeanServerQuery queryBuilder = new MBeanServerQuery().withFilters(filter).withIgnoresFilter(ignoreFilter).fetchValues(includeValues).showMBeansWithoutAttributes(all).sort(true);
    QueryResult result = queryBuilder.execute(mbeanServerConnection);
    if (idOnlyFlag) {
        for (QueryResult.MBeanResult eachResult : result.getMBeanResults()) {
            for (MBeanAttributeInfo eachAttributeInfo : eachResult.attributeResult.attributes) {
                LOG.info(toAttributeId(eachResult.objectName, eachAttributeInfo));
            }
        }
    } else {
        prettyPrint(result);
    }
}
Also used : MBeanServerQuery(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery) QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 2 with QueryResult

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.

the class QueryCommand method prettyPrint.

private void prettyPrint(QueryResult result) {
    for (QueryResult.MBeanResult eachMBeanResult : result.getMBeanResults()) {
        MBeanInfo mbeanInfo = eachMBeanResult.mbeanInfo;
        ObjectName objectName = eachMBeanResult.objectName;
        QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
        LOG.info(String.format("%s", objectName));
        LOG.info(String.format("\tdescription: %s", toString(mbeanInfo.getDescription())));
        LOG.info(String.format("\tclass name: %s", mbeanInfo.getClassName()));
        LOG.info(String.format("\tattributes: (%d/%d)", attributeResult.attributes.size(), attributeResult.totalCount));
        for (MBeanAttributeInfo eachAttribute : attributeResult.attributes) {
            LOG.info(String.format("\t\t%s", eachAttribute.getName()));
            LOG.info(String.format("\t\t\tid: %s", toAttributeId(objectName, eachAttribute)));
            LOG.info(String.format("\t\t\tdescription: %s", toString(eachAttribute.getDescription())));
            LOG.info(String.format("\t\t\ttype: %s", eachAttribute.getType()));
            LOG.info(String.format("\t\t\tisReadable: %s", eachAttribute.isReadable()));
            LOG.info(String.format("\t\t\tisWritable: %s", eachAttribute.isWritable()));
            LOG.info(String.format("\t\t\tisIs: %s", eachAttribute.isIs()));
            if (includeValues) {
                LOG.info(String.format("\t\t\tvalue: %s", toString(attributeResult.getValue(eachAttribute))));
            }
        }
    }
    if (filter != null && !filter.isEmpty()) {
        LOG.info(String.format("Your query '%s' shows %d/%d MBeans.", filter, result.getMBeanResults().size(), result.getTotalMBeanCount()));
    } else {
        LOG.info(String.format("There are %d registered MBeans", result.getTotalMBeanCount()));
    }
    if (ignoreFilter != null && !ignoreFilter.isEmpty()) {
        LOG.info(String.format("While querying, the following query was used to exclude MBeans/Attributes: '%s'", ignoreFilter));
    }
}
Also used : QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 3 with QueryResult

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.

the class JmxDatacollectionConfiggenerator method queryMbeanServer.

private QueryResult queryMbeanServer(List<String> ids, MBeanServerConnection mBeanServerConnection, boolean runStandardVmBeans) throws MBeanServerQueryException {
    final MBeanServerQuery query = new MBeanServerQuery().withFilters(ids).fetchValues(// we do not fetch values to improve collection speed
    false).showMBeansWithoutAttributes(// we don't need them
    false).sort(// sorting makes finding attributes easier
    true);
    if (!runStandardVmBeans) {
        query.withIgnoresFilter(Collections2.transform(standardVmBeans, input -> input + ":*"));
    }
    final QueryResult result = query.execute(mBeanServerConnection);
    return result;
}
Also used : MBeanServerQuery(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery) LogAdapter(org.opennms.features.jmxconfiggenerator.log.LogAdapter) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) HashMap(java.util.HashMap) Collections2(com.google.common.collect.Collections2) ArrayList(java.util.ArrayList) QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) Map(java.util.Map) FilterCriteria(org.opennms.features.jmxconfiggenerator.jmxconfig.query.FilterCriteria) AttributeType(org.opennms.netmgt.collection.api.AttributeType) JaxbUtils(org.opennms.core.xml.JaxbUtils) MBeanServerConnection(javax.management.MBeanServerConnection) Collection(java.util.Collection) Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) File(java.io.File) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) Rrd(org.opennms.netmgt.config.collectd.jmx.Rrd) List(java.util.List) Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) CompMember(org.opennms.netmgt.config.collectd.jmx.CompMember) JMException(javax.management.JMException) Attrib(org.opennms.netmgt.config.collectd.jmx.Attrib) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) NameCutter(org.opennms.features.namecutter.NameCutter) MBeanServerQuery(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery) QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)

Example 4 with QueryResult

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.

the class JmxDatacollectionConfiggenerator method generateJmxConfigModel.

public JmxDatacollectionConfig generateJmxConfigModel(List<String> ids, MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean skipNonNumber, Map<String, String> dictionary) throws MBeanServerQueryException, IOException, JMException {
    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n dictionary" + dictionary);
    aliasList.clear();
    aliasMap.clear();
    nameCutter.setDictionary(dictionary);
    final QueryResult queryResult = queryMbeanServer(ids, mBeanServerConnection, runStandardVmBeans);
    final JmxDatacollectionConfig xmlJmxDatacollectionConfig = createJmxDataCollectionConfig(serviceName, rrd);
    final JmxCollection xmlJmxCollection = xmlJmxDatacollectionConfig.getJmxCollectionList().get(0);
    for (QueryResult.MBeanResult eachMBeanResult : queryResult.getMBeanResults()) {
        final ObjectName objectName = eachMBeanResult.objectName;
        final Mbean xmlMbean = createMbean(objectName);
        final QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
        for (MBeanAttributeInfo jmxBeanAttributeInfo : attributeResult.attributes) {
            // check for CompositeData
            if ("javax.management.openmbean.CompositeData".equals(jmxBeanAttributeInfo.getType())) {
                CompAttrib compAttrib = createCompAttrib(mBeanServerConnection, objectName, jmxBeanAttributeInfo, skipNonNumber);
                if (compAttrib != null) {
                    xmlMbean.addCompAttrib(compAttrib);
                }
            }
            if (skipNonNumber && !numbers.contains(jmxBeanAttributeInfo.getType())) {
                logger.warn("The type of attribute '{}' is '{}' and '--skipNonNumber' is set. Ignoring.", jmxBeanAttributeInfo.getName(), jmxBeanAttributeInfo.getType());
            } else {
                Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                xmlMbean.addAttrib(xmlJmxAttribute);
            }
        }
        if (!xmlMbean.getAttribList().isEmpty() || !xmlMbean.getCompAttribList().isEmpty()) {
            xmlJmxCollection.addMbean(xmlMbean);
        }
    }
    if (xmlJmxCollection.getMbeans().size() != queryResult.getMBeanResults().size()) {
        logger.warn("Queried {} MBeans, but only got {} in the result set.", queryResult.getMBeanResults().size(), xmlJmxCollection.getMbeans().size());
    }
    return xmlJmxDatacollectionConfig;
}
Also used : QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) Attrib(org.opennms.netmgt.config.collectd.jmx.Attrib) ObjectName(javax.management.ObjectName)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)4 QueryResult (org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)4 ObjectName (javax.management.ObjectName)3 MBeanServerQuery (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery)2 Attrib (org.opennms.netmgt.config.collectd.jmx.Attrib)2 CompAttrib (org.opennms.netmgt.config.collectd.jmx.CompAttrib)2 JmxCollection (org.opennms.netmgt.config.collectd.jmx.JmxCollection)2 JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)2 Mbean (org.opennms.netmgt.config.collectd.jmx.Mbean)2 Collections2 (com.google.common.collect.Collections2)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 JMException (javax.management.JMException)1 MBeanInfo (javax.management.MBeanInfo)1