/** * Returns archive time step in seconds. Archive step is equal to RRD step * multiplied with the number of archive steps. * * @return Archive time step in seconds * @throws IOException Thrown in case of I/O error. */ public long getArcStep() throws IOException { return parentDb.getHeader().getStep() * steps.get(); }
/** * Returns archive time step in seconds. Archive step is equal to RRD step * multiplied with the number of archive steps. * * @return Archive time step in seconds * @throws java.io.IOException Thrown in case of I/O error. */ public long getArcStep() throws IOException { return parentDb.getHeader().getStep() * steps.get(); }
/** * Returns current ending timestamp. This value is not constant. * * @return Timestamp corresponding to the last archive row * @throws java.io.IOException Thrown in case of I/O error. */ public long getEndTime() throws IOException { long arcStep = getArcStep(); long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); return Util.normalize(lastUpdateTime, arcStep); }
/** * Returns current ending timestamp. This value is not constant. * * @return Timestamp corresponding to the last archive row * @throws IOException Thrown in case of I/O error. */ public long getEndTime() throws IOException { long arcStep = getArcStep(); long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); return Util.normalize(lastUpdateTime, arcStep); }
/** * 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]); } } }
/** * {@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]); } } }
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); } }
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); } }
void setFile(File newFile) { try { values = null; String path = newFile.getAbsolutePath(); RrdDb rrd = new RrdDb(path, true); try { Header header = rrd.getHeader(); String signature = header.getSignature(); String step = "" + header.getStep(); String lastTimestamp = header.getLastUpdateTime() + " [" + new Date(header.getLastUpdateTime() * 1000L) + "]"; String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); String size = rrd.getRrdBackend().getLength() + " bytes"; values = new Object[]{ path, signature, step, lastTimestamp, datasources, archives, size }; } finally { rrd.close(); } fireTableDataChanged(); } catch (Exception e) { Util.error(null, e); } } }
ArcState(Archive parentArc, boolean shouldInitialize) throws IOException { this.parentArc = parentArc; accumValue = new RrdDouble<>(this); nanSteps = new RrdLong<>(this); if (shouldInitialize) { Header header = parentArc.getParentDb().getHeader(); long step = header.getStep(); long lastUpdateTime = header.getLastUpdateTime(); long arcStep = parentArc.getArcStep(); long initNanSteps = (Util.normalize(lastUpdateTime, step) - Util.normalize(lastUpdateTime, arcStep)) / step; accumValue.set(Double.NaN); nanSteps.set(initNanSteps); } }
ArcState(Archive parentArc, boolean shouldInitialize) throws IOException { this.parentArc = parentArc; accumValue = new RrdDouble(this); nanSteps = new RrdLong(this); if (shouldInitialize) { Header header = parentArc.getParentDb().getHeader(); long step = header.getStep(); long lastUpdateTime = header.getLastUpdateTime(); long arcStep = parentArc.getArcStep(); long initNanSteps = (Util.normalize(lastUpdateTime, step) - Util.normalize(lastUpdateTime, arcStep)) / step; accumValue.set(Double.NaN); nanSteps.set(initNanSteps); } }
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); } }
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); } }
final void process(long newTime, double newValue) throws IOException { Header header = parentDb.getHeader(); long step = header.getStep(); long oldTime = header.getLastUpdateTime(); long startTime = Util.normalize(oldTime, step); long endTime = startTime + step; double oldValue = lastValue.get(); double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); if (newTime < endTime) { accumulate(oldTime, newTime, updateValue); } else { // should store something long boundaryTime = Util.normalize(newTime, step); accumulate(oldTime, boundaryTime, updateValue); double value = calculateTotal(startTime, boundaryTime); // how many updates? long numSteps = (boundaryTime - endTime) / step + 1L; // ACTION! parentDb.archive(this, value, numSteps); // cleanup nanSeconds.set(0); accumValue.set(0.0); accumulate(boundaryTime, newTime, updateValue); } }
final void process(long newTime, double newValue) throws IOException { Header header = parentDb.getHeader(); long step = header.getStep(); long oldTime = header.getLastUpdateTime(); long startTime = Util.normalize(oldTime, step); long endTime = startTime + step; double oldValue = lastValue.get(); double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); if (newTime < endTime) { accumulate(oldTime, newTime, updateValue); } else { // should store something long boundaryTime = Util.normalize(newTime, step); accumulate(oldTime, boundaryTime, updateValue); double value = calculateTotal(startTime, boundaryTime); double lastCalculateValue = calculateLastTotal(startTime, boundaryTime); // how many updates? long numSteps = (boundaryTime - endTime) / step + 1L; // ACTION! parentDb.archive(this, value, lastCalculateValue, numSteps); // cleanup nanSeconds.set(0); accumValue.set(0.0); accumLastValue = Double.NaN; accumulate(boundaryTime, newTime, updateValue); } }
Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { boolean shouldInitialize = dsDef != null; this.parentDb = parentDb; dsName = new RrdString<>(this); dsType = new RrdEnum<>(this, DsType.class); heartbeat = new RrdLong<>(this); minValue = new RrdDouble<>(this); maxValue = new RrdDouble<>(this); lastValue = new RrdDouble<>(this); accumValue = new RrdDouble<>(this); nanSeconds = new RrdLong<>(this); accumLastValue = Double.NaN; if (shouldInitialize) { dsName.set(dsDef.getDsName()); dsType.set(dsDef.getDsType()); heartbeat.set(dsDef.getHeartbeat()); minValue.set(dsDef.getMinValue()); maxValue.set(dsDef.getMaxValue()); lastValue.set(Double.NaN); accumValue.set(0.0); Header header = parentDb.getHeader(); nanSeconds.set(header.getLastUpdateTime() % header.getStep()); } }
Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { boolean shouldInitialize = dsDef != null; this.parentDb = parentDb; dsName = new RrdString(this); dsType = new RrdString(this); heartbeat = new RrdLong(this); minValue = new RrdDouble(this); maxValue = new RrdDouble(this); lastValue = new RrdDouble(this); accumValue = new RrdDouble(this); nanSeconds = new RrdLong(this); if (shouldInitialize) { dsName.set(dsDef.getDsName()); dsType.set(dsDef.getDsType().name()); heartbeat.set(dsDef.getHeartbeat()); minValue.set(dsDef.getMinValue()); maxValue.set(dsDef.getMaxValue()); lastValue.set(Double.NaN); accumValue.set(0.0); Header header = parentDb.getHeader(); nanSeconds.set(header.getLastUpdateTime() % header.getStep()); } }