Ejemplo n.º 1
0
		/// <summary>
		/// <p>Creates new archive definition object. This object should be passed as argument to
		/// {@link RrdDef#AddArchive(ArcDef) AddArchive()} method of
		/// {@link RrdDb RrdDb} object.</p>
		/// <p/>
		/// <p>For the complete explanation of all archive definition parameters, see RRDTool's
		/// <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a></p>
		/// </summary>
		/// <param name="consolFun">
		/// Consolidation function. Allowed values are "AVERAGE", "MIN",
		/// "MAX" and "LAST" (these string constants are conveniently defined in the
		/// {@link ConsolFuns} class).
		/// </param>
		/// <param name="xff">X-files factor, between 0 and 1.</param>
		/// <param name="steps">Number of archive steps.</param>
		/// <param name="rows">Number of archive rows</param>
		public ArcDef(ConsolidationFunction consolFun, double xff, int steps, int rows)
		{
			ConsolFun = consolFun;
			Xff = xff;
			Steps = steps;
			Rows = rows;
			Validate();
		}
 // Overrides the GetGrandTotalName method
 public override string GetGrandTotalName(ConsolidationFunction functionType)
 {
     // Checks the function type used to add the subtotals
     switch (functionType)
     {
         // Returns custom value based on the function type used to add the subtotals
         case ConsolidationFunction.Average:
             return "GRD AVG";
         // Handle other cases as per requirement
         default:
             return base.GetGrandTotalName(functionType);
     }
 }
        // Overrides the GetGrandTotalName method
        public override string GetGrandTotalName(ConsolidationFunction functionType)
        {
            // Checks the function type used to add the subtotals
            switch (functionType)
            {
            // Returns custom value based on the function type used to add the subtotals
            case ConsolidationFunction.Average:
                return("GRD AVG");

            // Handle other cases as per requirement
            default:
                return(base.GetGrandTotalName(functionType));
            }
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Returns single aggregated value for the give consolidation function
		/// </summary>
		/// <param name="consolFun">Consolidation Function</param>
		/// <returns>aggregated value</returns>
		public double GetAggregate(ConsolidationFunction consolFun)
		{
			switch (consolFun)
			{
				case ConsolidationFunction.AVERAGE:
					return Average;
				case ConsolidationFunction.MIN:
					return Min;
				case ConsolidationFunction.MAX:
					return Max;
				case ConsolidationFunction.LAST:
					return Last;
				case ConsolidationFunction.FIRST:
					return First;
				case ConsolidationFunction.TOTAL:
					return Total;
				default:
					throw new ArgumentOutOfRangeException("consolFun");
			}
		}
Ejemplo n.º 5
0
	public Def(String name, String rrdPath, String dsName, ConsolidationFunction consolFun):this(name, rrdPath, dsName, consolFun, null) {
		
	}
Ejemplo n.º 6
0
		/// <summary>
		/// Checks if function argument represents valid consolidation function name.
		/// </summary>
		/// <param name="consolFun">Consolidation function name</param>
		/// <returns></returns>
		public static bool ValidConsolFun(ConsolidationFunction consolFun)
		{
			return CONSOL_FUNS.Any(cFun => cFun == consolFun);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Returns single aggregated value from the fetched data for a single datasource.
		/// </summary>
		/// <param name="dsName">Datasource name</param>
		/// <param name="consolFun">Consolidation function to be applied to fetched datasource values.</param>
		/// <returns>
		/// MIN, MAX, LAST, FIRST, AVERAGE or TOTAL value calculated from the fetched data
		/// for the given datasource name
		/// </returns>
		public double GetAggregate(String dsName, ConsolidationFunction consolFun)
		{
			DataProcessor dp = CreateDataProcessor(null);
			return dp.GetAggregate(dsName, consolFun);
		}
Ejemplo n.º 8
0
	public PrintText(String srcName, ConsolidationFunction consolFun, String text, bool includedInGraph):base(text) {
		this.srcName = srcName;
		this.consolFun = consolFun;
		this.includedInGraph = includedInGraph;
	}
Ejemplo n.º 9
0
	/**
	 * Creates a new (static) virtual datasource. The value of the datasource is constant. This value is
	 * evaluated by applying the given consolidation function to another virtual datasource.
	 *
	 * @param name	  Source name
	 * @param defName   Other source name
	 * @param consolFun Consolidation function to be applied to other datasource.
	 */
	public void datasource(String name, String defName, ConsolidationFunction consolFun) {
		sources.Add(new SDef(name, defName, consolFun));
	}
Ejemplo n.º 10
0
		/**
	 * Creates new RRD file based on the existing one, but with a different
	 * size (number of rows) for a single archive. The archive to be resized
	 * is identified by its consolidation function and the number of steps.
	 *
	 * @param sourcePath Path to the source RRD file (will not be modified)
	 * @param destPath   Path to the new RRD file (will be created)
	 * @param consolFun  Consolidation function of the archive to be resized
	 * @param numSteps   Number of steps of the archive to be resized
	 * @param newRows	New archive size (number of archive rows)
	 * @throws IOException  Thrown in case of I/O error
	 * @throws RrdException Thrown in case of JRobin specific error
	 */

		public static void ResizeArchive(String sourcePath, String destPath, ConsolidationFunction consolFun,
		                                 int numSteps, int newRows)
		{
			if (Util.SameFilePath(sourcePath, destPath))
			{
				throw new RrdException("Source and destination paths are the same");
			}
			if (newRows < 2)
			{
				throw new RrdException("New arcihve size must be at least 2");
			}
			using (RrdDb rrdSource = RrdDb.Open(sourcePath))
			{
				RrdDef rrdDef = rrdSource.GetRrdDef();
				ArcDef arcDef = rrdDef.FindArchive(consolFun, numSteps);
				if (arcDef.Rows != newRows)
				{
					arcDef.Rows = newRows;
					rrdDef.Path = destPath;
					using (RrdDb rrdDest = RrdDb.Create(rrdDef))
					{
						rrdSource.CopyStateTo(rrdDest);
					}
				}
			}
		}
Ejemplo n.º 11
0
		/// <summary>
		/// Sets single archive's X-files factor to a new value.
		/// </summary>
		/// <param name="sourcePath">Path to existing RRD file (will be updated)</param>
		/// <param name="consolFun">Consolidation function of the target archive</param>
		/// <param name="steps">Number of steps of the target archive</param>
		/// <param name="newXff">New X-files factor for the target archive</param>
		public static void SetArcXff(String sourcePath, ConsolidationFunction consolFun, int steps,
		                             double newXff)
		{
			using (RrdDb rrd = RrdDb.Open(sourcePath))
			{
				Archive arc = rrd.GetArchive(consolFun, steps);
				arc.Xff = newXff;
			}
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Creates a new RRD file with one archive removed. RRD file is created based on the
		/// existing one (the original RRD file is not modified at all). All relevant 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="consolFun">Consolidation function of Archive which should be removed</param>
		/// <param name="steps">Number of steps for Archive which should be removed</param>
		public static void RemoveArchive(String sourcePath, String destPath, ConsolidationFunction consolFun, int steps)
		{
			if (Util.SameFilePath(sourcePath, destPath))
			{
				throw new RrdException("Source and destination paths are the same");
			}
			using (RrdDb rrdSource = RrdDb.Open(sourcePath))
			{
				RrdDef rrdDef = rrdSource.GetRrdDef();
				rrdDef.Path = destPath;
				rrdDef.RemoveArchive(consolFun, steps);
				using (RrdDb rrdDest = RrdDb.Create(rrdDef))
				{
					rrdSource.CopyStateTo(rrdDest);
				}
			}
		}
Ejemplo n.º 13
0
	public SDef(String name, String defName, ConsolidationFunction consolFun):base(name) {
		this.defName = defName;
		this.consolFun = consolFun;
	}
Ejemplo n.º 14
0
		/// <summary>
		/// Returns aggregated value for a set of values calculated by applying an RPN expression to the
		/// fetched data. For example, if you have two datasources named <code>x</code> and <code>y</code>
		/// in this FetchData and you want to calculate MAX value of <code>(x+y)/2</code>code> use something like:
		/// <code>getRpnAggregate("x,y,+,2,/", "MAX");</code>
		/// </summary>
		/// <param name="rpnExpression">RRDTool-like RPN expression</param>
		/// <param name="consolFun">Consolidation function (MIN, MAX, LAST, FIRST, AVERAGE or TOTAL)</param>
		/// <returns></returns>
		public double GetRpnAggregate(String rpnExpression, ConsolidationFunction consolFun)
		{
			DataProcessor dataProcessor = CreateDataProcessor(rpnExpression);
			return dataProcessor.GetAggregate(RPN_SOURCE_NAME, consolFun);
		}
Ejemplo n.º 15
0
		public double GetAggregate(String dsName, ConsolidationFunction consolFun, String rpnExpression)
		{
			// for backward compatibility
			rpnExpression = rpnExpression.Replace("value", dsName);
			return GetRpnAggregate(rpnExpression, consolFun);
		}
Ejemplo n.º 16
0
	public Def(String name, String rrdPath, String dsName, ConsolidationFunction consolFun, String backend):base(name) {
		this.rrdPath = rrdPath;
		this.dsName = dsName;
		this.consolFun = consolFun;
		this.backend = backend;
	}
Ejemplo n.º 17
0
	/**
	 * Defines virtual datasource. This datasource can then be used
	 * in other methods like {@link #datasource(String, String)} or
	 * {@link #gprint(String, String, String)}.
	 *
	 * @param name	  Source name
	 * @param rrdPath   Path to RRD file
	 * @param dsName	Datasource name in the specified RRD file
	 * @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
	 * @param backend   Backend to be used while fetching data from a RRD file.
	 */
	public void datasource(String name, String rrdPath, String dsName, ConsolidationFunction consolFun, String backend) {
		sources.Add(new Def(name, rrdPath, dsName, consolFun, backend));
	}
Ejemplo n.º 18
0
		/// <summary>
		/// Modifies existing RRD file, by resizing its chosen archive. The archive to be resized
		/// is identified by its consolidation function and the number of steps.
		/// </summary>
		/// <param name="sourcePath">Path to the RRD file (will be modified)</param>
		/// <param name="consolFun">Consolidation function of the archive to be resized</param>
		/// <param name="numSteps">Number of steps of the archive to be resized</param>
		/// <param name="newRows">New archive size (number of archive rows)</param>
		/// <param name="saveBackup">true, if backup of the original file should be created;false, otherwise</param>
		public static void ResizeArchive(String sourcePath, ConsolidationFunction consolFun,
		                                 int numSteps, int newRows, bool saveBackup)
		{
			String destPath = Util.GetTmpFilename();
			ResizeArchive(sourcePath, destPath, consolFun, numSteps, newRows);
			CopyFile(destPath, sourcePath, saveBackup);
		}
Ejemplo n.º 19
0
	/**
	 * This method does basically the same thing as {@link #print(String, String, String)},
	 * but the result is printed on the graph itself, below the chart area.
	 *
	 * @param srcName   Virtual source name
	 * @param consolFun Consolidation function to be applied to the source
	 * @param format	Format string (like "average = %10.3f %s")
	 */
	public void gprint(String srcName, ConsolidationFunction consolFun, String format) {
		comments.Add(new PrintText(srcName, consolFun, format, true));
	}
Ejemplo n.º 20
0
		/// <summary>
		/// Adds single archive definition by specifying its consolidation function, X-files factor,
		/// number of steps and rows. For the complete explanation of all archive
		/// definition parameters see RRDTool's
		/// <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a>.</p>
		/// </summary>
		/// <param name="consolFun">Consolidation function. </param>
		/// <param name="xff"> X-files factor. Valid values are between 0 and 1.</param>
		/// <param name="steps">Number of archive steps</param>
		/// <param name="rows">Number of archive rows</param>
		public void AddArchive(ConsolidationFunction consolFun, double xff, int steps, int rows)
		{
			AddArchive(new ArcDef(consolFun, xff, steps, rows));
		}
Ejemplo n.º 21
0
		public void RemoveArchive(ConsolidationFunction consolFun, int steps)
		{
			ArcDef arcDef = FindArchive(consolFun, steps);
			if (!arcDefs.Remove(arcDef))
			{
				throw new RrdException("Could not remove archive " + consolFun + "/" + steps);
			}
		}
Ejemplo n.º 22
0
		internal ArcDef FindArchive(ConsolidationFunction consolFun, int steps)
		{
			ArcDef result = arcDefs.SingleOrDefault(x => x.ConsolFun == consolFun  && x.Steps == steps);
			if(result !=null)
				return result;
			throw new RrdException("Could not find archive " + consolFun + "/" + steps);
		}
Ejemplo n.º 23
0
 // This function will return the grand total name
 public override String GetGrandTotalName(ConsolidationFunction functionType)
 {
     return("Chinese Grand Total - 可能的用法");
 }
 // This function will return the grand total name
 public override String GetGrandTotalName(ConsolidationFunction functionType)
 {
     return "Chinese Grand Total - 可能的用法";
 }