try { Archive arc = rrd.getArchive(arcIndex); ArcState state = arc.getArcState(dsIndex); values = new Object[]{ arc.getConsolFun(), "" + arc.getXff(), "" + arc.getSteps(), "" + arc.getRows(), InspectorModel.formatDouble(state.getAccumValue()), "" + state.getNanSteps(), "" + arc.getStartTime() + " [" + new Date(arc.getStartTime() * 1000L) + "]", "" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]" };
final void archive(Datasource datasource, double value, double lastValue, long numUpdates) throws IOException { int dsIndex = getDsIndex(datasource.getName()); for (Archive archive : archives) { if (ConsolFun.AVERAGE.equals(archive.getConsolFun())) { archive.archive(dsIndex, value, numUpdates); } else { archive.archive(dsIndex, lastValue, numUpdates); } } }
/** * Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes. * * @return String representing internal RRD state. * @throws java.io.IOException Thrown in case of I/O related error. */ public synchronized String dump() throws IOException { StringBuilder buffer = new StringBuilder(); buffer.append(header.dump()); for (Datasource datasource : datasources) { buffer.append(datasource.dump()); } for (Archive archive : archives) { buffer.append(archive.dump()); } return buffer.toString(); }
/** * Returns index of Archive object with the given consolidation function and the number * of steps. Exception is thrown if such archive could not be found. * * @param consolFun Consolidation function * @param steps Number of archive steps * @return Requested Archive object * @throws IOException Thrown in case of I/O error */ public int getArcIndex(ConsolFun consolFun, int steps) throws IOException { for (int i = 0; i < archives.length; i++) { if (archives[i].getConsolFun() == consolFun && archives[i].getSteps() == steps) { return i; } } throw new IllegalArgumentException("Could not find archive " + consolFun + "/" + steps); }
if (archives[i].getConsolFun().toString().equals(consolFun)) { arcStep = archives[i].getArcStep(); diff = Math.abs(resolution - arcStep); if (startTime >= archives[i].getStartTime()) { if (diff == 0) // Best possible match either way
ArcDef arcDef = new ArcDef(archive.getConsolFun(), archive.getXff(), archive.getSteps(), archive.getRows()); rrdDef.addArchive(arcDef);
for(int i = 0; i < rrdSource.getArcCount(); i++) { Archive srcArchive = rrdSource.getArchive(i); ConsolFun consolFun = srcArchive.getConsolFun(); int steps = srcArchive.getSteps(); Archive dstArchive = rrdDest.getArchive(consolFun, steps); if(dstArchive != null) { if(dstArchive.getConsolFun().equals(srcArchive.getConsolFun()) && dstArchive.getSteps() == srcArchive.getSteps()) { for(int k = 0; k < dsCount; k++) { Datasource srcDs = rrdSource.getDatasource(k); if(j >= 0 && !badDs.contains(dsName)) { log(Level.TRACE, "Upgrade of %s from %s", dsName, srcArchive); srcArchive.getArcState(k).copyStateTo(dstArchive.getArcState(j)); srcArchive.getRobin(k).copyStateTo(dstArchive.getRobin(j)); robinMigrated++;
long bestStepDiff = 0, bestMatch = 0; for (Archive archive : archives) { if (archive.getConsolFun() == consolFun) { long arcStep = archive.getArcStep(); long arcStart = archive.getStartTime() - arcStep; long arcEnd = archive.getEndTime(); long fullMatch = fetchEnd - fetchStart; if (arcEnd >= fetchEnd && arcStart <= fetchStart) { long tmpStepDiff = Math.abs(archive.getArcStep() - resolution);
Datasource ds = rrdDb.getDatasource(dsIndex); Archive arc = rrdDb.getArchive(arcIndex); Robin robin = arc.getRobin(dsIndex); dsName = ds.getName(); t1 = arc.getStartTime(); t2 = arc.getEndTime(); long step = arc.getArcStep(); int count = robin.getSize(); timestamps = new long[count];
void archive(int dsIndex, double value, long numUpdates) throws IOException { Robin robin = robins[dsIndex]; ArcState state = states[dsIndex]; long step = parentDb.getHeader().getStep(); long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); long updateTime = Util.normalize(lastUpdateTime, step) + step; long arcStep = getArcStep(); // finish current step while (numUpdates > 0) { accumulate(state, value); numUpdates--; if (updateTime % arcStep == 0) { finalizeStep(state, robin); break; } else { updateTime += step; } } // update robin in bulk int bulkUpdateCount = (int) Math.min(numUpdates / steps.get(), (long) rows.get()); robin.bulkStore(value, bulkUpdateCount); // update remaining steps long remainingUpdates = numUpdates % steps.get(); for (long i = 0; i < remainingUpdates; i++) { accumulate(state, value); } }
try { Archive arc = rrd.getArchive(arcIndex); Robin robin = arc.getRobin(dsIndex); long start = arc.getStartTime(); long step = arc.getArcStep(); double robinValues[] = robin.getValues(); values = new Object[robinValues.length][];
/** * Sets minimum allowed value for this datasource. If <code>filterArchivedValues</code> * argument is set to true, all archived values less then <code>minValue</code> will * be fixed to NaN. * * @param minValue New minimal value. Specify <code>Double.NaN</code> if no minimal * value should be set * @param filterArchivedValues true, if archived datasource values should be fixed; * false, otherwise. * @throws java.io.IOException Thrown in case of I/O error * @throws java.lang.IllegalArgumentException Thrown if invalid minValue was supplied (not less then maxValue) */ public void setMinValue(double minValue, boolean filterArchivedValues) throws IOException { double maxValue = this.maxValue.get(); if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { throw new IllegalArgumentException(INVALID_MIN_MAX_VALUES + minValue + "/" + maxValue); } this.minValue.set(minValue); if (!Double.isNaN(minValue) && filterArchivedValues) { int dsIndex = getDsIndex(); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getRobin(dsIndex).filterValues(minValue, Double.NaN); } } }
archives[i] = new Archive(this, reader, i);
public void setDsType(DsType newDsType) throws IOException { // set datasource type this.dsType.set(newDsType.name()); // reset datasource status lastValue.set(Double.NaN); accumValue.set(0.0); // reset archive status int dsIndex = parentDb.getDsIndex(dsName.get()); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getArcState(dsIndex).setAccumValue(Double.NaN); } }
private void finalizeStep(ArcState state, Robin robin) throws IOException { // should store long arcSteps = steps.get(); double arcXff = xff.get(); long nanSteps = state.getNanSteps(); //double nanPct = (double) nanSteps / (double) arcSteps; double accumValue = state.getAccumValue(); if (nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { if (getConsolFun() == ConsolFun.AVERAGE) { accumValue /= (arcSteps - nanSteps); } robin.store(accumValue); } else { robin.store(Double.NaN); } state.setAccumValue(Double.NaN); state.setNanSteps(0); }
/** * Copies object's internal state to another RrdDb object. * * @param other New RrdDb object to copy state to * @throws IOException Thrown in case of I/O error */ public synchronized void copyStateTo(RrdUpdater other) throws IOException { if (!(other instanceof RrdDb)) { throw new IllegalArgumentException("Cannot copy RrdDb object to " + other.getClass().getName()); } RrdDb otherRrd = (RrdDb) other; header.copyStateTo(otherRrd.header); for (int i = 0; i < datasources.length; i++) { int j = Util.getMatchingDatasourceIndex(this, i, otherRrd); if (j >= 0) { datasources[i].copyStateTo(otherRrd.datasources[j]); } } for (int i = 0; i < archives.length; i++) { int j = Util.getMatchingArchiveIndex(this, i, otherRrd); if (j >= 0) { archives[i].copyStateTo(otherRrd.archives[j]); } } }
/** * <p>Writes the RRD content to OutputStream using XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging.</p> * * @param destination Output stream to receive XML data * @throws IOException Thrown in case of I/O related error */ public synchronized void dumpXml(OutputStream destination) throws IOException { XmlWriter writer = new XmlWriter(destination); writer.startTag("rrd"); // dump header header.appendXml(writer); // dump datasources for (Datasource datasource : datasources) { datasource.appendXml(writer); } // dump archives for (Archive archive : archives) { archive.appendXml(writer); } writer.closeTag(); writer.flush(); }
final void archive(Datasource datasource, double value, long numUpdates) throws IOException { int dsIndex = getDsIndex(datasource.getName()); for (Archive archive : archives) { archive.archive(dsIndex, value, numUpdates); } }
ArcDef arcDef = new ArcDef(archive.getConsolFun(), archive.getXff(), archive.getSteps(), archive.getRows()); rrdDef.addArchive(arcDef);
if (archives[i].getConsolFun().toString().equals(consolFun)) { arcStep = archives[i].getArcStep(); diff = Math.abs(resolution - arcStep); if (startTime >= archives[i].getStartTime()) { if (diff == 0) // Best possible match either way