Example #1
0
        internal FetchData FetchData(FetchRequest request)
        {
            Archive   archive   = FindMatchingArchive(request);
            FetchData fetchData = archive.FetchData(request);

            Util.Debug(request.RrdToolCommand);
            return(fetchData);
        }
Example #2
0
        internal FetchData FetchData(FetchRequest request)
        {
            long arcStep    = ArcStep;
            long fetchStart = Util.Normalize(request.FetchStart, arcStep);
            long fetchEnd   = Util.Normalize(request.FetchEnd, arcStep);

            if (fetchEnd < request.FetchEnd)
            {
                fetchEnd += arcStep;
            }
            long startTime = StartTime;
            long endTime   = EndTime;

            string[] dsToFetch = request.Filter;
            if (dsToFetch == null)
            {
                dsToFetch = parentDb.DsNames;
            }
            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 val = Double.NaN;
                    if (time >= matchStartTime && time <= matchEndTime)
                    {
                        // inbound time
                        int robinValueIndex = (int)((time - matchStartTime) / arcStep);
                        val = robinValues[i][robinValueIndex];
                    }
                    values[i][ptIndex] = val;
                }
            }
            FetchData fetchData = new FetchData(this, request);

            fetchData.Timestamps = timestamps;
            fetchData.Values     = values;
            return(fetchData);
        }