Beispiel #1
0
 public Datasource(RrdDb parentDb, DsDef dsDef)
 {
     bool shouldInitialize = dsDef != null;
     this.parentDb = parentDb;
     dsName = new RrdString(this);
     dsTypeName = new RrdString(this);
     if (!shouldInitialize) 
        dsType = new DsType(dsTypeName.get());
     heartbeat = new RrdLong(this);
     minValue = new RrdDouble(this);
     maxValue = new RrdDouble(this);
     lastValue = new RrdDouble(this);
     accumValue = new RrdDouble(this);
     nanSeconds = new RrdLong(this);
     if (shouldInitialize)
     {
         dsName.set(dsDef.getDsName());
         dsType = dsDef.getDsType();
         dsTypeName.set(dsType.Name);
         heartbeat.set(dsDef.getHeartbeat());
         minValue.set(dsDef.getMinValue());
         maxValue.set(dsDef.getMaxValue());
         lastValue.set(Double.NaN);
         accumValue.set(0.0);
         Header header = parentDb.getHeader();
         nanSeconds.set(header.getLastUpdateTime() % header.getStep());
     }
 }
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 Datasource(RrdDb parentDb, DsDef dsDef)
        {
            bool shouldInitialize = dsDef != null;

            this.parentDb = parentDb;
            dsName        = new RrdString(this);
            dsTypeName    = new RrdString(this);
            if (!shouldInitialize)
            {
                dsType = new DsType(dsTypeName.get());
            }
            heartbeat  = new RrdLong(this);
            minValue   = new RrdDouble(this);
            maxValue   = new RrdDouble(this);
            lastValue  = new RrdDouble(this);
            accumValue = new RrdDouble(this);
            nanSeconds = new RrdLong(this);
            if (shouldInitialize)
            {
                dsName.set(dsDef.getDsName());
                dsType = dsDef.getDsType();
                dsTypeName.set(dsType.Name);
                heartbeat.set(dsDef.getHeartbeat());
                minValue.set(dsDef.getMinValue());
                maxValue.set(dsDef.getMaxValue());
                lastValue.set(Double.NaN);
                accumValue.set(0.0);
                Header header = parentDb.getHeader();
                nanSeconds.set(header.getLastUpdateTime() % header.getStep());
            }
        }
Beispiel #4
0
 /**
  * Adds single datasource definition represented with object of class <code>DsDef</code>.
  * @param dsDef Datasource definition.
  */
 public void addDatasource(DsDef dsDef)
 {
     if (dsDefs.Contains(dsDef))
     {
         throw new ArgumentException("Datasource already defined: " + dsDef.dump());
     }
     dsDefs.Add(dsDef);
 }
Beispiel #5
0
 /**
  * Checks if two datasource definitions are equal.
  * Source definitions are treated as equal if they have the same source name.
  * 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(DsDef))
     {
         DsDef dsObj = (DsDef)obj;
         return(DsName.CompareTo(dsObj.DsName) == 0);
     }
     return(false);
 }
Beispiel #6
0
 void removeDatasource(String dsName)
 {
     for (int i = 0; i < dsDefs.Count; i++)
     {
         DsDef dsDef = dsDefs[i];
         if (dsDef.getDsName().CompareTo(dsName) == 0)
         {
             dsDefs.RemoveAt(i);
             return;
         }
     }
     throw new ArgumentException("Could not find datasource named '" + dsName + "'");
 }
Beispiel #7
0
 public void UpdateDataSource(string command, DsDef originalDsDef)
 {
    RrdDbParser parser = new RrdDbParser("");
    model.UpdateDataSource(SrcDatabase, parser.parseDef(command), originalDsDef);
 }
Beispiel #8
0
 public void SetDatasourceData(DsDef[] datasources)
 {
    LoadDataSourceView(datasources);
 }
Beispiel #9
0
 /**
  * Adds data source definitions to RRD definition in bulk.
  * @param dsDefs Array of data source definition objects.
  */
 public void addDatasource(DsDef[] dsDefs)
 {
     foreach (DsDef dsDef in dsDefs)
     {
         addDatasource(dsDef);
     }
 }
Beispiel #10
0
 /**
  * Adds single datasource definition represented with object of class <code>DsDef</code>.
  * @param dsDef Datasource definition.
  */
 public void addDatasource(DsDef dsDef)
 {
     if (dsDefs.Contains(dsDef))
     {
         throw new ArgumentException("Datasource already defined: " + dsDef.dump());
     }
     dsDefs.Add(dsDef);
 }
Beispiel #11
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 #12
0
      public void UpdateDataSource(DatabaseData srcDatabase, DsDef updatedDsDef, DsDef originalDsDef)
      {
         RrdDb database = null;

         try
         {
            database = new RrdDb(srcDatabase.Definition.Path, false);
            Datasource datasource = database.getDatasource(originalDsDef.getDsName());
            if (datasource == null)
               throw new ArgumentException(updatedDsDef.getDsName() + " datasource don't exist");
            if (datasource.DsName != updatedDsDef.DsName)
               datasource.setDsName(updatedDsDef.getDsName());
            datasource.setDsType(updatedDsDef.getDsType());
            datasource.setHeartbeat(updatedDsDef.getHeartbeat());
            datasource.setMaxValue(updatedDsDef.getMaxValue(), true);
            datasource.setMinValue(updatedDsDef.getMinValue(), true);

         }
         catch (FileNotFoundException ex)
         {
            Logger.Error("Update datasource failed", ex);
            throw new ApplicationException("Can't update datasource until database saved!", ex);
         }
         finally
         {
            if (database != null)
               database.close();
         }
      }
Beispiel #13
0
 public void AddDataSource(DsDef dsDef)
 {
    EditingDatabaseData.Definition.addDatasource(dsDef);
    DatabaseDirty = true;
 }
Beispiel #14
0
 public bool exactlyEqual(DsDef def)
 {
     return (DsName.CompareTo(def.DsName) == 0) && dsType.Dt == def.dsType.Dt &&
             heartbeat == def.heartbeat && Util.equal(minValue, def.minValue) &&
             Util.equal(maxValue, def.maxValue);
 }
Beispiel #15
0
 public bool exactlyEqual(DsDef def)
 {
     return((DsName.CompareTo(def.DsName) == 0) && dsType.Dt == def.dsType.Dt &&
            heartbeat == def.heartbeat && Util.equal(minValue, def.minValue) &&
            Util.equal(maxValue, def.maxValue));
 }