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);
}
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);
}
Aggregations