示例#1
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();
                }
            }
        }
示例#2
0
文件: Archive.cs 项目: mujing/rrd4net
      public FetchData fetchData(FetchRequest request)
      {
         long arcStep = getArcStep();
         long fetchStart = Util.normalize(request.FetchStart, arcStep);
         long fetchEnd = Util.normalize(request.FetchEnd, arcStep);
         if (fetchEnd < request.FetchEnd)
         {
            fetchEnd += arcStep;
         }
         long startTime = getStartTime();
         long endTime = getEndTime();
         String[] dsToFetch = request.getFilter();
         if (dsToFetch == null)
         {
            dsToFetch = parentDb.getDsNames();
         }
         int dsCount = dsToFetch.Length;
         int ptsCount = (int)((fetchEnd - fetchStart) / arcStep + 1);
         long[] timestamps = new long[ptsCount];
         double[][] values = new double[dsCount][];
         for (int i = 0; i < dsCount; i++)
            values[i] = new double[ptsCount];


         long matchStartTime = Math.Max(fetchStart, startTime);
         long matchEndTime = Math.Min(fetchEnd, endTime);
         double[][] robinValues = null;
         if (matchStartTime <= matchEndTime)
         {
            // preload robin values
            int matchCount = (int)((matchEndTime - matchStartTime) / arcStep + 1);
            int matchStartIndex = (int)((matchStartTime - startTime) / arcStep);
            robinValues = new double[dsCount][];
            for (int i = 0; i < dsCount; i++)
            {
               int dsIndex = parentDb.getDsIndex(dsToFetch[i]);
               robinValues[i] = robins[dsIndex].getValues(matchStartIndex, matchCount);
            }
         }
         for (int ptIndex = 0; ptIndex < ptsCount; ptIndex++)
         {
            long time = fetchStart + ptIndex * arcStep;
            timestamps[ptIndex] = time;
            for (int i = 0; i < dsCount; i++)
            {
               double value = Double.NaN;
               if (time >= matchStartTime && time <= matchEndTime)
               {
                  // inbound time
                  int robinValueIndex = (int)((time - matchStartTime) / arcStep);
                  Debug.Assert(robinValues != null);
                  value = robinValues[i][robinValueIndex];
               }
               values[i][ptIndex] = value;
            }
         }
         FetchData fetchData = new FetchData(steps.get(),endTime, parentDb.getDsNames());
         fetchData.setTimestamps(timestamps);
         fetchData.setValues(values);
         return fetchData;
      }
示例#3
0
文件: Model.cs 项目: mujing/rrd4net
      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();
         }
      }