Search in sources :

Example 6 with JmxDatacollectionConfig

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

the class DetectMBeansJob method execute.

@Override
public JmxDatacollectionConfig execute() throws JobManager.TaskRunException {
    final JmxConnectionConfig connectionConfig = new JmxConnectionConfigBuilder().withUrl(config.getConnection()).withUsername(config.getUser()).withPassword(config.getPassword()).build();
    try (JmxServerConnectionWrapper connector = new DefaultJmxConnector().createConnection(connectionConfig)) {
        final JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class));
        final JmxDatacollectionConfig generatedJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel(connector.getMBeanServerConnection(), "anyservice", !config.isSkipDefaultVM(), config.isSkipNonNumber(), JmxHelper.loadInternalDictionary());
        applyFilters(generatedJmxConfigModel);
        return generatedJmxConfigModel;
    } catch (IOException | MBeanServerQueryException | JMException | JmxServerConnectionException e) {
        if (e instanceof UnknownHostException || e.getCause() instanceof UnknownHostException) {
            throw new JobManager.TaskRunException(String.format("Unknown host: %s", config.getConnection()), e);
        }
        if (e instanceof MalformedURLException || e.getCause() instanceof MalformedURLException) {
            throw new JobManager.TaskRunException(String.format("Cannot create valid JMX Connection URL. Connection: '%s'", config.getConnection()), e);
        }
        throw new JobManager.TaskRunException("Error while retrieving MBeans from server.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) IOException(java.io.IOException) JmxConnectionConfig(org.opennms.netmgt.jmx.connection.JmxConnectionConfig) JmxServerConnectionException(org.opennms.netmgt.jmx.connection.JmxServerConnectionException) JmxDatacollectionConfiggenerator(org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator) DefaultJmxConnector(org.opennms.netmgt.jmx.impl.connection.connectors.DefaultJmxConnector) JMException(javax.management.JMException) JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) JmxConnectionConfigBuilder(org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder)

Example 7 with JmxDatacollectionConfig

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

the class MBeansView method createJmxDataCollectionAccordingToSelection.

/**
 * The whole point was to select/deselect
 * Mbeans/Attribs/CompMembers/CompAttribs. In this method we simply create a
 * JmxDatacollectionConfig considering the choices we made in the gui. To do
 * this, we clone the original <code>JmxDatacollectionConfig</code>
 * loaded at the beginning. After that we remove all
 * MBeans/Attribs/CompMembers/CompAttribs and add all selected
 * MBeans/Attribs/CompMembers/CompAttribs afterwards.
 *
 * @return
 */
private static JmxDatacollectionConfig createJmxDataCollectionAccordingToSelection(final UiModel uiModel, final SelectionManager selectionManager) {
    /*
		 * At First we clone the original collection. This is done, because if
		 * we make any modifications (e.g. deleting not selected elements) the
		 * data isn't available in the GUI, too. To avoid reloading the data
		 * from server, we just clone it.
		 */
    JmxDatacollectionConfig clone = JmxCollectionCloner.clone(uiModel.getRawModel());
    /*
		 * At second we remove all MBeans from original data and get only
		 * selected once.
		 */
    List<Mbean> exportBeans = clone.getJmxCollectionList().get(0).getMbeans();
    exportBeans.clear();
    Iterable<Mbean> selectedMbeans = selectionManager.getSelectedMbeans();
    for (Mbean mbean : selectedMbeans) {
        /*
			 * We remove all Attributes from Mbean, because we only want
			 * selected ones.
			 */
        Mbean exportBean = JmxCollectionCloner.clone(mbean);
        // we only want selected ones :)
        exportBean.clearAttribs();
        for (Attrib att : selectionManager.getSelectedAttributes(mbean)) {
            exportBean.addAttrib(JmxCollectionCloner.clone(att));
        }
        // we do not add the parent
        if (!exportBean.getAttribList().isEmpty()) {
            exportBeans.add(exportBean);
        }
        /*
			 * We remove all CompAttribs and CompMembers from MBean,
			 * because we only want selected ones.
			 */
        exportBean.clearCompAttribs();
        for (CompAttrib compAtt : selectionManager.getSelectedCompositeAttributes(mbean)) {
            CompAttrib cloneCompAtt = JmxCollectionCloner.clone(compAtt);
            cloneCompAtt.clearCompMembers();
            for (CompMember compMember : selectionManager.getSelectedCompositeMembers(compAtt)) {
                cloneCompAtt.addCompMember(JmxCollectionCloner.clone(compMember));
            }
            // we do not add the child
            if (!cloneCompAtt.getCompMemberList().isEmpty()) {
                exportBean.addCompAttrib(cloneCompAtt);
            }
        }
    }
    // we sort the order, so the result is deterministic
    sort(exportBeans);
    // Last but not least, we need to update the service name
    clone.getJmxCollectionList().get(0).setName(uiModel.getServiceName());
    return clone;
}
Also used : Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) Attrib(org.opennms.netmgt.config.collectd.jmx.Attrib) CompMember(org.opennms.netmgt.config.collectd.jmx.CompMember)

Example 8 with JmxDatacollectionConfig

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

the class JmxDataCollectionConfigResourceIT method testJmxConfig.

@Test
public void testJmxConfig() throws Exception {
    sendRequest(GET, "/config/jmx/notfound", 404);
    String xml = sendRequest(GET, "/config/jmx", 200);
    JmxDatacollectionConfig config = JaxbUtils.unmarshal(JmxDatacollectionConfig.class, xml);
    assertNotNull(config);
    assertEquals(6, config.getJmxCollectionCount());
    assertEquals("jmx-jboss", config.getJmxCollection("jmx-jboss").getName());
    assertEquals(300, config.getJmxCollection("jmx-jboss").getRrd().getStep());
    assertEquals(4, config.getJmxCollection("jmx-jboss").getMbeanCount());
    assertEquals("jsr160", config.getJmxCollection("jsr160").getName());
    assertEquals(300, config.getJmxCollection("jsr160").getRrd().getStep());
    assertEquals(39, config.getJmxCollection("jsr160").getMbeanCount());
    assertEquals("jmx-minion", config.getJmxCollection("jmx-minion").getName());
    assertEquals(300, config.getJmxCollection("jmx-minion").getRrd().getStep());
    assertEquals(11, config.getJmxCollection("jmx-minion").getMbeanCount());
    assertEquals("jmx-cassandra30x", config.getJmxCollection("jmx-cassandra30x").getName());
    assertEquals(300, config.getJmxCollection("jmx-cassandra30x").getRrd().getStep());
    assertEquals(53, config.getJmxCollection("jmx-cassandra30x").getMbeanCount());
    assertEquals("jmx-cassandra30x-newts", config.getJmxCollection("jmx-cassandra30x-newts").getName());
    assertEquals(300, config.getJmxCollection("jmx-cassandra30x-newts").getRrd().getStep());
    assertEquals(22, config.getJmxCollection("jmx-cassandra30x-newts").getMbeanCount());
}
Also used : JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) Test(org.junit.Test)

Example 9 with JmxDatacollectionConfig

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

the class JmxDataCollectionConfigResource method getJmxDataCollectionConfig.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response getJmxDataCollectionConfig() throws ConfigurationResourceException {
    LOG.debug("getJmxDataCollectionConfigurationForLocation()");
    final JmxDatacollectionConfig jmxDataCollectionConfig = m_jmxDataCollectionConfigDao.getConfig();
    if (jmxDataCollectionConfig == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.ok(jmxDataCollectionConfig).build();
}
Also used : JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with JmxDatacollectionConfig

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

the class JmxDatacollectionConfiggeneratorTest method testGenerateJmxConfigModelRunJvmMBeans.

@Test
public void testGenerateJmxConfigModelRunJvmMBeans() throws MBeanServerQueryException, IOException, JMException {
    JmxDatacollectionConfig jmxConfigModel = jmxConfiggenerator.generateJmxConfigModel(platformMBeanServer, "testService", true, true, dictionary);
    Assert.assertEquals(1, jmxConfigModel.getJmxCollectionList().size());
    Assert.assertTrue(10 < jmxConfigModel.getJmxCollectionList().get(0).getMbeans().size());
    Mbean mbean = findMbean(jmxConfigModel, "org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxTest");
    Assert.assertNotNull(mbean);
    Assert.assertEquals(4, mbean.getAttribList().size());
    LOG.info(prettyPrint(jmxConfigModel));
}
Also used : Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) 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