Search in sources :

Example 1 with JmxCollection

use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.

the class JMXDataCollectionConfigDao method getStep.

public int getStep(String cName) {
    // Try retrieving the object, which will trigger a reload of the cache if it changed
    getObject();
    m_lock.readLock().lock();
    try {
        JmxCollection collection = m_collectionMap.get(cName);
        if (collection != null)
            return collection.getRrd().getStep();
        else
            return -1;
    } finally {
        m_lock.readLock().unlock();
    }
}
Also used : JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection)

Example 2 with JmxCollection

use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.

the class JMXDataCollectionConfigDao method getMBeanInfo.

public Map<String, BeanInfo> getMBeanInfo(String cName) {
    // Try retrieving the object, which will trigger a reload of the cache if it changed
    getObject();
    m_lock.readLock().lock();
    try {
        Map<String, BeanInfo> map = new HashMap<String, BeanInfo>();
        // Retrieve the appropriate Collection object
        // 
        JmxCollection collection = m_collectionMap.get(cName);
        if (collection == null) {
            LOG.warn("no collection named '{}' was found", cName);
        } else {
            return getMBeanInfo(collection);
        }
        return Collections.unmodifiableMap(map);
    } finally {
        m_lock.readLock().unlock();
    }
}
Also used : HashMap(java.util.HashMap) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection)

Example 3 with JmxCollection

use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.

the class JMXCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    // Retrieve the name of the JMX data collector
    final String collectionName = ParameterMap.getKeyedString(parameters, ParameterName.COLLECTION.toString(), serviceName);
    final JmxCollection jmxCollection = m_jmxDataCollectionConfigDao.getJmxCollection(collectionName);
    if (jmxCollection == null) {
        throw new IllegalArgumentException(String.format("JMXCollector: No collection found with name '%s'.", collectionName));
    }
    runtimeAttributes.put(JMX_COLLECTION_KEY, jmxCollection);
    // Retrieve the agent config.
    final Map<String, String> parameterStringMap = new HashMap<String, String>();
    for (Map.Entry<String, Object> eachEntry : parameters.entrySet()) {
        if (eachEntry.getValue() instanceof String) {
            parameterStringMap.put(eachEntry.getKey(), (String) eachEntry.getValue());
        }
    }
    final MBeanServer mBeanServer = JmxUtils.getMBeanServer(m_jmxConfigDao, agent.getHostAddress(), parameterStringMap);
    if (mBeanServer != null) {
        runtimeAttributes.put(JMX_MBEAN_SERVER_KEY, mBeanServer);
    }
    return runtimeAttributes;
}
Also used : HashMap(java.util.HashMap) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) HashMap(java.util.HashMap) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap) MBeanServer(org.opennms.netmgt.config.jmx.MBeanServer)

Example 4 with JmxCollection

use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.

the class JmxDatacollectionConfiggenerator method createJmxDataCollectionConfig.

private JmxDatacollectionConfig createJmxDataCollectionConfig(String serviceName, Rrd rrd) {
    final JmxDatacollectionConfig xmlJmxDatacollectionConfig = new JmxDatacollectionConfig();
    final JmxCollection xmlJmxCollection = new JmxCollection();
    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);
    xmlJmxDatacollectionConfig.addJmxCollection(xmlJmxCollection);
    return xmlJmxDatacollectionConfig;
}
Also used : JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection)

Example 5 with JmxCollection

use of org.opennms.netmgt.config.collectd.jmx.JmxCollection 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

JmxCollection (org.opennms.netmgt.config.collectd.jmx.JmxCollection)14 HashMap (java.util.HashMap)4 Mbean (org.opennms.netmgt.config.collectd.jmx.Mbean)4 JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)3 MBeanServer (org.opennms.netmgt.config.jmx.MBeanServer)3 Map (java.util.Map)2 ObjectName (javax.management.ObjectName)2 ParameterMap (org.opennms.core.utils.ParameterMap)2 JMXDataCollectionConfigDao (org.opennms.netmgt.config.JMXDataCollectionConfigDao)2 Attrib (org.opennms.netmgt.config.collectd.jmx.Attrib)2 JmxConfigDao (org.opennms.netmgt.dao.jmx.JmxConfigDao)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 InetAddress (java.net.InetAddress)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Objects (java.util.Objects)1