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());
}
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);
}
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;
}
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;
}
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));
}
Aggregations