Search in sources :

Example 1 with Sample

use of org.jrobin.core.Sample in project jmxtrans by jmxtrans.

the class RRDWriter method internalWrite.

@Override
public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
    RrdDb db = null;
    try {
        db = createOrOpenDatabase();
        Sample sample = db.createSample();
        List<String> dsNames = Arrays.asList(db.getDsNames());
        // keys from the result values
        for (Result res : results) {
            for (Entry<String, Object> entry : res.getValues().entrySet()) {
                if (dsNames.contains(entry.getKey()) && isNumeric(entry.getValue())) {
                    sample.setValue(entry.getKey(), Double.valueOf(entry.getValue().toString()));
                }
            }
        }
        sample.update();
    } finally {
        if (db != null) {
            db.close();
        }
    }
}
Also used : Sample(org.jrobin.core.Sample) RrdDb(org.jrobin.core.RrdDb) Result(com.googlecode.jmxtrans.model.Result)

Example 2 with Sample

use of org.jrobin.core.Sample in project opennms by OpenNMS.

the class JRobinConverterTest method createMockVariationRrds.

private void createMockVariationRrds(final RrdBackendFactory factory) throws RrdException, IOException {
    final long end = getMidnightInSeconds(m_baseTime);
    initializeRrd(m_variation, new String[] { "a", "b" }, new String[] { "1:4032", "12:1488", "288:366" });
    initializeRrd(m_overlapping, new String[] { "c", "d", "a" }, new String[] { "1:4032", "12:1488", "288:366" });
    final RrdDb variation;
    final RrdDb overlapping;
    if (factory == null) {
        variation = new RrdDb(m_variation);
        overlapping = new RrdDb(m_overlapping);
    } else {
        variation = new RrdDb(m_variation.getAbsolutePath(), factory);
        overlapping = new RrdDb(m_overlapping.getAbsolutePath(), factory);
    }
    final long start = (end - SECONDS_PER_YEAR);
    final Function sequence = new AverageSequence(300, 10);
    final Function sequenceCounter = new Counter(0, sequence);
    final Function overlappingSequence = new AverageSequence(300, 20);
    final Function overlappingCounter = new Counter(0, overlappingSequence);
    long timestamp = start - 300L;
    for (; timestamp <= end; timestamp += 300L) {
        final Sample variationSample = variation.createSample(timestamp);
        final double variationValue = sequenceCounter.evaluate(timestamp);
        variationSample.setValue("a", variationValue);
        variationSample.update();
        final Sample overlappingSample = overlapping.createSample(timestamp);
        final double overlappingValue = overlappingCounter.evaluate(timestamp);
        overlappingSample.setValue("d", Double.NaN);
        if (((timestamp % 1200) / 300) < 2) {
            overlappingSample.setValue("a", overlappingValue);
        }
        overlappingSample.setValue("c", overlappingValue);
        overlappingSample.update();
    }
    variation.close();
    overlapping.close();
}
Also used : Sample(org.jrobin.core.Sample) RrdDb(org.jrobin.core.RrdDb)

Example 3 with Sample

use of org.jrobin.core.Sample in project opennms by OpenNMS.

the class JRobinRrdStrategy method updateFile.

/**
     * {@inheritDoc}
     *
     * Creates a sample from the JRobin RrdDb and passes in the data provided.
     */
@Override
public void updateFile(final RrdDb rrdFile, final String owner, final String data) throws Exception {
    Sample sample = rrdFile.createSample();
    sample.setAndUpdate(data);
}
Also used : Sample(org.jrobin.core.Sample)

Example 4 with Sample

use of org.jrobin.core.Sample in project opennms by OpenNMS.

the class JRobinRrdStrategyTest method testCreate.

@Test
public void testCreate() throws Exception {
    File rrdFile = createRrdFile();
    RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
    //m_strategy.updateFile(openedFile, "huh?", "N:1,234234");
    Sample sample = ((RrdDb) openedFile).createSample();
    sample.set("N:1.234 something not that politically incorrect");
    System.err.println(sample.dump());
    m_strategy.closeFile(openedFile);
}
Also used : Sample(org.jrobin.core.Sample) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) Test(org.junit.Test)

Example 5 with Sample

use of org.jrobin.core.Sample in project opennms by OpenNMS.

the class RrdDatabaseWriter method write.

public void write(final RrdEntry entry) throws IOException, RrdException {
    final Sample s = m_rrd.createSample(entry.getTimestamp());
    final double[] values = new double[entry.getDsNames().size()];
    int i = 0;
    for (final String dsName : entry.getDsNames()) {
        if (dsName != null) {
            Double value = entry.getValue(dsName);
            final Datasource dataSource = m_rrd.getDatasource(dsName);
            if (value != null) {
                if (dataSource.getDsType().equals("COUNTER")) {
                    final double counterValue = getLastValue(dsName) + (value * m_step);
                    if (Double.isInfinite(counterValue)) {
                        // if we've overrun the counter, calculate our own counter loop
                        final BigDecimal bigValue = BigDecimal.valueOf(value);
                        final BigDecimal bigLastValue = BigDecimal.valueOf(getLastValue(dsName));
                        final BigDecimal bigStep = BigDecimal.valueOf(m_step);
                        final BigDecimal newValue = bigLastValue.multiply(bigStep).add(bigValue).subtract(m_doubleMax);
                        value = newValue.doubleValue();
                    } else {
                        value = counterValue;
                    }
                }
                values[i] = value;
                setLastValue(dsName, value);
            }
        }
        i++;
    }
    s.setValues(values);
    //        LogUtils.debugf(this, "writing sample to %s: %s", outputRrd, s);
    s.update();
}
Also used : Datasource(org.jrobin.core.Datasource) Sample(org.jrobin.core.Sample) BigDecimal(java.math.BigDecimal)

Aggregations

Sample (org.jrobin.core.Sample)9 RrdDb (org.jrobin.core.RrdDb)7 File (java.io.File)4 Test (org.junit.Test)4 Ignore (org.junit.Ignore)2 Result (com.googlecode.jmxtrans.model.Result)1 BigDecimal (java.math.BigDecimal)1 Datasource (org.jrobin.core.Datasource)1 RrdException (org.opennms.netmgt.rrd.RrdException)1 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)1