Beispiel #1
0
		/// <summary>
		/// Adds single archive to RRD definition from a RRDTool-like
		/// archive definition string. The string must have five elements separated with colons
		/// (:) in the following order:<p>
		/// <code>
		/// RRA:consolidationFunction:XFilesFactor:steps:rows
		/// </code>
		/// For example:</p>
		/// <code>
		/// RRA:AVERAGE:0.5:10:1000
		/// </code>
		/// For more information on archive definition parameters see <code>rrdcreate</code>
		/// man page.
		/// </summary>
		/// <param name="rrdToolArcDef">Archive definition string with the syntax borrowed from RRDTool.</param>
		public static ArcDef FromRrdToolString(String rrdToolArcDef)
		{
			var rrdException = new RrdException("Wrong rrdtool-like archive definition: " + rrdToolArcDef);
			String[] tokens = rrdToolArcDef.Split(':');
			if (tokens.Length != 5)
				throw rrdException;
			if (!tokens[0].Equals("RRA", StringComparison.InvariantCultureIgnoreCase))
			{
				throw rrdException;
			}
			ConsolidationFunction consolFun;
			if (!Enum.TryParse(tokens[1], true, out consolFun))
				throw rrdException;

			double xff = Util.ParseDouble(tokens[2]);
			if(double.IsNaN(xff))
			{
				throw rrdException;
			}
			int steps;
			if (!int.TryParse(tokens[3], out steps))
			{
				throw rrdException;
			}
			int rows;
			if (!int.TryParse(tokens[4], out rows))
			{
				throw rrdException;
			}
			return new ArcDef(consolFun, xff, steps, rows);
		}
Beispiel #2
0
		/// <summary>
		/// Create a DsDef from a RRDTool-like datasource definition string. The string must have six elements separated with colons
		/// (:) in the following order:<p>
		/// <code>
		/// DS:name:type:heartbeat:minValue:maxValue
		/// </code>
		/// For example:</p>
		/// <code>
		/// DS:input:COUNTER:600:0:U
		/// </code>
		/// For more information on datasource definition parameters see <code>rrdcreate</code>
		/// man page.
		/// </summary>
		/// <param name="rrdToolDataSourceDefinition"></param>
		public static DsDef FromRrdToolString(string rrdToolDataSourceDefinition)
		{
			var rrdException = new RrdException("Wrong rrdtool-like datasource definition: " + rrdToolDataSourceDefinition);

			string[] tokens = rrdToolDataSourceDefinition.Split(':');
			if (tokens.Length != 6)
			{
				throw rrdException;
			}

			if (!tokens[0].Equals("DS", StringComparison.InvariantCultureIgnoreCase))
			{
				throw rrdException;
			}
			String dsName = tokens[1];
			DataSourceType dsType;
			if (!Enum.TryParse(tokens[2], true, out dsType))
				throw new RrdException("Invalid DataSource Type");

			long dsHeartbeat;
			if (!long.TryParse(tokens[3], out dsHeartbeat))
			{
				throw rrdException;
			}
			double minValue = Double.NaN;
			if (!tokens[4].Equals("U", StringComparison.InvariantCultureIgnoreCase))
			{
				minValue = Util.ParseDouble(tokens[4]);
				if(double.IsNaN(minValue))
					throw rrdException;
			}
			double maxValue = Double.NaN;
			if (!tokens[5].Equals("U", StringComparison.InvariantCultureIgnoreCase))
			{
				maxValue = Util.ParseDouble(tokens[5]);
				if (double.IsNaN(maxValue))
					throw rrdException;
			}
			return  new DsDef(dsName,dsType,dsHeartbeat,minValue,maxValue);
		}