Search in sources :

Example 1 with JmxDatacollectionConfig

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

the class JMXDataCollectionConfigDaoTest method loadsConfigFiles.

@Test
public void loadsConfigFiles() throws IOException {
    JMXDataCollectionConfigDao dao = new JMXDataCollectionConfigDao();
    dao.setOpennmsHome(Paths.get(new File(".").getCanonicalPath(), "src/test/resources"));
    dao.getConfig();
    JmxDatacollectionConfig config = dao.getConfig();
    Assert.assertNotNull("JMX data collection should not be null", config);
    // These are declared in the top-level jmx-datacollection-config.xml file
    Assert.assertEquals(4, config.getJmxCollection("jboss").getMbeanCount());
    Assert.assertEquals(15, config.getJmxCollection("jsr160").getMbeanCount());
    // These are automatically included from the jmx-datacollection-config.d/ folder
    Assert.assertEquals(8, config.getJmxCollection("jboss-included").getMbeanCount());
    Assert.assertEquals(4, config.getJmxCollection("jsr160-included").getMbeanCount());
    // These beans should be imported for other files
    Assert.assertEquals(16, config.getJmxCollection("ActiveMQ").getMbeanCount());
}
Also used : JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) File(java.io.File) Test(org.junit.Test)

Example 2 with JmxDatacollectionConfig

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

the class JmxConfigCreateCommand method execute.

@Override
protected void execute(MBeanServerConnection mbeanServerConnection) throws IOException, MBeanServerQueryException, JMException {
    JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(LOG);
    Map<String, String> dictionary = loadDictionary();
    JmxDatacollectionConfig generateJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel(ids, mbeanServerConnection, serviceName, !skipDefaultVM, skipNonNumber, dictionary);
    jmxConfigGenerator.writeJmxConfigFile(generateJmxConfigModel, outFile);
}
Also used : JmxDatacollectionConfiggenerator(org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)

Example 3 with JmxDatacollectionConfig

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

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

Example 5 with JmxDatacollectionConfig

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

the class JmxDatacollectionConfiggeneratorTest method testGenerateJmxConfigModelSkipJvmMBeans.

@Test
public void testGenerateJmxConfigModelSkipJvmMBeans() throws MBeanServerQueryException, IOException, JMException {
    JmxDatacollectionConfig jmxConfigModel = jmxConfiggenerator.generateJmxConfigModel(platformMBeanServer, "testService", false, true, dictionary);
    Assert.assertEquals(1, jmxConfigModel.getJmxCollectionList().size());
    Assert.assertEquals(1, jmxConfigModel.getJmxCollectionList().get(0).getMbeans().size());
    Assert.assertEquals("org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxTest", jmxConfigModel.getJmxCollectionList().get(0).getMbeans().get(0).getName());
    Assert.assertEquals(4, jmxConfigModel.getJmxCollectionList().get(0).getMbeans().get(0).getAttribList().size());
    LOG.info(prettyPrint(jmxConfigModel));
}
Also used : JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) Test(org.junit.Test)

Aggregations

JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)14 Test (org.junit.Test)7 Mbean (org.opennms.netmgt.config.collectd.jmx.Mbean)6 JmxCollection (org.opennms.netmgt.config.collectd.jmx.JmxCollection)3 ArrayList (java.util.ArrayList)2 JmxDatacollectionConfiggenerator (org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator)2 Attrib (org.opennms.netmgt.config.collectd.jmx.Attrib)2 CompAttrib (org.opennms.netmgt.config.collectd.jmx.CompAttrib)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 JMException (javax.management.JMException)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 ObjectName (javax.management.ObjectName)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 MBeanServerQueryException (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException)1 QueryResult (org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)1 Slf4jLogAdapter (org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter)1