Esempio n. 1
0
 public DataDef(String name, String path, String dsName, ConsolFun consolFunc, long step, long startTime, long endTime, string reduceName)
    : this(name, path, dsName, consolFunc, null)
 {
    StartTime = startTime;
    EndTime = endTime;
    // Step resolution must be at last 1 (every value)
    Step = Math.Max(1,step);
    ReduceCfName = reduceName;
 }
Esempio n. 2
0
 public Def(String name, String rrdPath, String dsName, ConsolFun consolFun, String backend)
    : base(name)
 {
    this.rrdPath = rrdPath;
    this.dsName = dsName;
    this.consolFun = consolFun;
    this.backend = backend;
    Step = long.MinValue;
    StartTime = long.MinValue;
    EndTime = long.MinValue;
    ReduceName = string.Empty;
 }
Esempio n. 3
0
 public DataDef(String name, String path, String dsName, ConsolFun consolFunc, String backend)
    : base(name)
 {
    this.path = path;
    this.dsName = dsName;
    consolFun = consolFunc;
    this.backend = backend;
    StartTime = long.MinValue;
    EndTime = long.MinValue;
    Step = long.MinValue;
    ReduceCfName = string.Empty;
 }
Esempio n. 4
0
        /**
         * <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>For the complete explanation of all archive definition parameters, see RRDTool's
         * <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a></p>
         *
         * @param consolFun Consolidation function. Allowed values are "AVERAGE", "MIN",
         *                  "MAX" and "LAST" (these string constants are conveniently defined in the
         *                  {@link ConsolFun} class).
         * @param xff       X-files factor, between 0 and 1.
         * @param steps     Number of archive steps.
         * @param rows      Number of archive rows.
         */
        public ArcDef(ConsolFun consolFun, double xff, int steps, int rows)
        {
            if (consolFun == null)
            {
                throw new ArgumentException("Null consolidation function specified");
            }
            if (Double.IsNaN(xff) || xff < 0.0 || xff >= 1.0)
            {
                throw new ArgumentException("Invalid xff, must be >= 0 and < 1: " + xff);
            }
            if (steps < 1 || rows < 2)
            {
                throw new ArgumentException("Invalid steps/rows settings: " + steps + "/" + rows +
                        ". Minimal values allowed are steps=1, rows=2");
            }

            this.consolFun = consolFun;
            this.Xff = xff;
            this.Steps = steps;
            this.Rows = rows;
        }
Esempio n. 5
0
   public FetchRequest(RrdDb parentDb, ConsolFun consolFun, long fetchStart, long fetchEnd, long resolution) {
        if (consolFun == null) {
            throw new ArgumentException("Null consolidation function in fetch request");
        }
        if (fetchStart < 0) {
            throw new ArgumentException("Invalid start time in fetch request: " + fetchStart);
        }
        if (fetchEnd < 0) {
            throw new ArgumentException("Invalid end time in fetch request: " + fetchEnd);
        }
        if (fetchStart > fetchEnd) {
            throw new ArgumentException("Invalid start/end time in fetch request: " + fetchStart +
                    " > " + fetchEnd);
        }
        if (resolution <= 0) {
            throw new ArgumentException("Invalid resolution in fetch request: " + resolution);
        }

		this.parentDb = parentDb;
		this.consolFun = consolFun;
		this.fetchStart = fetchStart;
		this.fetchEnd = fetchEnd;
		this.resolution = resolution;
	}
Esempio n. 6
0
 public Def(String name, String rrdPath, String dsName, ConsolFun consolFun)
    : this(name, rrdPath, dsName, consolFun, null)
 {
 }
Esempio n. 7
0
 private void accumulate(ArcState state, double value)
 {
    if (Double.IsNaN(value))
    {
       state.setNanSteps(state.getNanSteps() + 1);
    }
    else
    {
       ConsolFun cf = new ConsolFun(ConsolFun.ValueOf(consolFun.get()));
       switch (cf.CSType)
       {
          case ConsolFun.ConsolFunTypes.MIN:
             state.setAccumValue(Util.min(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.MAX:
             state.setAccumValue(Util.max(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.LAST:
             state.setAccumValue(value);
             break;
          case ConsolFun.ConsolFunTypes.AVERAGE:
             state.setAccumValue(Util.sum(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.TOTAL:
             state.setAccumValue(Util.sum(state.getAccumValue(), value));
             break;
       }
    }
 }
Esempio n. 8
0
      public ArcDef parseRra(String word)
      {
         // RRA:cfun:xff:steps:rows
         String[] tokens = word.Split(':');
         if (tokens.Length < 5) throw new ArgumentException("Invalid RRA definition: " + word);

         ConsolFun cf = new ConsolFun(tokens[1]);
         double xff;
         if (!double.TryParse(tokens[2], out xff))
            xff = double.NaN;
         int steps = int.Parse(tokens[3]);
         int rows = int.Parse(tokens[4]);

         return new ArcDef(cf, xff, steps, rows);
      }
Esempio n. 9
0
 public ArcDef findArchive(ConsolFun consolFun, int steps)
 {
     foreach (ArcDef arcDef in arcDefs)
     {
         if (arcDef.getConsolFun().Name.CompareTo(consolFun.Name) == 0 && arcDef.getSteps() == steps)
         {
             return arcDef;
         }
     }
     throw new ArgumentException("Could not find archive " + consolFun + "/" + steps);
 }
Esempio n. 10
0
 void removeArchive(ConsolFun consolFun, int steps)
 {
     ArcDef arcDef = findArchive(consolFun, steps);
     if (!arcDefs.Remove(arcDef))
     {
         throw new ArgumentException("Could not remove archive " + consolFun + "/" + steps);
     }
 }
Esempio n. 11
0
 public void addDatasource(String name, String file, String dsName, ConsolFun consolFunc, long step, long startTime, long endTime, string reduceName)
 {
    long defStartTime = startTime;
    if (defStartTime == long.MinValue)
       defStartTime = StartTime;
    long defEndTime = endTime;
    if (defEndTime == long.MinValue)
       defEndTime = EndTime;
    sources.Add(new DataDef(name, file, dsName, consolFunc, step, defStartTime, defEndTime, reduceName));
 }
Esempio n. 12
0
 public void SetConsulFunType(string consolFunName)
 {
    consolFun = new ConsolFun(consolFunName);
 }
Esempio n. 13
0
 public DataDef(String name, String path, String dsName, ConsolFun consolFunc)
    : this(name, path, dsName, consolFunc, null)
 {
 }
Esempio n. 14
0
 /**
  * <p>Prepares fetch request to be executed on this RRD. Use returned
  * <code>FetchRequest</code> object and its {@link FetchRequest#fetchData() fetchData()}
  * method to actually fetch data from this RRD. Data will be fetched with the smallest
  * possible resolution (see RRDTool's
  * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a>
  * for the explanation of the resolution parameter).</p>
  *
  * @param consolFun  Consolidation function to be used in fetch request. Allowed values are
  *                   AVERAGE, MIN, MAX and LAST (see {@link ConsolFun} enum).
  * @param fetchStart Starting timestamp for fetch request.
  * @param fetchEnd   Ending timestamp for fetch request.
  * @return Request object that should be used to actually fetch data from RRD.
  */
 public FetchRequest createFetchRequest(ConsolFun consolFun, long fetchStart, long fetchEnd)
 {
    return createFetchRequest(consolFun, fetchStart, fetchEnd, 1);
 }
Esempio n. 15
0
 /**
  * <p>Prepares fetch request to be executed on this RRD. Use returned
  * <code>FetchRequest</code> object and its {@link FetchRequest#fetchData() fetchData()}
  * method to actually fetch data from the RRD file.</p>
  *
  * @param consolFun  Consolidation function to be used in fetch request. Allowed values are
  *                   "AVERAGE", "MIN", "MAX" and "LAST" (these constants are conveniently defined in the
  *                   {@link ConsolFun} class).
  * @param fetchStart Starting timestamp for fetch request.
  * @param fetchEnd   Ending timestamp for fetch request.
  * @param resolution Fetch resolution (see RRDTool's
  *                   <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> for an
  *                   explanation of this parameter.
  * @return Request object that should be used to actually fetch data from RRD
  */
 public FetchRequest createFetchRequest(ConsolFun consolFun, long fetchStart, long fetchEnd, long resolution)
 {
    return new FetchRequest(this.getPath(), consolFun.Name, Util.getDate(fetchStart), Util.getDate(fetchEnd), resolution);
 }
Esempio n. 16
0
 /**
  * Returns Archive object with the given consolidation function and the number
  * of steps.
  *
  * @param consolFun Consolidation function
  * @param steps     Number of archive steps
  * @return Requested Archive object or null if no such archive could be found
  * @Thrown in case of I/O error
  */
 public Archive getArchive(ConsolFun consolFun, int steps)
 {
    try
    {
       return getArchive(getArcIndex(consolFun, steps));
    }
    catch (ArgumentException)
    {
       return null;
    }
 }
Esempio n. 17
0
 /**
  * Returns index of Archive object with the given consolidation function and the number
  * of steps. Exception is thrown if such archive could not be found.
  *
  * @param consolFun Consolidation function
  * @param steps     Number of archive steps
  * @return Requested Archive object
  * @Thrown in case of I/O error
  */
 public int getArcIndex(ConsolFun consolFun, int steps)
 {
    for (int i = 0; i < archives.Length; i++)
    {
       if (archives[i].getConsolFun().Name.CompareTo(consolFun.Name) == 0 && archives[i].getSteps() == steps)
       {
          return i;
       }
    }
    throw new ArgumentException("Could not find archive " + consolFun + "/" + steps);
 }
Esempio n. 18
0
 /**
  * Defines virtual datasource. This datasource can then be used
  * in other methods like {@link #datasource(String, String)} or
  * {@link #gprint(String, ConsolFun, 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, ConsolFun consolFun, String backend)
 {
    sources.Add(new Def(name, rrdPath, dsName, consolFun, backend));
 }
Esempio n. 19
0
 /**
  * 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>
  * @param consolFun Consolidation function.
  * @param xff X-files factor. Valid values are between 0 and 1.
  * @param steps Number of archive steps
  * @param rows Number of archive rows
  * @throws ArgumentException Thrown if archive with the same consolidation function
  * and the same number of steps is already added.
  */
 public void addArchive(ConsolFun consolFun, double xff, int steps, int rows)
 {
     addArchive(new ArcDef(consolFun, xff, steps, rows));
 }
Esempio n. 20
0
        /**
         * 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>
         * <pre>
         * RRA:consolidationFunction:XFilesFactor:steps:rows
         * </pre>
         * For example:</p>
         * <pre>
         * RRA:AVERAGE:0.5:10:1000
         * </pre>
         * For more information on archive definition parameters see <code>rrdcreate</code>
         * man page.<p>
         * @param rrdToolArcDef Archive definition string with the syntax borrowed from RRDTool.
         * @throws ArgumentException Thrown if invalid string is supplied.
         */
        public void addArchive(String rrdToolArcDef)
        {

            String[] tokens = rrdToolArcDef.Split(':');
            if (tokens.Length != 5)
                throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef);

            if (tokens[0].ToUpper().CompareTo("RRA") != 0)
                throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef);

            ConsolFun consolFun = new ConsolFun(ConsolFun.ValueOf(tokens[1]));
            double xff;
            try
            {
                xff = Double.Parse(tokens[2]);
            }
            catch (FormatException nfe)
            {
                throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe);
            }
            int steps;
            try
            {
                steps = int.Parse(tokens[3]);
            }
            catch (FormatException nfe)
            {
                throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe);
            }
            int rows;
            try
            {
                rows = int.Parse(tokens[4]);
            }
            catch (FormatException nfe)
            {
                throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe);
            }
            addArchive(new ArcDef(consolFun, xff, steps, rows));
        }
Esempio n. 21
0
 /**
  * <p>Adds simple source (<b>DEF</b>). Source <code>name</code> can be used:</p>
  * <ul>
  * <li>To specify sources for line, area and stack plots.</li>
  * <li>To define complex sources
  * </ul>
  *
  * @param name       Source name.
  * @param file       Path to RRD file.
  * @param dsName     Data source name defined in the RRD file.
  * @param consolFunc Consolidation function that will be used to extract data from the RRD
  *                   file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
  *                   in the {@link org.Rrd4n.ConsolFun ConsolFun} class).
  * @param backend    Name of the RrdBackendFactory that should be used for this RrdDb.
  */
 public void addDatasource(String name, String file, String dsName, ConsolFun consolFunc, String backend)
 {
    sources.Add(new DataDef(name, file, dsName, consolFunc, backend));
 }
Esempio n. 22
0
 public FetchRequest(RrdDb parentDb, ConsolFun consolFun, DateTime fetchStart, DateTime fetchEnd, long resolution)
    : this(parentDb,consolFun,Util.getTimestamp(fetchStart),Util.getTimestamp(fetchEnd),resolution)
 {
 }