Search in sources :

Example 1 with AbstractDS

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

the class NewtsConverter method injectSamplesToNewts.

private void injectSamplesToNewts(final ResourcePath resourcePath, final String group, final List<? extends AbstractDS> dataSources, final SortedMap<Long, List<Double>> samples) {
    final ResourcePath groupPath = ResourcePath.get(resourcePath, group);
    // Create a resource ID from the resource path
    final String groupId = NewtsUtils.toResourceId(groupPath);
    // Build indexing attributes
    final Map<String, String> attributes = Maps.newHashMap();
    NewtsUtils.addIndicesToAttributes(groupPath, attributes);
    // Create the NewTS resource to insert
    final Resource resource = new Resource(groupId, Optional.of(attributes));
    // Transform the RRD samples into NewTS samples
    List<Sample> batch = new ArrayList<>(this.batchSize);
    for (final Map.Entry<Long, List<Double>> s : samples.entrySet()) {
        for (int i = 0; i < dataSources.size(); i++) {
            final double value = s.getValue().get(i);
            if (Double.isNaN(value)) {
                continue;
            }
            final AbstractDS ds = dataSources.get(i);
            final Timestamp timestamp = Timestamp.fromEpochSeconds(s.getKey());
            try {
                batch.add(toSample(ds, resource, timestamp, value));
            } catch (IllegalArgumentException e) {
                // type i.e. negative for a counter, so we silently skip these
                continue;
            }
            if (batch.size() >= this.batchSize) {
                this.repository.insert(batch, true);
                this.processedSamples.getAndAdd(batch.size());
                batch = new ArrayList<>(this.batchSize);
            }
        }
    }
    if (!batch.isEmpty()) {
        this.repository.insert(batch, true);
        this.processedSamples.getAndAdd(batch.size());
    }
    this.processedMetrics.getAndAdd(dataSources.size());
    LOG.trace("Stats: {} / {}", this.processedMetrics, this.processedSamples);
}
Also used : Sample(org.opennms.newts.api.Sample) Resource(org.opennms.newts.api.Resource) ArrayList(java.util.ArrayList) Timestamp(org.opennms.newts.api.Timestamp) AbstractDS(org.opennms.netmgt.rrd.model.AbstractDS) ResourcePath(org.opennms.netmgt.model.ResourcePath) UnsignedLong(com.google.common.primitives.UnsignedLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 2 with AbstractDS

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

the class JRobinConverter method consolidateRrdFile.

public void consolidateRrdFile(final File groupFile, final File outputFile) throws IOException, RrdException, ConverterException {
    /*
        final List<RrdDatabase> rrds = new ArrayList<RrdDatabase>();
        rrds.add(new RrdDatabase(new RrdDb(groupFile, true)));
        for (final File individualFile : getMatchingGroupRrds(groupFile)) {
            final RrdDb individualRrd = new RrdDb(individualFile, true);
            rrds.add(new RrdDatabase(individualRrd));
        }
        final TimeSeriesDataSource dataSource = new AggregateTimeSeriesDataSource(rrds);

        final RrdDb outputRrd = new RrdDb(outputFile);
        final RrdDatabaseWriter writer = new RrdDatabaseWriter(outputRrd);

        final long endTime = dataSource.getEndTime();
        // 1 year
        final long startTime = endTime - ONE_YEAR_IN_SECONDS;
        for (long time = startTime; time <= endTime; time += dataSource.getNativeStep()) {
            final RrdEntry entry = dataSource.getDataAt(time);
            writer.write(entry);
        }
        dataSource.close();
        outputRrd.close();
        */
    final RRDv1 groupRrd = RrdConvertUtils.dumpJrb(groupFile);
    LogUtils.debugf(this, "consolidateRrdFile: multi-metric RRD with %d data sources", groupRrd.getDataSources().size());
    int i = 1;
    for (AbstractDS ds : groupRrd.getDataSources()) {
        LogUtils.debugf(this, "consolidateRrdFile: multi-metric data source %d: %s", i++, ds.getName());
    }
    final List<RRDv1> singleMetricFiles = new ArrayList<RRDv1>();
    for (final File individualFile : getMatchingGroupRrds(groupFile)) {
        final RRDv1 singleRrd = RrdConvertUtils.dumpJrb(individualFile);
        LogUtils.debugf(this, "consolidateRrdFile: adding single-metric RRD for data source %s", singleRrd.getDataSource(0).getName());
        singleMetricFiles.add(singleRrd);
    }
    groupRrd.merge(singleMetricFiles);
    RrdConvertUtils.restoreJrb(groupRrd, outputFile);
}
Also used : AbstractDS(org.opennms.netmgt.rrd.model.AbstractDS) RRDv1(org.opennms.netmgt.rrd.model.v1.RRDv1) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)2 AbstractDS (org.opennms.netmgt.rrd.model.AbstractDS)2 UnsignedLong (com.google.common.primitives.UnsignedLong)1 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)1 Resource (org.opennms.newts.api.Resource)1 Sample (org.opennms.newts.api.Sample)1 Timestamp (org.opennms.newts.api.Timestamp)1