use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class NMS7963IT method testHttpCollection.
/**
* Test HTTP Data Collection with XPath
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
File configFile = new File("src/test/resources/http-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("NMS-7963");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "NMS-7963");
DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
collector.setRrdRepository(repository);
collector.setServiceName("HTTP");
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
collectionSet.visit(persister);
RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/xml-retrv-wipo-data.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(1, jrb.getDsCount());
Datasource ds = jrb.getDatasource("xml-wipo-paco");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(903), Double.valueOf(ds.getLastValue()));
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class NodeLevelDataOnMultipleNodesTest method executeCollectorTest.
/**
* Executes collector test.
*
* @param nodeId the node id
* @param ipAddress the IP address
* @param xmlSampleFileName the XML sample file name
* @param parameters the parameters
* @param expectedFiles the expected amount of JRB files
* @throws Exception the exception
*/
public void executeCollectorTest(int nodeId, String ipAddress, String xmlSampleFileName, Map<String, Object> parameters, int expectedFiles) throws Exception {
MockDocumentBuilder.setXmlFileName(xmlSampleFileName);
CollectionAgent collectionAgent = new MockCollectionAgent(nodeId, "mynode", InetAddrUtils.addr(ipAddress));
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_collector, collectionAgent, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
collectionSet.visit(persister);
Assert.assertEquals(expectedFiles, FileUtils.listFiles(new File(getSnmpRoot(), Integer.toString(nodeId)), new String[] { getRrdExtension() }, true).size());
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectableService method doCollection.
/**
* Perform data collection.
*/
private void doCollection() throws CollectionException {
LOG.info("run: starting new collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
CollectionSet result = null;
try {
result = m_spec.collect(m_agent);
if (result != null) {
Collectd.instrumentation().beginPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
try {
CollectionSetVisitor persister = m_persisterFactory.createPersister(m_params, m_repository, result.ignorePersist(), false, false);
if (Boolean.getBoolean(USE_COLLECTION_START_TIME_SYS_PROP)) {
final ConstantTimeKeeper timeKeeper = new ConstantTimeKeeper(new Date(m_lastScheduledCollectionTime));
// Wrap the persister visitor such that calls to CollectionResource.getTimeKeeper() return the given timeKeeper
persister = wrapResourcesWithTimekeeper(persister, timeKeeper);
}
result.visit(persister);
} finally {
Collectd.instrumentation().endPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
}
/*
* Do the thresholding; this could be made more generic (listeners being passed the collectionset), but frankly, why bother?
* The first person who actually needs to configure that sort of thing on the fly can code it up.
*/
if (m_thresholdVisitor != null) {
if (m_thresholdVisitor.isNodeInOutage()) {
LOG.info("run: the threshold processing will be skipped because the node {} is on a scheduled outage.", m_nodeId);
} else if (m_thresholdVisitor.hasThresholds()) {
// Required to reinitialize the counters.
m_thresholdVisitor.setCounterReset(result.ignorePersist());
result.visit(m_thresholdVisitor);
}
}
if (!CollectionStatus.SUCCEEDED.equals(result.getStatus())) {
throw new CollectionFailed(result.getStatus());
}
}
} catch (CollectionException e) {
LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
throw e;
} catch (Throwable t) {
LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
throw new CollectionException("An undeclared throwable was caught during data collection for interface " + m_nodeId + "/" + getHostAddress() + "/" + m_spec.getServiceName(), t);
}
LOG.info("run: finished collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class StressCommand method generateAndPersistCollectionSets.
private Callable<Void> generateAndPersistCollectionSets(ServiceParameters params, RrdRepository repository, int generatorThreadId, int sleepTimeInMillisBetweenNodes) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int nodeId = 0; nodeId < numberOfNodes; nodeId++) {
if (nodeId % numberOfGeneratorThreads != generatorThreadId) {
// A different generator will handle this node
continue;
}
// Build the node resource
CollectionAgent agent = new MockCollectionAgent(nodeId);
NodeLevelResource nodeResource = new NodeLevelResource(nodeId);
// Don't reuse the persister instance across nodes to help simulate collectd's actual behavior
Persister persister = persisterFactory.createPersister(params, repository);
for (int interfaceId = 0; interfaceId < numberOfInterfacesPerNode; interfaceId++) {
// Return immediately if the abort flag is set
if (abort.get()) {
return null;
}
// Build the interface resource
InterfaceLevelResource interfaceResource = new InterfaceLevelResource(nodeResource, "tap" + interfaceId);
// Generate the collection set
CollectionSet collectionSet = generateCollectionSet(agent, nodeId, interfaceId, interfaceResource);
// Persist
collectionSet.visit(persister);
}
Thread.sleep(sleepTimeInMillisBetweenNodes);
}
return null;
}
};
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class JdbcCollectorTest method canCollectEmptyCollection.
@Test
public void canCollectEmptyCollection() throws Exception {
JdbcDataCollection collection = new JdbcDataCollection();
CollectionSet collectionSet = collect(collection);
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
assertEquals(0, CollectionSetUtils.getAttributesByName(collectionSet).size());
}
Aggregations