Exemple #1
0
        /**
         * Constructor used to create new RRD object from the definition object but with a storage
         * (backend) different from default.
         *
         * <p>Rrd4n uses <i>factories</i> to create RRD backend objecs. There are three different
         * backend factories supplied with Rrd4n, and each factory has its unique name:</p>
         * <p/>
         * <ul>
         * <li><b>FILE</b>: backends created from this factory will store RRD data to files by using
         * java.io.* classes and methods
         * <li><b>NIO</b>: backends created from this factory will store RRD data to files by using
         * java.nio.* classes and methods
         * <li><b>MEMORY</b>: backends created from this factory will store RRD data in memory. This might
         * be useful in runtime environments which prohibit disk utilization, or for storing temporary,
         * non-critical data (it gets lost as soon as JVM exits).
         * </ul>
         * <p/>
         * <p>For example, to create RRD in memory, use the following code</p>
         * <pre>
         * RrdBackendFactory factory = RrdBackendFactory.getFactory("MEMORY");
         * RrdDb rrdDb = new RrdDb(rrdDef, factory);
         * rrdDb.close();
         * </pre>
         * <p/>
         * <p>New RRD file structure is specified with an object of class
         * {@link RrdDef <b>RrdDef</b>}. The underlying RRD storage is created as soon
         * as the constructor returns.</p>
         *
         * @param rrdDef  RRD definition object
         * @param factory The factory which will be used to create storage for this RRD
         * @Thrown in case of I/O error
         * @see RrdBackendFactory
         */
        public RrdDb(RrdDef rrdDef, RrdBackendFactory factory)
        {
            if (!rrdDef.hasDatasources())
            {
                throw new ArgumentException("No RRD Datasource specified. At least one is needed.");
            }
            if (!rrdDef.hasArchives())
            {
                throw new ArgumentException("No RRD archive specified. At least one is needed.");
            }

            String path = rrdDef.getPath();

            backend = factory.open(path, false);
            try
            {
                backend.setLength(rrdDef.getEstimatedSize());
                // create header
                header = new Header(this, rrdDef);
                // create Datasources
                DsDef[] dsDefs = rrdDef.getDsDefs();
                Datasources = new Datasource[dsDefs.Length];
                for (int i = 0; i < dsDefs.Length; i++)
                {
                    Datasources[i] = new Datasource(this, dsDefs[i]);
                }
                // create archives
                ArcDef[] arcDefs = rrdDef.getArcDefs();
                archives = new Archive[arcDefs.Length];
                for (int i = 0; i < arcDefs.Length; i++)
                {
                    archives[i] = new Archive(this, arcDefs[i]);
                }
            }
            catch (IOException e)
            {
                backend.close();
                throw;
            }
        }
Exemple #2
0
      /**
       * Constructor used to create new RRD object from the definition object but with a storage
       * (backend) different from default.
       *
       * <p>Rrd4n uses <i>factories</i> to create RRD backend objecs. There are three different
       * backend factories supplied with Rrd4n, and each factory has its unique name:</p>
       * <p/>
       * <ul>
       * <li><b>FILE</b>: backends created from this factory will store RRD data to files by using
       * java.io.* classes and methods
       * <li><b>NIO</b>: backends created from this factory will store RRD data to files by using
       * java.nio.* classes and methods
       * <li><b>MEMORY</b>: backends created from this factory will store RRD data in memory. This might
       * be useful in runtime environments which prohibit disk utilization, or for storing temporary,
       * non-critical data (it gets lost as soon as JVM exits).
       * </ul>
       * <p/>
       * <p>For example, to create RRD in memory, use the following code</p>
       * <pre>
       * RrdBackendFactory factory = RrdBackendFactory.getFactory("MEMORY");
       * RrdDb rrdDb = new RrdDb(rrdDef, factory);
       * rrdDb.close();
       * </pre>
       * <p/>
       * <p>New RRD file structure is specified with an object of class
       * {@link RrdDef <b>RrdDef</b>}. The underlying RRD storage is created as soon
       * as the constructor returns.</p>
       *
       * @param rrdDef  RRD definition object
       * @param factory The factory which will be used to create storage for this RRD
       * @Thrown in case of I/O error
       * @see RrdBackendFactory
       */
      public RrdDb(RrdDef rrdDef, RrdBackendFactory factory)
      {
         if (!rrdDef.hasDatasources())
         {
            throw new ArgumentException("No RRD Datasource specified. At least one is needed.");
         }
         if (!rrdDef.hasArchives())
         {
            throw new ArgumentException("No RRD archive specified. At least one is needed.");
         }

         String path = rrdDef.getPath();
         backend = factory.open(path, false);
         try
         {
            backend.setLength(rrdDef.getEstimatedSize());
            // create header
            header = new Header(this, rrdDef);
            // create Datasources
            DsDef[] dsDefs = rrdDef.getDsDefs();
            Datasources = new Datasource[dsDefs.Length];
            for (int i = 0; i < dsDefs.Length; i++)
            {
               Datasources[i] = new Datasource(this, dsDefs[i]);
            }
            // create archives
            ArcDef[] arcDefs = rrdDef.getArcDefs();
            archives = new Archive[arcDefs.Length];
            for (int i = 0; i < arcDefs.Length; i++)
            {
               archives[i] = new Archive(this, arcDefs[i]);
            }
         }
         catch (IOException e)
         {
            backend.close();
            throw;
         }
      }
Exemple #3
0
        /**
         * Compares the current RrdDef with another. RrdDefs are considered equal if:<p>
         *<ul>
         * <li>RRD steps match
         * <li>all datasources have exactly the same definition in both RrdDef objects (datasource names,
         * types, heartbeat, min and max values must match)
         * <li>all archives have exactly the same definition in both RrdDef objects (archive consolidation
         * functions, X-file factors, step and row counts must match)
         * </ul>
         * @param obj The second RrdDef object
         * @return true if RrdDefs match exactly, false otherwise
         */
        public bool equals(Object obj)
        {
            if (obj == null || (obj.GetType() != typeof(RrdDef)))
            {
                return(false);
            }
            RrdDef rrdDef2 = (RrdDef)obj;

            // check primary RRD step
            if (step != rrdDef2.step)
            {
                return(false);
            }
            // check datasources
            DsDef[] dsDefs = getDsDefs(), dsDefs2 = rrdDef2.getDsDefs();
            if (dsDefs.Length != dsDefs2.Length)
            {
                return(false);
            }
            foreach (DsDef dsDef in dsDefs)
            {
                bool matched = false;
                foreach (DsDef aDsDefs2 in dsDefs2)
                {
                    if (dsDef.exactlyEqual(aDsDefs2))
                    {
                        matched = true;
                        break;
                    }
                }
                // this datasource could not be matched
                if (!matched)
                {
                    return(false);
                }
            }
            // check archives
            ArcDef[] arcDefs = getArcDefs(), arcDefs2 = rrdDef2.getArcDefs();
            if (arcDefs.Length != arcDefs2.Length)
            {
                return(false);
            }
            foreach (ArcDef arcDef in arcDefs)
            {
                bool matched = false;
                foreach (ArcDef anArcDefs2 in arcDefs2)
                {
                    if (arcDef.exactlyEqual(anArcDefs2))
                    {
                        matched = true;
                        break;
                    }
                }
                // this archive could not be matched
                if (!matched)
                {
                    return(false);
                }
            }
            // everything matches
            return(true);
        }
Exemple #4
0
      private void LoadTree(RrdDef databaseDefinition)
      {
         rrdDbTreeView.Nodes.Clear();

         var databaseNode = rrdDbTreeView.Nodes.Add("databasenode",Path.GetFileNameWithoutExtension(databaseDefinition.Path));
         var datasources = databaseNode.Nodes.Add(dataSourceNodesName, dataSourceNodesName);
         foreach (var datasource in databaseDefinition.getDsDefs())
         {
            var datasourceNode = datasources.Nodes.Add(datasource.DsName);
            datasourceNode.Tag = datasource;
            foreach (var arcDef in databaseDefinition.getArcDefs())
            {
               string nodeText = string.Format("RRA:{0}:{1}:{2}:{3}", arcDef.getConsolFun().Name,
                                                arcDef.Xff, arcDef.Steps, arcDef.Rows);
               var archiveNode = datasourceNode.Nodes.Add(nodeText);
               archiveNode.Tag = arcDef;
            }
         }
         databaseNode.Nodes.Add(archiveNodesName, archiveNodesName);
      }