String dump() throws IOException { StringBuilder sb = new StringBuilder("== ARCHIVE ==\n"); sb.append("RRA:").append(consolFun.get()).append(":").append(xff.get()).append(":").append(steps.get()).append(":").append(rows.get()).append("\n"); sb.append("interval [").append(getStartTime()).append(", ").append(getEndTime()).append("]" + "\n"); for (int i = 0; i < robins.length; i++) { sb.append(states[i].dump()); sb.append(robins[i].dump()); } return sb.toString(); }
/** * 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); } } }
/** * Copies object's internal state to another Archive object. * * @param other New Archive object to copy state to * @throws IOException Thrown in case of I/O error */ public void copyStateTo(RrdUpdater other) throws IOException { if (!(other instanceof Archive)) { throw new IllegalArgumentException( "Cannot copy Archive object to " + other.getClass().getName()); } Archive arc = (Archive) other; if (!arc.consolFun.get().equals(consolFun.get())) { throw new IllegalArgumentException("Incompatible consolidation functions"); } if (arc.steps.get() != steps.get()) { throw new IllegalArgumentException("Incompatible number of steps"); } int count = parentDb.getHeader().getDsCount(); for (int i = 0; i < count; i++) { int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); if (j >= 0) { states[i].copyStateTo(arc.states[j]); robins[i].copyStateTo(arc.robins[j]); } } }
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { assert columnIndex == 2 : "Column " + columnIndex + " is not editable!"; double value; try { value = Double.parseDouble(aValue.toString()); } catch (NumberFormatException nfe) { value = Double.NaN; } if (dsIndex >= 0 && arcIndex >= 0 && file != null) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); try { Robin robin = rrd.getArchive(arcIndex).getRobin(dsIndex); robin.setValue(rowIndex, value); values[rowIndex][2] = InspectorModel.formatDouble(robin.getValue(rowIndex)); } finally { rrd.close(); } } catch (Exception e) { Util.error(null, e); } } }
long start = arc.getStartTime(); long step = arc.getArcStep(); double robinValues[] = robin.getValues(); values = new Object[robinValues.length][]; for (int i = 0; i < robinValues.length; i++) {
Archive(RrdDb parentDb, DataImporter reader, int arcIndex) throws IOException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), reader.getSteps(arcIndex), reader.getRows(arcIndex))); int n = parentDb.getHeader().getDsCount(); for (int i = 0; i < n; i++) { // restore state states[i].setAccumValue(reader.getStateAccumValue(arcIndex, i)); states[i].setNanSteps(reader.getStateNanSteps(arcIndex, i)); // restore robins double[] values = reader.getValues(arcIndex, i); robins[i].update(values); } }
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); }
void appendXml(XmlWriter writer) throws IOException { writer.startTag("rra"); writer.writeTag("cf", consolFun.get()); writer.writeComment(getArcStep() + " seconds"); writer.writeTag("pdp_per_row", steps.get()); writer.writeTag("xff", xff.get()); writer.startTag("cdp_prep"); for (ArcState state : states) { state.appendXml(writer); } writer.closeTag(); // cdp_prep writer.startTag("database"); long startTime = getStartTime(); for (int i = 0; i < rows.get(); i++) { long time = startTime + i * getArcStep(); writer.writeComment(Util.getDate(time) + " / " + time); writer.startTag("row"); for (Robin robin : robins) { writer.writeTag("v", robin.getValue(i)); } writer.closeTag(); // row } writer.closeTag(); // database writer.closeTag(); // rra }
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); } }
/** * {@inheritDoc} * * Copies object's internal state to another Archive object. */ public void copyStateTo(Archive arc) throws IOException { if (arc.consolFun.get() != consolFun.get()) { throw new IllegalArgumentException("Incompatible consolidation functions"); } if (arc.steps.get() != steps.get()) { throw new IllegalArgumentException("Incompatible number of steps"); } int count = parentDb.getHeader().getDsCount(); for (int i = 0; i < count; i++) { int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); if (j >= 0) { states[i].copyStateTo(arc.states[j]); robins[i].copyStateTo(arc.robins[j]); } } }
for (int i = 0; i < dsCount; i++) { int dsIndex = parentDb.getDsIndex(dsToFetch[i]); robinValues[i] = robins[dsIndex].getValues(matchStartIndex, matchCount);
Archive(RrdDb parentDb, DataImporter reader, int arcIndex) throws IOException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), reader.getSteps(arcIndex), reader.getRows(arcIndex))); int n = parentDb.getHeader().getDsCount(); for (int i = 0; i < n; i++) { // restore state states[i].setAccumValue(reader.getStateAccumValue(arcIndex, i)); states[i].setNanSteps(reader.getStateNanSteps(arcIndex, i)); // restore robins double[] values = reader.getValues(arcIndex, i); robins[i].update(values); } }
private void finalizeStep(ArcState state, Robin robin) throws IOException { // should store long arcSteps = steps.get(); double arcXff = xff.get(); long nanSteps = state.getNanSteps(); double accumValue = state.getAccumValue(); if (nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { if (consolFun.get() == ConsolFun.AVERAGE) { accumValue /= (arcSteps - nanSteps); } robin.store(accumValue); } else { robin.store(Double.NaN); } state.setAccumValue(Double.NaN); state.setNanSteps(0); }
void appendXml(XmlWriter writer) throws IOException { writer.startTag("rra"); writer.writeTag("cf", consolFun.name()); writer.writeComment(getArcStep() + " seconds"); writer.writeTag("pdp_per_row", steps.get()); writer.startTag("params"); writer.writeTag("xff", xff.get()); writer.closeTag(); // params writer.startTag("cdp_prep"); for (ArcState state : states) { state.appendXml(writer); } writer.closeTag(); // cdp_prep writer.startTag("database"); long startTime = getStartTime(); for (int i = 0; i < rows.get(); i++) { long time = startTime + i * getArcStep(); writer.writeComment(Util.getDate(time) + " / " + time); writer.startTag("row"); for (Robin robin : robins) { writer.writeTag("v", robin.getValue(i)); } writer.closeTag(); // row } writer.closeTag(); // database writer.closeTag(); // rra }
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); } }
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++;
/** * Sets maximum allowed value for this datasource. If <code>filterArchivedValues</code> * argument is set to true, all archived values greater then <code>maxValue</code> will * be fixed to NaN. * * @param maxValue New maximal value. Specify <code>Double.NaN</code> if no max * 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 maxValue was supplied (not greater then minValue) */ public void setMaxValue(double maxValue, boolean filterArchivedValues) throws IOException { double minValue = this.minValue.get(); if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { throw new IllegalArgumentException(INVALID_MIN_MAX_VALUES + minValue + "/" + maxValue); } this.maxValue.set(maxValue); if (!Double.isNaN(maxValue) && filterArchivedValues) { int dsIndex = getDsIndex(); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getRobin(dsIndex).filterValues(Double.NaN, maxValue); } } }