Search in sources :

Example 1 with RRDv3

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);
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) File(java.io.File)

Example 2 with RRDv3

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());
    }
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) Row(org.opennms.netmgt.rrd.model.Row)

Example 3 with RRDv3

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);
}
Also used : RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3)

Example 4 with RRDv3

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);
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) File(java.io.File) Test(org.junit.Test)

Example 5 with RRDv3

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)));
}
Also used : RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) File(java.io.File) Test(org.junit.Test)

Aggregations

RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)21 File (java.io.File)15 Test (org.junit.Test)14 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)8 ArrayList (java.util.ArrayList)5 Row (org.opennms.netmgt.rrd.model.Row)4 List (java.util.List)3 RRA (org.opennms.netmgt.rrd.model.v3.RRA)3 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 SortedMap (java.util.SortedMap)2 AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 SAXSource (javax.xml.transform.sax.SAXSource)1 FileUtils (org.apache.commons.io.FileUtils)1 RrdException (org.jrobin.core.RrdException)1