use of org.opennms.netmgt.rrd.model.v3.RRDv3 in project opennms by OpenNMS.
the class SnmpInterfaceRrdMigratorOnline method mergeRrd.
/**
* Merge RRDs.
*
* @param source the source RRD
* @param dest the destination RRD
* @throws Exception the exception
*/
protected void mergeRrd(File source, File dest) throws Exception {
log(" merging RRD %s into %s\n", source, dest);
RRDv3 rrdSrc = RrdConvertUtils.dumpRrd(source);
RRDv3 rrdDst = RrdConvertUtils.dumpRrd(dest);
if (rrdSrc == null || rrdDst == null) {
log(" Warning: can't load RRDs (ingoring merge).\n");
return;
}
rrdDst.merge(rrdSrc);
final File outputFile = new File(dest.getCanonicalPath() + ".merged");
RrdConvertUtils.restoreRrd(rrdDst, outputFile);
if (dest.exists()) {
FileUtils.deleteQuietly(dest);
}
FileUtils.moveFile(outputFile, dest);
}
use of org.opennms.netmgt.rrd.model.v3.RRDv3 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.RRDv3 in project opennms by OpenNMS.
the class RrdConvertUtils method convertFromJrobinToRrd.
/**
* Convert from JRobin to RRDtool.
*
* @param sourceJrobinFile the source JRobin file
* @param targetRrdFile the target RRDtool file
* @throws IOException Signals that an I/O exception has occurred.
* @throws RrdException the RRD exception
*/
public static void convertFromJrobinToRrd(File sourceJrobinFile, File targetRrdFile) throws IOException, RrdException {
RRDv1 jrb = dumpJrb(sourceJrobinFile);
RRDv3 rrd = convert(jrb);
restoreRrd(rrd, targetRrdFile);
}
use of org.opennms.netmgt.rrd.model.v3.RRDv3 in project opennms by OpenNMS.
the class NMS6302IT method testJrobinParse.
/**
* Test JRobin parse.
*
* @throws Exception the exception
*/
@Test
public void testJrobinParse() throws Exception {
RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/ifHCOutOctets.xml"), true);
Assert.assertNotNull(rrd);
}
use of org.opennms.netmgt.rrd.model.v3.RRDv3 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)));
}
Aggregations