Beispiel #1
0
		// state variables

		internal DataSource(RrdDb parentDb, DsDef dsDef)
		{
			bool shouldInitialize = dsDef != null;
			this.parentDb = parentDb;
			dsName = new RrdString(this);
			dsType = new RrdString(this);
			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.Name);
				primitiveDsName = null;
				dsType.Set(dsDef.Type.ToString());
				primitiveDsType = null;
				heartbeat.Set(dsDef.Heartbeat);
				minValue.Set(dsDef.MinValue);
				maxValue.Set(dsDef.MaxValue);
				lastValue.Set(Double.NaN);
				accumValue.Set(0.0);
				Header header = parentDb.Header;
				nanSeconds.Set(header.LastUpdateTime%header.Step);
			}
		}
Beispiel #2
0
		/// <summary>
		/// Creates a new RRD file with one more datasource in it. RRD file is created based on the
		/// existing one (the original RRD file is not modified at all). All data from
		/// the original RRD file is copied to the new one.
		/// </summary>
		/// <param name="sourcePath">path to a RRD file to import data from (will not be modified)</param>
		/// <param name="destPath">path to a new RRD file (will be created)</param>
		/// <param name="newDatasource">Datasource definition to be added to the new RRD file</param>
		public static void AddDatasource(String sourcePath, String destPath, DsDef newDatasource)
		{
			if (Util.SameFilePath(sourcePath, destPath))
			{
				throw new RrdException("Source and destination paths are the same");
			}
			using (RrdDb rrdSource = RrdDb.Open(sourcePath, true))
			{
				RrdDef rrdDef = rrdSource.GetRrdDef();
				rrdDef.Path = destPath;
				rrdDef.AddDatasource(newDatasource);
				using (RrdDb rrdDest = RrdDb.Create(rrdDef))
				{
					rrdSource.CopyStateTo(rrdDest);
				}
			}
		}
Beispiel #3
0
		/// <summary>
		/// Adds single datasource definition represented with object of class <code>DsDef</code>.
		/// </summary>
		/// <param name="dsDef">Datasource definition.</param>
		public void AddDatasource(DsDef dsDef)
		{
			if (dsDefs.Contains(dsDef))
			{
				throw new RrdException("Datasource already defined: " + dsDef.Dump());
			}
			dsDefs.Add(dsDef);
		}
Beispiel #4
0
		/// <summary>
		///  <p>Adds one more datasource to a RRD file.</p>
		///  <p>WARNING: This method is potentialy dangerous! It will modify your RRD file.
		///  It is highly recommended to preserve the original RRD file (<i>saveBackup</i>
		///  should be set to <code>true</code>). The backup file will be created in the same
		///  directory as the original one with <code>.bak</code> extension added to the
		///  original name.</p>
		///  <p>Before applying this method, be sure that the specified RRD file is not in use
		///  (not open)</p>
		/// </summary>
		/// <param name="sourcePath">path to a RRD file to add datasource to.</param>
		/// <param name="newDatasource">Datasource definition to be added to the RRD file</param>
		/// <param name="saveBackup">true, if backup of the original file should be created; false, otherwise</param>
		public static void AddDatasource(String sourcePath, DsDef newDatasource, bool saveBackup)
		{
			String destPath = Util.GetTmpFilename();
			AddDatasource(sourcePath, destPath, newDatasource);
			CopyFile(destPath, sourcePath, saveBackup);
		}
Beispiel #5
0
		internal bool ExactlyEqual(DsDef def)
		{
			return Name == def.Name && Type == def.Type &&
			       Heartbeat == def.Heartbeat && MinValue == def.MinValue &&
			       MaxValue == def.MaxValue;
		}