/** * Returns an array of last datasource values. The first value in the array corresponds * to the first datasource defined in the RrdDb and so on. * * @return Array of last datasource values * @throws IOException Thrown in case of I/O error */ public synchronized double[] getLastDatasourceValues() throws IOException { double[] values = new double[datasources.length]; for (int i = 0; i < values.length; i++) { values[i] = datasources[i].getLastValue(); } return values; }
/** * Returns an array of datasource names defined in RRD. * * @return Array of datasource names. * @throws java.io.IOException Thrown in case of I/O error. */ public String[] getDsNames() throws IOException { int n = datasources.length; String[] dsNames = new String[n]; for (int i = 0; i < n; i++) { dsNames[i] = datasources[i].getName(); } return dsNames; }
/** * Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes. * * @return String representing internal RRD state. * @throws java.io.IOException Thrown in case of I/O related error. */ public synchronized String dump() throws IOException { StringBuilder buffer = new StringBuilder(); buffer.append(header.dump()); for (Datasource datasource : datasources) { buffer.append(datasource.dump()); } for (Archive archive : archives) { buffer.append(archive.dump()); } return buffer.toString(); }
Datasource ds = rrd.getDatasource(dsIndex); values = new Object[]{ ds.getName(), ds.getType(), "" + ds.getHeartbeat(), InspectorModel.formatDouble(ds.getMinValue()), InspectorModel.formatDouble(ds.getMaxValue()), InspectorModel.formatDouble(ds.getLastValue()), InspectorModel.formatDouble(ds.getAccumValue()), "" + ds.getNanSeconds() };
DsDef dsDef = new DsDef(datasource.getName(), datasource.getType(), datasource.getHeartbeat(), datasource.getMinValue(), datasource.getMaxValue()); rrdDef.addDatasource(dsDef);
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); } }
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); } }
for(int i = 0; i < dsCount; i++) { Datasource srcDs = rrdSource.getDatasource(i); String dsName = srcDs.getName(); Datasource dstDS = rrdDest.getDatasource(dsName); if(dstDS != null) { try { srcDs.copyStateTo(dstDS); log(Level.TRACE, "Update %s", dsName); } catch (RuntimeException e) { for(int k = 0; k < dsCount; k++) { Datasource srcDs = rrdSource.getDatasource(k); String dsName = srcDs.getName(); try { int j = rrdDest.getDsIndex(dsName);
/** * Sets min/max values allowed for this datasource. If <code>filterArchivedValues</code> * argument is set to true, all archived values less then <code>minValue</code> or * greater then <code>maxValue</code> will be fixed to NaN. * * @param minValue New minimal value. Specify <code>Double.NaN</code> if no min * value should be set. * @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 min/max values were supplied */ public void setMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues) throws IOException { if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { throw new IllegalArgumentException(INVALID_MIN_MAX_VALUES + minValue + "/" + maxValue); } this.minValue.set(minValue); this.maxValue.set(maxValue); if (!(Double.isNaN(minValue) && Double.isNaN(maxValue)) && filterArchivedValues) { int dsIndex = getDsIndex(); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getRobin(dsIndex).filterValues(minValue, maxValue); } } }
datasources[i] = new Datasource(this, reader, i);
/** * Copies object's internal state to another RrdDb object. * * @param other New RrdDb object to copy state to * @throws IOException Thrown in case of I/O error */ public synchronized void copyStateTo(RrdUpdater other) throws IOException { if (!(other instanceof RrdDb)) { throw new IllegalArgumentException("Cannot copy RrdDb object to " + other.getClass().getName()); } RrdDb otherRrd = (RrdDb) other; header.copyStateTo(otherRrd.header); for (int i = 0; i < datasources.length; i++) { int j = Util.getMatchingDatasourceIndex(this, i, otherRrd); if (j >= 0) { datasources[i].copyStateTo(otherRrd.datasources[j]); } } for (int i = 0; i < archives.length; i++) { int j = Util.getMatchingArchiveIndex(this, i, otherRrd); if (j >= 0) { archives[i].copyStateTo(otherRrd.archives[j]); } } }
/** * <p>Writes the RRD content to OutputStream using XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging.</p> * * @param destination Output stream to receive XML data * @throws IOException Thrown in case of I/O related error */ public synchronized void dumpXml(OutputStream destination) throws IOException { XmlWriter writer = new XmlWriter(destination); writer.startTag("rrd"); // dump header header.appendXml(writer); // dump datasources for (Datasource datasource : datasources) { datasource.appendXml(writer); } // dump archives for (Archive archive : archives) { archive.appendXml(writer); } writer.closeTag(); writer.flush(); }
DsDef dsDef = new DsDef(datasource.getName(), datasource.getType(), datasource.getHeartbeat(), datasource.getMinValue(), datasource.getMaxValue()); rrdDef.addDatasource(dsDef);
/** * Sets min/max values allowed for this datasource. If <code>filterArchivedValues</code> * argment is set to true, all archived values less then <code>minValue</code> or * greater then <code>maxValue</code> will be fixed to NaN. * * @param minValue New minimal value. Specify <code>Double.NaN</code> if no min * value should be set. * @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 IOException Thrown in case of I/O error * @throws IllegalArgumentException Thrown if invalid min/max values were supplied */ public void setMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues) throws IOException { if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { throw new IllegalArgumentException("Invalid min/max values: " + minValue + "/" + maxValue); } this.minValue.set(minValue); this.maxValue.set(maxValue); if (!(Double.isNaN(minValue) && Double.isNaN(maxValue)) && filterArchivedValues) { int dsIndex = getDsIndex(); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getRobin(dsIndex).filterValues(minValue, maxValue); } } }
datasources = new Datasource[dsCount]; for (int i = 0; i < dsCount; i++) { datasources[i] = new Datasource(this, null);
/** * {@inheritDoc} * <p> * Copies object's internal state to another RrdDb object. */ public synchronized void copyStateTo(RrdDb otherRrd) throws IOException { header.copyStateTo(otherRrd.header); for (int i = 0; i < datasources.length; i++) { int j = Util.getMatchingDatasourceIndex(this, i, otherRrd); if (j >= 0) { datasources[i].copyStateTo(otherRrd.datasources[j]); } } for (int i = 0; i < archives.length; i++) { int j = Util.getMatchingArchiveIndex(this, i, otherRrd); if (j >= 0) { archives[i].copyStateTo(otherRrd.archives[j]); } } }
/** * Writes the RRD content to OutputStream using XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging. * * @param destination Output stream to receive XML data * @throws java.io.IOException Thrown in case of I/O related error */ public synchronized void dumpXml(OutputStream destination) throws IOException { XmlWriter writer = new XmlWriter(destination); writer.startTag("rrd"); // dump header header.appendXml(writer); // dump datasources for (Datasource datasource : datasources) { datasource.appendXml(writer); } // dump archives for (Archive archive : archives) { archive.appendXml(writer); } writer.closeTag(); writer.flush(); }
/** * <p>Returns an array of datasource names defined in RRD.</p> * * @return Array of datasource names. * @throws IOException Thrown in case of I/O error. */ public String[] getDsNames() throws IOException { int n = datasources.length; String[] dsNames = new String[n]; for (int i = 0; i < n; i++) { dsNames[i] = datasources[i].getName(); } return dsNames; }