Example #1
0
 public DataSource(string name, DsType type, double min, double max)
 {
     Name = name;
     Type = type;
     Min  = min;
     Max  = max;
 }
Example #2
0
 public DataSource(string name, DsType type, double min, double max)
 {
     Name = name;
     Type = type;
     Min = min;
     Max = max;
 }
Example #3
0
        /**
         * <p>Creates new data source definition object. This object should be passed as argument
         * to {@link RrdDef#addDatasource(DsDef) addDatasource()}
         * method of {@link RrdDb RrdDb} object.</p>
         * <p/>
         * <p>For the complete explanation of all source definition parameters, see RRDTool's
         * <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a></p>
         * <p/>
         * <p><b>IMPORTANT NOTE:</b> If datasource name ends with '!', corresponding archives will never
         * store NaNs as datasource values. In that case, NaN datasource values will be silently
         * replaced with zeros by the framework.</p>
         *
         * @param dsName    Data source name.
         * @param dsType    Data source type. Valid values are "COUNTER", "GAUGE", "DERIVE"
         *                  and "ABSOLUTE" (these string constants are conveniently defined in the
         *                  {@link org.Rrd4n.DsType} class).
         * @param heartbeat Hearbeat
         * @param minValue  Minimal value. Use <code>Double.NaN</code> if unknown.
         * @param maxValue  Maximal value. Use <code>Double.NaN</code> if unknown.
         */
        public DsDef(String dsName, DsType dsType, long heartbeat, double minValue, double maxValue)
        {
            if (dsName == null)
            {
                throw new ArgumentException("Null datasource name specified");
            }
            if (dsName.Length == 0)
            {
                throw new ArgumentException("Datasource name length equal to zero");
            }
            if (dsName.Length > RrdPrimitive.STRING_LENGTH)
            {
                throw new ArgumentException("Datasource name [" + dsName + "] to long (" +
                                            dsName.Length + " chars found, only " + RrdPrimitive.STRING_LENGTH + " allowed");
            }
            if (dsType == null)
            {
                throw new ArgumentException("Null datasource type specified");
            }
            if (heartbeat <= 0)
            {
                throw new ArgumentException("Invalid heartbeat, must be positive: " + heartbeat);
            }
            if (!Double.IsNaN(minValue) && !Double.IsNaN(maxValue) && minValue >= maxValue)
            {
                throw new ArgumentException("Invalid min/max values specified: " +
                                            minValue + "/" + maxValue);
            }

            this.DsName    = dsName;
            this.dsType    = dsType;
            this.heartbeat = heartbeat;
            this.minValue  = minValue;
            this.maxValue  = maxValue;
        }
Example #4
0
        /**
         * Adds single datasource to RRD definition from a RRDTool-like
         * datasource definition string. The string must have six elements separated with colons
         * (:) in the following order:<p>
         * <pre>
         * DS:name:type:heartbeat:minValue:maxValue
         * </pre>
         * For example:</p>
         * <pre>
         * DS:input:COUNTER:600:0:U
         * </pre>
         * For more information on datasource definition parameters see <code>rrdcreate</code>
         * man page.<p>
         * @param rrdToolDsDef Datasource definition string with the syntax borrowed from RRDTool.
         * @throws ArgumentException Thrown if invalid string is supplied.
         */
        public void addDatasource(String rrdToolDsDef)
        {
            String[] tokens = rrdToolDsDef.Split(':');
            if (tokens.Length != 6)
            {
                throw new ArgumentException("Wrong rrdtool-like datasource definition: " + rrdToolDsDef + ". Wrong number of elements");
            }

            if (tokens[0].ToUpper().CompareTo("DS") != 0)
            {
                throw new ArgumentException("Wrong rrdtool-like datasource definition: " + rrdToolDsDef + ". No data source");
            }
            String dsName = tokens[1];
            DsType dsType = new DsType(DsType.ValueOf(tokens[2]));
            long   dsHeartbeat;

            try
            {
                dsHeartbeat = long.Parse(tokens[3]);
            }
            catch (FormatException nfe)
            {
                throw new ArgumentException("Wrong rrdtool-like datasource definition: " + rrdToolDsDef, nfe);
            }
            double minValue = Double.NaN;

            if (tokens[4].ToUpper().CompareTo("U") != 0)
            {
                try
                {
                    minValue = Double.Parse(tokens[4]);
                }
                catch (FormatException nfe)
                {
                    throw new ArgumentException("Wrong rrdtool-like datasource definition: " + rrdToolDsDef, nfe);
                }
            }
            double maxValue = Double.NaN;

            if (tokens[5].ToUpper().CompareTo("U") != 0)
            {
                try
                {
                    maxValue = Double.Parse(tokens[5]);
                }
                catch (FormatException nfe)
                {
                    throw new ArgumentException("Wrong rrdtool-like datasource definition: " + rrdToolDsDef, nfe);
                }
            }
            addDatasource(new DsDef(dsName, dsType, dsHeartbeat, minValue, maxValue));
        }
Example #5
0
        public DsDef parseDef(String word)
        {
            // DEF:name:type:heratbeat:min:max
            String[] tokens = word.Split(':');
            if (tokens.Length < 6)
            {
                throw new ArgumentException("Invalid DS definition: " + word);
            }

            String dsName = tokens[1];
            DsType dsType = new DsType(tokens[2]);

            long     heartbeat;
            TimeSpan heartbeatSpan;

            if (!long.TryParse(tokens[3], out heartbeat))
            {
                heartbeatSpan = TimeSpan.Parse(tokens[3]);
                heartbeat     = (long)heartbeatSpan.TotalSeconds;
            }

            double min;

            if (!double.TryParse(tokens[4], out min))
            {
                min = double.NaN;
            }

            double max;

            if (!double.TryParse(tokens[5], out max))
            {
                max = double.NaN;
            }

            return(new DsDef(dsName, dsType, heartbeat, min, max));
        }
Example #6
0
 /**
  * <p>Adds single datasource to RRD definition by specifying its data source name, source type,
  * heartbeat, minimal and maximal value. For the complete explanation of all data
  * source definition parameters see RRDTool's
  * <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a>.</p>
  *
  * <p><b>IMPORTANT NOTE:</b> If datasource name ends with '!', corresponding archives will never
  * store NaNs as datasource values. In that case, NaN datasource values will be silently
  * replaced with zeros by the framework.</p>
  *
  * @param dsName Data source name.
  * @param dsType Data source type. Valid types are "COUNTER",
  * "GAUGE", "DERIVE" and "ABSOLUTE" (these string constants are conveniently defined in
  * the {@link DsType} class).
  * @param heartbeat Data source heartbeat.
  * @param minValue Minimal acceptable value. Use <code>Double.NaN</code> if unknown.
  * @param maxValue Maximal acceptable value. Use <code>Double.NaN</code> if unknown.
  * @throws ArgumentException Thrown if new datasource definition uses already used data
  * source name.
  */
 public void addDatasource(String dsName, DsType dsType, long heartbeat, double minValue, double maxValue)
 {
     addDatasource(new DsDef(dsName, dsType, heartbeat, minValue, maxValue));
 }