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