/** * Normalize to a probe step, as org.rrd4j.core.Util.normalize But use a * Date argument and return a Date * * @param date A Date to normalize * @param step Step in seconds * @return "Rounded" Date */ public static Date normalize(Date date, long step) { long timestamp = org.rrd4j.core.Util.getTimestamp(date); return org.rrd4j.core.Util.getDate(org.rrd4j.core.Util.normalize(timestamp, step)); }
/** * @param start the start to set */ public void setStart(Date start) { long step = getNode().getProbe().getStep(); this.start = new Date(org.rrd4j.core.Util.normalize(start.getTime() / 1000L, step) * 1000L); }
/** * 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); }
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); } }
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); } }
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); } }