use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.
the class HttpDataCollectionIT 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("Http-Count");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Http-Count");
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/count-stats.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(1, jrb.getDsCount());
Datasource ds = jrb.getDatasource("count");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(5), Double.valueOf(ds.getLastValue()));
}
use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.
the class HttpDataCollectionIT method testCssSelectorHttpCollection.
/**
* Test HTTP Data Collection with CSS Selector
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testCssSelectorHttpCollection() throws Exception {
File configFile = new File("src/test/resources/http-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("Http-Market");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Http-Market");
HttpCollectionHandler collector = new HttpCollectionHandler();
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/market.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(2, jrb.getDsCount());
Datasource ds = jrb.getDatasource("nasdaq");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(3578.30), Double.valueOf(ds.getLastValue()));
}
use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.
the class HttpDataCollectionIT method testPostRequestHttpCollection.
/**
* Test HTTP Data Collection with a POST Request
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testPostRequestHttpCollection() throws Exception {
File configFile = new File("src/test/resources/http-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("Http-Person-Stats");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Http-Person-Stats");
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/person-stats.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(3, jrb.getDsCount());
Datasource ds = jrb.getDatasource("contributions");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(500), Double.valueOf(ds.getLastValue()));
}
use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.
the class NodeLevelDataOnMultipleNodesTest method createRrdRepository.
/**
* Creates the RRD repository.
*
* @return the RRD repository
* @throws IOException Signals that an I/O exception has occurred.
*/
private RrdRepository createRrdRepository(String collection) throws IOException {
XmlRrd rrd = m_xmlCollectionDao.getDataCollectionByName(collection).getXmlRrd();
RrdRepository repository = new RrdRepository();
repository.setRrdBaseDir(getSnmpRoot());
repository.setHeartBeat(rrd.getStep() * 2);
repository.setStep(rrd.getStep());
repository.setRraList(rrd.getXmlRras());
return repository;
}
use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.
the class NSClientDataCollectionConfigFactory method getRrdRepository.
/**
* <p>getRrdRepository</p>
*
* @param collectionName a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.rrd.RrdRepository} object.
*/
public RrdRepository getRrdRepository(final String collectionName) {
try {
getReadLock().lock();
final RrdRepository repo = new RrdRepository();
repo.setRrdBaseDir(new File(getRrdPath()));
repo.setRraList(getRRAList(collectionName));
repo.setStep(getStep(collectionName));
repo.setHeartBeat((2 * getStep(collectionName)));
return repo;
} finally {
getReadLock().unlock();
}
}
Aggregations