public void archive(Datasource Datasource, double value, long numUpdates) { int dsIndex = getDsIndex(Datasource.DsName); foreach (Archive archive in archives) { archive.archive(dsIndex, value, numUpdates); } }
/** * <p>Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes.</p> * * @return String representing internal RRD state. * @Thrown in case of I/O related error. */ public String dump() { lock (sync) { StringBuilder buffer = new StringBuilder(); buffer.Append(header.dump()); foreach (Datasource Datasource in Datasources) { buffer.Append(Datasource.dump()); } foreach (Archive archive in archives) { buffer.Append(archive.dump()); } return(buffer.ToString()); } }
public void copyStateTo(RrdUpdater other) { if (!(other.GetType() == typeof(Datasource))) { throw new ArgumentException( "Cannot copy Datasource object to " + other.GetType().ToString()); } Datasource datasource = (Datasource)other; if (datasource.dsName.get().CompareTo(dsName.get()) != 0) { throw new ArgumentException("Incompatible datasource names"); } if (datasource.DsType.Name.CompareTo(dsType.Name) != 0) { throw new ArgumentException("Incompatible datasource types"); } datasource.lastValue.set(lastValue.get()); datasource.nanSeconds.set(nanSeconds.get()); datasource.accumValue.set(accumValue.get()); }
/** * Constructor used to open already existing RRD backed * with a storage (backend) different from default. Constructor * obtains read or read/write access to this RRD. * * @param path Path to existing RRD. * @param readOnly Should be set to <code>false</code> if you want to update * the underlying RRD. If you want just to fetch data from the RRD file * (read-only access), specify <code>true</code>. If you try to update RRD file * open in read-only mode (<code>readOnly</code> set to <code>true</code>), * <code>IOException</code> will be thrown. * @param factory Backend factory which will be used for this RRD. * @throws FileNotFoundException Thrown if the requested file does not exist. * @ Thrown in case of general I/O error (bad RRD file, for example). * @see RrdBackendFactory */ public RrdDb(String path, bool readOnly, RrdBackendFactory factory) { if (!factory.exists(path)) { throw new System.IO.FileNotFoundException("Could not open " + path + " [non existent]"); } backend = factory.open(path, readOnly); try { // restore header header = new Header(this, (RrdDef)null); if (factory.shouldValidateHeader(path)) { header.validateHeader(); } // restore Datasources int dsCount = header.getDsCount(); Datasources = new Datasource[dsCount]; for (int i = 0; i < dsCount; i++) { Datasources[i] = new Datasource(this, null); } // restore archives int arcCount = header.getArcCount(); archives = new Archive[arcCount]; for (int i = 0; i < arcCount; i++) { archives[i] = new Archive(this, null); } } catch (IOException e) { backend.close(); log.ErrorFormat("RrdDb ctor failed on:{0} [{1]}", path, e.Message); throw e; } }
/** * Constructor used to create new RRD object from the definition object but with a storage * (backend) different from default. * * <p>Rrd4n uses <i>factories</i> to create RRD backend objecs. There are three different * backend factories supplied with Rrd4n, and each factory has its unique name:</p> * <p/> * <ul> * <li><b>FILE</b>: backends created from this factory will store RRD data to files by using * java.io.* classes and methods * <li><b>NIO</b>: backends created from this factory will store RRD data to files by using * java.nio.* classes and methods * <li><b>MEMORY</b>: backends created from this factory will store RRD data in memory. This might * be useful in runtime environments which prohibit disk utilization, or for storing temporary, * non-critical data (it gets lost as soon as JVM exits). * </ul> * <p/> * <p>For example, to create RRD in memory, use the following code</p> * <pre> * RrdBackendFactory factory = RrdBackendFactory.getFactory("MEMORY"); * RrdDb rrdDb = new RrdDb(rrdDef, factory); * rrdDb.close(); * </pre> * <p/> * <p>New RRD file structure is specified with an object of class * {@link RrdDef <b>RrdDef</b>}. The underlying RRD storage is created as soon * as the constructor returns.</p> * * @param rrdDef RRD definition object * @param factory The factory which will be used to create storage for this RRD * @Thrown in case of I/O error * @see RrdBackendFactory */ public RrdDb(RrdDef rrdDef, RrdBackendFactory factory) { if (!rrdDef.hasDatasources()) { throw new ArgumentException("No RRD Datasource specified. At least one is needed."); } if (!rrdDef.hasArchives()) { throw new ArgumentException("No RRD archive specified. At least one is needed."); } String path = rrdDef.getPath(); backend = factory.open(path, false); try { backend.setLength(rrdDef.getEstimatedSize()); // create header header = new Header(this, rrdDef); // create Datasources DsDef[] dsDefs = rrdDef.getDsDefs(); Datasources = new Datasource[dsDefs.Length]; for (int i = 0; i < dsDefs.Length; i++) { Datasources[i] = new Datasource(this, dsDefs[i]); } // create archives ArcDef[] arcDefs = rrdDef.getArcDefs(); archives = new Archive[arcDefs.Length]; for (int i = 0; i < arcDefs.Length; i++) { archives[i] = new Archive(this, arcDefs[i]); } } catch (IOException e) { backend.close(); throw; } }
/** * <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 * @Thrown in case of I/O related error */ public void dumpXml(StreamWriter destination) { XmlWriter writer = XmlWriter.Create(destination); writer.WriteStartDocument(); writer.WriteStartElement("rrd"); // dump header header.appendXml(writer); // dump Datasources foreach (Datasource Datasource in Datasources) { Datasource.appendXml(writer); } // dump archives foreach (Archive archive in archives) { archive.appendXml(writer); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); }
/** * Constructor used to open already existing RRD backed * with a storage (backend) different from default. Constructor * obtains read or read/write access to this RRD. * * @param path Path to existing RRD. * @param readOnly Should be set to <code>false</code> if you want to update * the underlying RRD. If you want just to fetch data from the RRD file * (read-only access), specify <code>true</code>. If you try to update RRD file * open in read-only mode (<code>readOnly</code> set to <code>true</code>), * <code>IOException</code> will be thrown. * @param factory Backend factory which will be used for this RRD. * @throws FileNotFoundException Thrown if the requested file does not exist. * @ Thrown in case of general I/O error (bad RRD file, for example). * @see RrdBackendFactory */ public RrdDb(String path, bool readOnly, RrdBackendFactory factory) { if (!factory.exists(path)) throw new System.IO.FileNotFoundException("Could not open " + path + " [non existent]"); backend = factory.open(path, readOnly); try { // restore header header = new Header(this, (RrdDef)null); if (factory.shouldValidateHeader(path)) { header.validateHeader(); } // restore Datasources int dsCount = header.getDsCount(); Datasources = new Datasource[dsCount]; for (int i = 0; i < dsCount; i++) { Datasources[i] = new Datasource(this, null); } // restore archives int arcCount = header.getArcCount(); archives = new Archive[arcCount]; for (int i = 0; i < arcCount; i++) { archives[i] = new Archive(this, null); } } catch (IOException e) { backend.close(); log.ErrorFormat("RrdDb ctor failed on:{0} [{1]}", path, e.Message); throw e; } }