Beispiel #1
0
 public Archive(RrdDb parentDb, ArcDef arcDef)
 {
    bool shouldInitialize = arcDef != null;
    this.parentDb = parentDb;
    consolFun = new RrdString(this, true);  // constant, may be cached
    xff = new RrdDouble(this);
    steps = new RrdInt(this, true);            // constant, may be cached
    rows = new RrdInt(this, true);            // constant, may be cached
    if (shouldInitialize)
    {
       consolFun.set(arcDef.getConsolFun().Name);
       xff.set(arcDef.getXff());
       steps.set(arcDef.getSteps());
       rows.set(arcDef.getRows());
    }
    int n = parentDb.getHeader().getDsCount();
    states = new ArcState[n];
    robins = new Robin[n];
    for (int i = 0; i < n; i++)
    {
       states[i] = new ArcState(this, shouldInitialize);
       int numRows = rows.get();
       robins[i] = new Robin(this, numRows, shouldInitialize);
    }
 }
Beispiel #2
0
 /**
  * <p>Returns RRD definition object which can be used to create new RRD
  * with the same creation parameters but with no data in it.</p>
  * <p/>
  * <p>Example:</p>
  * <p/>
  * <pre>
  * RrdDb rrd1 = new RrdDb("original.rrd");
  * RrdDef def = rrd1.getRrdDef();
  * // fix path
  * def.setPath("empty_copy.rrd");
  * // create new RRD file
  * RrdDb rrd2 = new RrdDb(def);
  * </pre>
  *
  * @return RRD definition.
  */
 public RrdDef getRrdDef()
 {
     lock (sync)
     {
         // set header
         long   startTime = header.getLastUpdateTime();
         long   step      = header.getStep();
         String path      = backend.getPath();
         RrdDef rrdDef    = new RrdDef(path, startTime, step);
         // add Datasources
         foreach (Datasource Datasource in Datasources)
         {
             DsDef dsDef = new DsDef(Datasource.DsName,
                                     Datasource.DsType, Datasource.Heartbeat,
                                     Datasource.MinValue, Datasource.MaxValue);
             rrdDef.addDatasource(dsDef);
         }
         // add archives
         foreach (Archive archive in archives)
         {
             ArcDef arcDef = new ArcDef(archive.getConsolFun(),
                                        archive.getXff(), archive.getSteps(), archive.getRows());
             rrdDef.addArchive(arcDef);
         }
         return(rrdDef);
     }
 }
Beispiel #3
0
        public Archive(RrdDb parentDb, ArcDef arcDef)
        {
            bool shouldInitialize = arcDef != null;

            this.parentDb = parentDb;
            consolFun     = new RrdString(this, true); // constant, may be cached
            xff           = new RrdDouble(this);
            steps         = new RrdInt(this, true);    // constant, may be cached
            rows          = new RrdInt(this, true);    // constant, may be cached
            if (shouldInitialize)
            {
                consolFun.set(arcDef.getConsolFun().Name);
                xff.set(arcDef.getXff());
                steps.set(arcDef.getSteps());
                rows.set(arcDef.getRows());
            }
            int n = parentDb.getHeader().getDsCount();

            states = new ArcState[n];
            robins = new Robin[n];
            for (int i = 0; i < n; i++)
            {
                states[i] = new ArcState(this, shouldInitialize);
                int numRows = rows.get();
                robins[i] = new Robin(this, numRows, shouldInitialize);
            }
        }
Beispiel #4
0
 /**
  * Adds single archive definition represented with object of class <code>ArcDef</code>.
  * @param arcDef Archive definition.
  * @throws ArgumentException Thrown if archive with the same consolidation function
  * and the same number of steps is already added.
  */
 public void addArchive(ArcDef arcDef)
 {
     if (arcDefs.Contains(arcDef))
     {
         throw new ArgumentException("Archive already defined: " + arcDef.dump());
     }
     arcDefs.Add(arcDef);
 }
Beispiel #5
0
 /**
  * Checks if two archive definitions are equal.
  * Archive definitions are considered equal if they have the same number of steps
  * and the same consolidation function. It is not possible to create RRD with two
  * equal archive definitions.
  *
  * @param obj Archive definition to compare with.
  *
  * @return <code>true</code> if archive definitions are equal,
  *         <code>false</code> otherwise.
  */
 public bool equals(Object obj)
 {
     if (obj.GetType() == typeof(ArcDef))
     {
         ArcDef arcObj = (ArcDef)obj;
         return(consolFun.Name.CompareTo(arcObj.consolFun.Name) == 0 && Steps == arcObj.Steps);
     }
     return(false);
 }
Beispiel #6
0
 /**
  * Returns all archive definition objects specified so far.
  * @return Array of archive definition objects.
  */
 public ArcDef[] getArcDefs()
 {
     ArcDef[] archives = new ArcDef[arcDefs.Count];
     for (var i = 0; i < arcDefs.Count; i++)
     {
         archives[i] = arcDefs[i];
     }
     return(archives);
 }
Beispiel #7
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);
            }
        }
Beispiel #8
0
 public bool ContainsArchive(ArcDef otherArcDef)
 {
     foreach (ArcDef arcDef in arcDefs)
     {
         if (arcDef.getConsolFun().CSType == otherArcDef.getConsolFun().CSType &&
             arcDef.getSteps() == otherArcDef.getSteps())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
 public bool exactlyEqual(ArcDef def)
 {
     return consolFun.CSType == def.consolFun.CSType && Xff == def.Xff && Steps == def.Steps && Rows == def.Rows;
 }
Beispiel #10
0
 public void UpdateArchive(ArcDef updatedArcDef)
 {
    var archDef = EditingDatabaseData.Definition.findArchive(updatedArcDef.getConsolFun(), updatedArcDef.getSteps());
    archDef.setRows(updatedArcDef.getRows());
    DatabaseDirty = true;
 }
Beispiel #11
0
      public FetchData GetArchiveData(DatabaseData databaseData, string dataSourceName, ArcDef archiveDefinition)
      {
         RrdDb database = null;
         try
         {
            database = new RrdDb(databaseData.Definition.getPath(), true);
            int datasourceIndex = database.getDsIndex(dataSourceName);
            Archive archive = database.getArchive(new ConsolFun(archiveDefinition.getConsolFun().Name), archiveDefinition.Steps);
            Robin robin = archive.getRobin(datasourceIndex);
            double[] values = robin.getValues();
            DateTime archiveStartTime = archive.getStartDateTime();
            TimeSpan tick = new TimeSpan(archive.getArcStep() * TimeSpan.TicksPerSecond);

            FetchData fetchedData = new FetchData(archive.getArcStep(), archive.getEndTime(), new string[] { dataSourceName });
            long[] timestamps = new long[archive.getRows()];
            long offset = archive.getStartTime();
            for (var i = 0; i < archive.getRows(); i++)
            {
               timestamps[i] = offset;
               offset += archive.getArcStep();
            }
            fetchedData.setTimestamps(timestamps);
            double[][] value = new double[1][];
            value[0] = values;
            fetchedData.setValues(value);
            return fetchedData;

         }
         finally
         {
            if (database != null)
               database.close();
         }
      }
Beispiel #12
0
 public bool exactlyEqual(ArcDef def)
 {
     return(consolFun.CSType == def.consolFun.CSType && Xff == def.Xff && Steps == def.Steps && Rows == def.Rows);
 }
Beispiel #13
0
 /**
  * <p>Returns RRD definition object which can be used to create new RRD
  * with the same creation parameters but with no data in it.</p>
  * <p/>
  * <p>Example:</p>
  * <p/>
  * <pre>
  * RrdDb rrd1 = new RrdDb("original.rrd");
  * RrdDef def = rrd1.getRrdDef();
  * // fix path
  * def.setPath("empty_copy.rrd");
  * // create new RRD file
  * RrdDb rrd2 = new RrdDb(def);
  * </pre>
  *
  * @return RRD definition.
  */
 public RrdDef getRrdDef()
 {
    lock (sync)
    {
       // set header
       long startTime = header.getLastUpdateTime();
       long step = header.getStep();
       String path = backend.getPath();
       RrdDef rrdDef = new RrdDef(path, startTime, step);
       // add Datasources
       foreach (Datasource Datasource in Datasources)
       {
          DsDef dsDef = new DsDef(Datasource.DsName,
                  Datasource.DsType, Datasource.Heartbeat,
                  Datasource.MinValue, Datasource.MaxValue);
          rrdDef.addDatasource(dsDef);
       }
       // add archives
       foreach (Archive archive in archives)
       {
          ArcDef arcDef = new ArcDef(archive.getConsolFun(),
                  archive.getXff(), archive.getSteps(), archive.getRows());
          rrdDef.addArchive(arcDef);
       }
       return rrdDef;
    }
 }
Beispiel #14
0
 public void AddArchive(ArcDef arcDef)
 {
    EditingDatabaseData.Definition.addArchive(arcDef);
    DatabaseDirty = true;
 }
Beispiel #15
0
 public bool ContainsArchive(ArcDef otherArcDef)
 {
    foreach (ArcDef arcDef in arcDefs)
    {
       if (arcDef.getConsolFun().CSType == otherArcDef.getConsolFun().CSType 
          && arcDef.getSteps() == otherArcDef.getSteps())
          return true;
    }
    return false;
 }
Beispiel #16
0
 /**
  * Returns all archive definition objects specified so far.
  * @return Array of archive definition objects.
  */
 public ArcDef[] getArcDefs()
 {
    ArcDef[] archives = new ArcDef[arcDefs.Count];
    for (var i = 0; i < arcDefs.Count; i++ )
    {
       archives[i] = arcDefs[i];
    }
    return archives;
 }
Beispiel #17
0
 /**
  * Adds archive definitions to RRD definition in bulk.
  * @param arcDefs Array of archive definition objects
  * @throws ArgumentException Thrown if RRD definition already contains archive with
  * the same consolidation function and the same number of steps.
  */
 public void addArchive(ArcDef[] arcDefs)
 {
     foreach (ArcDef arcDef in arcDefs)
     {
         addArchive(arcDef);
     }
 }
Beispiel #18
0
 /**
  * Adds single archive definition represented with object of class <code>ArcDef</code>.
  * @param arcDef Archive definition.
  * @throws ArgumentException Thrown if archive with the same consolidation function
  * and the same number of steps is already added.
  */
 public void addArchive(ArcDef arcDef)
 {
     if (arcDefs.Contains(arcDef))
     {
         throw new ArgumentException("Archive already defined: " + arcDef.dump());
     }
     arcDefs.Add(arcDef);
 }