Search in sources :

Example 1 with Datasource

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()));
    }
}
Also used : Datasource(org.jrobin.core.Datasource) RrdDb(org.jrobin.core.RrdDb)

Example 2 with Datasource

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()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 3 with Datasource

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();
}
Also used : Datasource(org.jrobin.core.Datasource) Sample(org.jrobin.core.Sample) BigDecimal(java.math.BigDecimal)

Example 4 with Datasource

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()));
}
Also used : Datasource(org.jrobin.core.Datasource) DefaultJsonCollectionHandler(org.opennms.protocols.json.collector.DefaultJsonCollectionHandler) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 5 with Datasource

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()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

Datasource (org.jrobin.core.Datasource)9 RrdDb (org.jrobin.core.RrdDb)8 File (java.io.File)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)5 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)5 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)5 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)5 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)5 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)5 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)5 BigDecimal (java.math.BigDecimal)1 Sample (org.jrobin.core.Sample)1 HttpCollectionHandler (org.opennms.protocols.http.collector.HttpCollectionHandler)1 DefaultJsonCollectionHandler (org.opennms.protocols.json.collector.DefaultJsonCollectionHandler)1