Search in sources :

Example 1 with DataProcessor

use of org.jrobin.data.DataProcessor in project opennms by OpenNMS.

the class JrobinFetchStrategy method fetchMeasurements.

/**
     * {@inheritDoc}
     */
@Override
protected FetchResults fetchMeasurements(long start, long end, long step, int maxrows, Map<Source, String> rrdsBySource, Map<String, Object> constants) throws RrdException {
    final long startInSeconds = (long) Math.floor(start / 1000);
    final long endInSeconds = (long) Math.floor(end / 1000);
    long stepInSeconds = (long) Math.floor(step / 1000);
    // The step must be strictly positive
    if (stepInSeconds <= 0) {
        stepInSeconds = 1;
    }
    final DataProcessor dproc = new DataProcessor(startInSeconds, endInSeconds);
    if (maxrows > 0) {
        dproc.setPixelCount(maxrows);
    }
    dproc.setFetchRequestResolution(stepInSeconds);
    for (final Map.Entry<Source, String> entry : rrdsBySource.entrySet()) {
        final Source source = entry.getKey();
        final String rrdFile = entry.getValue();
        dproc.addDatasource(source.getLabel(), rrdFile, source.getEffectiveDataSource(), source.getAggregation());
    }
    try {
        dproc.processData();
    } catch (IOException e) {
        throw new RrdException("JRB processing failed.", e);
    }
    final long[] timestamps = dproc.getTimestamps();
    // Convert the timestamps to milliseconds
    for (int i = 0; i < timestamps.length; i++) {
        timestamps[i] *= 1000;
    }
    final Map<String, double[]> columns = Maps.newHashMapWithExpectedSize(rrdsBySource.keySet().size());
    for (Source source : rrdsBySource.keySet()) {
        columns.put(source.getLabel(), dproc.getValues(source.getLabel()));
    }
    return new FetchResults(timestamps, columns, dproc.getStep() * 1000, constants);
}
Also used : FetchResults(org.opennms.netmgt.measurements.api.FetchResults) DataProcessor(org.jrobin.data.DataProcessor) IOException(java.io.IOException) RrdException(org.jrobin.core.RrdException) Map(java.util.Map) Source(org.opennms.netmgt.measurements.model.Source)

Aggregations

IOException (java.io.IOException)1 Map (java.util.Map)1 RrdException (org.jrobin.core.RrdException)1 DataProcessor (org.jrobin.data.DataProcessor)1 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)1 Source (org.opennms.netmgt.measurements.model.Source)1