Search in sources :

Example 6 with RRA

use of org.opennms.netmgt.rrd.model.v1.RRA in project opennms by OpenNMS.

the class RRDv1IT method parseRrdSimple.

/**
     * Parses a simple RRD.
     *
     * @throws Exception the exception
     */
@Test
public void parseRrdSimple() throws Exception {
    RRDv1 rrd = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/jrb-dump.xml"));
    Assert.assertNotNull(rrd);
    Assert.assertEquals(new Long(300), rrd.getStep());
    Assert.assertEquals(new Long(1233926670), rrd.getLastUpdate());
    // Test Data Source
    Assert.assertEquals("ifInDiscards", rrd.getDataSources().get(0).getName());
    Assert.assertEquals(DSType.COUNTER, rrd.getDataSources().get(0).getType());
    Assert.assertEquals(new Long(0), rrd.getDataSources().get(0).getUnknownSec());
    // Test RRA
    Assert.assertEquals(CFType.AVERAGE, rrd.getRras().get(0).getConsolidationFunction());
    Assert.assertEquals(new Long(1), rrd.getRras().get(0).getPdpPerRow());
    Assert.assertEquals(new Long(12), rrd.getRras().get(1).getPdpPerRow());
    Assert.assertEquals(new Long(288), rrd.getRras().get(4).getPdpPerRow());
    // Test time related functions : getEndTimestamp
    Assert.assertEquals(new Long(1233926400), rrd.getEndTimestamp(rrd.getRras().get(0)));
    Assert.assertEquals(new Long(1233925200), rrd.getEndTimestamp(rrd.getRras().get(1)));
    Assert.assertEquals(new Long(1233878400), rrd.getEndTimestamp(rrd.getRras().get(4)));
    // Test time related functions : getStartTimestamp
    Assert.assertEquals(new Long(1233321900), rrd.getStartTimestamp(rrd.getRras().get(0)));
    Assert.assertEquals(new Long(1228572000), rrd.getStartTimestamp(rrd.getRras().get(1)));
    Assert.assertEquals(new Long(1202342400), rrd.getStartTimestamp(rrd.getRras().get(4)));
    // Test time related functions : findRowByTimestamp
    AbstractRRA rra = rrd.getRras().get(0);
    Assert.assertEquals(rra.getRows().get(0), rrd.findRowByTimestamp(rra, new Long(1233321900)));
    Assert.assertEquals(rra.getRows().get(5), rrd.findRowByTimestamp(rra, new Long(1233323400)));
    // Test time related functions : findTimestampByRow
    Assert.assertEquals(new Long(1233321900), rrd.findTimestampByRow(rra, rra.getRows().get(0)));
    Assert.assertEquals(new Long(1233323400), rrd.findTimestampByRow(rra, rra.getRows().get(5)));
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) File(java.io.File) Test(org.junit.Test)

Example 7 with RRA

use of org.opennms.netmgt.rrd.model.v1.RRA in project opennms by OpenNMS.

the class RRDv3IT method testSplit.

/**
     * Test split and merge
     *
     * @throws Exception the exception
     */
@Test
public void testSplit() throws Exception {
    RRDv3 masterRrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-dump.xml"));
    Assert.assertNotNull(masterRrd);
    List<AbstractRRD> rrds = masterRrd.split();
    Assert.assertEquals(masterRrd.getDataSources().size(), rrds.size());
    RRA masterRRA = masterRrd.getRras().get(0);
    for (int i = 0; i < rrds.size(); i++) {
        RRDv3 singleRRD = (RRDv3) rrds.get(i);
        Assert.assertEquals(1, singleRRD.getDataSources().size());
        Assert.assertEquals(masterRrd.getDataSource(i).getName(), singleRRD.getDataSource(0).getName());
        RRA singleRRA = singleRRD.getRras().get(0);
        Assert.assertEquals(1, singleRRA.getDataSources().size());
        Assert.assertEquals(masterRRA.getPdpPerRow(), singleRRA.getPdpPerRow());
        Assert.assertEquals(masterRRA.getRows().size(), singleRRA.getRows().size());
        Assert.assertEquals(masterRRA.getConsolidationFunction().name(), singleRRA.getConsolidationFunction().name());
        for (int j = 0; j < masterRRA.getRows().size(); j++) {
            Row masterRow = masterRRA.getRows().get(j);
            Row row = singleRRA.getRows().get(j);
            Assert.assertEquals(1, row.getValues().size());
            Assert.assertEquals(masterRow.getValues().get(i), row.getValues().get(0));
            masterRow.getValues().set(i, Double.NaN);
        }
    }
    int dsIndex = 3;
    masterRrd.merge(rrds);
    for (int j = 0; j < masterRRA.getRows().size(); j++) {
        Row masterRow = masterRRA.getRows().get(j);
        Row row = rrds.get(dsIndex).getRras().get(0).getRows().get(j);
        Assert.assertEquals(1, row.getValues().size());
        Assert.assertEquals(masterRow.getValues().get(dsIndex), row.getValues().get(0));
    }
}
Also used : RRA(org.opennms.netmgt.rrd.model.v3.RRA) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) AbstractRRD(org.opennms.netmgt.rrd.model.AbstractRRD) Row(org.opennms.netmgt.rrd.model.Row) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)5 Test (org.junit.Test)5 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)5 RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)4 ArrayList (java.util.ArrayList)2 Row (org.opennms.netmgt.rrd.model.Row)2 RRA (org.opennms.netmgt.rrd.model.v1.RRA)2 RRA (org.opennms.netmgt.rrd.model.v3.RRA)2 FileWriter (java.io.FileWriter)1 List (java.util.List)1 FileUtils (org.apache.commons.io.FileUtils)1 Assert (org.junit.Assert)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1 AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)1 CFType (org.opennms.netmgt.rrd.model.v1.CFType)1 DSType (org.opennms.netmgt.rrd.model.v1.DSType)1