use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.
the class NodeLevelDataWithRrdtoolTest method validateRrd.
/**
* Validates a RRD.
* <p>It assumes storeByGroup=true</p>
*
* @param file the RRD file instance
* @param dsnames the array of data source names
* @param dsvalues the array of data source values
* @throws Exception the exception
*/
protected void validateRrd(File file, String[] dsnames, Double[] dsvalues) throws Exception {
Assert.assertTrue(file.exists());
RRDv3 rrd = RrdConvertUtils.dumpRrd(file);
Assert.assertEquals(dsnames.length, rrd.getDataSources().size());
for (int i = 0; i < dsnames.length; i++) {
Assert.assertEquals(dsvalues[i], Double.valueOf(rrd.getDataSource(i).getLastDs()));
List<Row> rows = rrd.getRras().get(0).getRows();
// All the last values stored on the RRA must be valid numbers
Assert.assertFalse(rows.get(rows.size() - 1).isNan());
}
}
use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.
the class RRDv1IT method testSplit.
/**
* Test split and merge
*
* @throws Exception the exception
*/
@Test
public void testSplit() throws Exception {
RRDv1 masterRrd = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/jrb-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++) {
RRDv1 singleRRD = (RRDv1) 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));
}
}
use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.
the class RRDv1IT method testMerge.
/**
* Test merge.
*
* @throws Exception the exception
*/
@Test
public void testMerge() throws Exception {
File sourceFile = new File("src/test/resources/rrd-temp-multids-jrb.xml");
File targetFile = new File("target/multimetric.xml");
RRDv1 multimetric = JaxbUtils.unmarshal(RRDv1.class, sourceFile);
Assert.assertNotNull(multimetric);
Assert.assertEquals("tempA", multimetric.getDataSource(0).getName());
Assert.assertEquals("tempB", multimetric.getDataSource(1).getName());
multimetric.getRras().stream().flatMap(rra -> rra.getRows().stream()).forEach(row -> {
List<Double> values = new ArrayList<>();
row.getValues().forEach(d -> values.add(Double.NaN));
row.setValues(values);
});
List<RRDv1> singleMetricArray = new ArrayList<>();
RRDv1 tempA = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempA-jrb.xml"));
Assert.assertNotNull(tempA);
Assert.assertEquals("tempA", tempA.getDataSource(0).getName());
singleMetricArray.add(tempA);
RRDv1 tempB = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempB-jrb.xml"));
Assert.assertNotNull(tempB);
Assert.assertEquals("tempB", tempB.getDataSource(0).getName());
singleMetricArray.add(tempB);
multimetric.merge(singleMetricArray);
JaxbUtils.marshal(multimetric, new FileWriter(targetFile));
Assert.assertTrue(FileUtils.contentEquals(sourceFile, targetFile));
targetFile.delete();
}
use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.
the class RRDv3IT method parseRrdSimple.
/**
* Parses a simple RRD.
*
* @throws Exception the exception
*/
@Test
public void parseRrdSimple() throws Exception {
RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-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)));
}
use of org.opennms.netmgt.rrd.model.v3.RRA in project opennms by OpenNMS.
the class RRDv3IT method testSamplesSingleRRA.
/**
* Test samples for a single RRA
*
* @throws Exception the exception
*/
@Test
public void testSamplesSingleRRA() throws Exception {
File source = new File("src/test/resources/sample-counter.xml");
RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, source);
Assert.assertNotNull(rrd);
NavigableMap<Long, List<Double>> samples = rrd.generateSamples(rrd.getRras().get(0));
Assert.assertFalse(samples.isEmpty());
long ts = 1441748400L;
Double v1 = 600.0;
Double v2 = 2.0;
Assert.assertEquals(rrd.getRras().get(0).getRows().size(), samples.size());
for (Map.Entry<Long, List<Double>> s : samples.entrySet()) {
System.out.println(s);
Assert.assertEquals(2, s.getValue().size());
Assert.assertEquals(ts, (long) s.getKey());
Assert.assertEquals(v1, s.getValue().get(0));
Assert.assertEquals(v2, s.getValue().get(1));
ts += 300L;
v1 += 300.0 * v2;
v2 += 1.0;
}
}
Aggregations