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 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 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 Archive(RrdDb parentDb, ArcDef arcDef) { bool shouldInitialize = arcDef != null; this.parentDb = parentDb; consolFun = new RrdString(this, true); // constant, may be cached xff = new RrdDouble(this); steps = new RrdInt(this, true); // constant, may be cached rows = new RrdInt(this, true); // constant, may be cached if (shouldInitialize) { consolFun.set(arcDef.getConsolFun().Name); xff.set(arcDef.getXff()); steps.set(arcDef.getSteps()); rows.set(arcDef.getRows()); } int n = parentDb.getHeader().getDsCount(); states = new ArcState[n]; robins = new Robin[n]; for (int i = 0; i < n; i++) { states[i] = new ArcState(this, shouldInitialize); int numRows = rows.get(); robins[i] = new Robin(this, numRows, shouldInitialize); } }
//// read from XML //public Archive(RrdDb parentDb, DataImporter reader, int arcIndex) { // 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); // } //} /** * 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 * @Thrown in case of I/O error. */ public long getArcStep() { long step = parentDb.getHeader().getStep(); return(step * steps.get()); }