/** * <p>Returns RRD definition object which can be used to create new RRD * with the same creation parameters but with no data in it.</p> * <p/> * <p>Example:</p> * <p/> * <pre> * RrdDb rrd1 = new RrdDb("original.rrd"); * RrdDef def = rrd1.getRrdDef(); * // fix path * def.setPath("empty_copy.rrd"); * // create new RRD file * RrdDb rrd2 = new RrdDb(def); * </pre> * * @return RRD definition. */ public RrdDef getRrdDef() { lock (sync) { // set header long startTime = header.getLastUpdateTime(); long step = header.getStep(); String path = backend.getPath(); RrdDef rrdDef = new RrdDef(path, startTime, step); // add Datasources foreach (Datasource Datasource in Datasources) { DsDef dsDef = new DsDef(Datasource.DsName, Datasource.DsType, Datasource.Heartbeat, Datasource.MinValue, Datasource.MaxValue); rrdDef.addDatasource(dsDef); } // add archives foreach (Archive archive in archives) { ArcDef arcDef = new ArcDef(archive.getConsolFun(), archive.getXff(), archive.getSteps(), archive.getRows()); rrdDef.addArchive(arcDef); } return(rrdDef); } }
public void process(long newTime, double newValue) { 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); } }
public Datasource(RrdDb parentDb, DsDef dsDef) { bool shouldInitialize = dsDef != null; this.parentDb = parentDb; dsName = new RrdString(this); dsTypeName = new RrdString(this); if (!shouldInitialize) { dsType = new DsType(dsTypeName.get()); } 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 = dsDef.getDsType(); dsTypeName.set(dsType.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()); } }
public ArcState(Archive parentArc, bool shouldInitialize) { 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); } }