use of org.jrobin.core.Datasource in project opennms by OpenNMS.
the class AbstractVTDXmlCollectorTest method validateJrb.
/**
* Validates a JRB.
* <p>It assumes storeByGroup=true</p>
*
* @param file the JRB file instance
* @param dsnames the array of data source names
* @param dsvalues the array of data source values
* @throws Exception the exception
*/
public void validateJrb(File file, String[] dsnames, Double[] dsvalues) throws Exception {
Assert.assertTrue(file.exists());
RrdDb jrb = new RrdDb(file);
Assert.assertEquals(dsnames.length, jrb.getDsCount());
for (int i = 0; i < dsnames.length; i++) {
Datasource ds = jrb.getDatasource(dsnames[i]);
Assert.assertNotNull(ds);
Assert.assertEquals(dsvalues[i], Double.valueOf(ds.getLastValue()));
}
}
use of org.jrobin.core.Datasource 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.jrobin.core.Datasource in project opennms by OpenNMS.
the class RrdDatabaseWriter method write.
public void write(final RrdEntry entry) throws IOException, RrdException {
final Sample s = m_rrd.createSample(entry.getTimestamp());
final double[] values = new double[entry.getDsNames().size()];
int i = 0;
for (final String dsName : entry.getDsNames()) {
if (dsName != null) {
Double value = entry.getValue(dsName);
final Datasource dataSource = m_rrd.getDatasource(dsName);
if (value != null) {
if (dataSource.getDsType().equals("COUNTER")) {
final double counterValue = getLastValue(dsName) + (value * m_step);
if (Double.isInfinite(counterValue)) {
// if we've overrun the counter, calculate our own counter loop
final BigDecimal bigValue = BigDecimal.valueOf(value);
final BigDecimal bigLastValue = BigDecimal.valueOf(getLastValue(dsName));
final BigDecimal bigStep = BigDecimal.valueOf(m_step);
final BigDecimal newValue = bigLastValue.multiply(bigStep).add(bigValue).subtract(m_doubleMax);
value = newValue.doubleValue();
} else {
value = counterValue;
}
}
values[i] = value;
setLastValue(dsName, value);
}
}
i++;
}
s.setValues(values);
// LogUtils.debugf(this, "writing sample to %s: %s", outputRrd, s);
s.update();
}
use of org.jrobin.core.Datasource in project opennms by OpenNMS.
the class HttpDataCollectionIT method testJsonHttpCollection.
/**
* Test HTTP Data Collection with JSON
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testJsonHttpCollection() throws Exception {
File configFile = new File("src/test/resources/solaris-zones-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("Solaris");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Solaris");
DefaultJsonCollectionHandler collector = new DefaultJsonCollectionHandler();
collector.setRrdRepository(repository);
collector.setServiceName("HTTP");
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
System.err.println(CollectionSetUtils.flatten(collectionSet));
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/solarisZoneStats/global/solaris-zone-stats.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(6, jrb.getDsCount());
Datasource ds = jrb.getDatasource("nproc");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(245.0), Double.valueOf(ds.getLastValue()));
}
use of org.jrobin.core.Datasource 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()));
}
Aggregations