Search in sources :

Example 1 with AbstractRRD

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

the class NewtsConverter method processResource.

/**
 * Process metric.
 *
 * @param resourceDir the path where the resource file lives in
 * @param fileName the RRD file name without extension
 * @param group the group name
 */
private void processResource(final Path resourceDir, final String fileName, final String group) {
    LOG.info("Processing resource: dir={}, file={}, group={}", resourceDir, fileName, group);
    final ResourcePath resourcePath = buildResourcePath(resourceDir);
    if (resourcePath == null) {
        return;
    }
    // Load the RRD file
    final Path file;
    switch(this.storageTool) {
        case RRDTOOL:
            file = resourceDir.resolve(fileName + ".rrd");
            break;
        case JROBIN:
            file = resourceDir.resolve(fileName + ".jrb");
            break;
        default:
            file = null;
    }
    if (!Files.exists(file)) {
        LOG.error("File not found: {}", file);
        return;
    }
    final AbstractRRD rrd;
    try {
        switch(this.storageTool) {
            case RRDTOOL:
                rrd = RrdConvertUtils.dumpRrd(file.toFile());
                break;
            case JROBIN:
                rrd = RrdConvertUtils.dumpJrb(file.toFile());
                break;
            default:
                rrd = null;
        }
    } catch (final Exception e) {
        LOG.error("Can't parse JRB/RRD file: {}", file, e);
        return;
    }
    // Inject the samples from the RRD file to NewTS
    try {
        this.injectSamplesToNewts(resourcePath, group, rrd.getDataSources(), rrd.generateSamples());
    } catch (final Exception e) {
        LOG.error("Failed to convert file: {}", file, e);
        return;
    }
}
Also used : Path(java.nio.file.Path) ResourcePath(org.opennms.netmgt.model.ResourcePath) ResourcePath(org.opennms.netmgt.model.ResourcePath) AbstractRRD(org.opennms.netmgt.rrd.model.AbstractRRD) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException)

Example 2 with AbstractRRD

use of org.opennms.netmgt.rrd.model.AbstractRRD 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

AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ParseException (org.apache.commons.cli.ParseException)1 Test (org.junit.Test)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 Row (org.opennms.netmgt.rrd.model.Row)1 RRA (org.opennms.netmgt.rrd.model.v3.RRA)1 RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)1