Exemple #1
0
 private void Accumulate(ArcState state, double data)
 {
     if (Double.IsNaN(data))
     {
         state.NanSteps = (state.NanSteps + 1);
     }
     else
     {
         if (consolFun.Get().Equals("MIN"))
         {
             state.AccumValue = Util.Min(state.AccumValue, data);
         }
         else if (consolFun.Get().Equals("MAX"))
         {
             state.AccumValue = Util.Max(state.AccumValue, data);
         }
         else if (consolFun.Get().Equals("LAST"))
         {
             state.AccumValue = data;
         }
         else if (consolFun.Get().Equals("AVERAGE"))
         {
             state.AccumValue = Util.Sum(state.AccumValue, data);
         }
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        public void CopyStateTo(IRrdUpdatable other)
        {
            if (!(other is ArcState))
            {
                throw new RrdException("Cannot copy ArcState object to " + other.ToString());
            }
            ArcState arcState = (ArcState)other;

            arcState.accumValue.Set(accumValue.Get());
            arcState.nanSteps.Set(nanSteps.Get());
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentDb"></param>
        public Archive(RrdDb parentDb)
        {
            this.parentDb = parentDb;
            consolFun     = new RrdString(this);
            xff           = new RrdDouble(this);
            steps         = new RrdInt(this);
            rows          = new RrdInt(this);
            int n = parentDb.Header.DsCount;

            states = new ArcState[n];
            robins = new Robin[n];
            for (int i = 0; i < n; i++)
            {
                states[i] = new ArcState(this);
                robins[i] = new Robin(this, rows.Get());
            }
        }
Exemple #4
0
        private void FinalizeStep(ArcState state, Robin robin)
        {
            // should store
            long   arcSteps = steps.Get();
            double arcXff   = xff.Get();
            long   nanSteps = state.NanSteps;
            //double nanPct = (double) nanSteps / (double) arcSteps;
            double accumValue = state.AccumValue;

            if (nanSteps <= arcXff * arcSteps && !Double.IsNaN(accumValue))
            {
                if (consolFun.Get().Equals("AVERAGE"))
                {
                    accumValue /= (arcSteps - nanSteps);
                }
                robin.Store(accumValue);
            }
            else
            {
                robin.Store(Double.NaN);
            }
            state.AccumValue = Double.NaN;
            state.NanSteps   = 0;
        }
Exemple #5
0
        internal void archive(int dsIndex, double data, long numUpdates)
        {
            Robin    robin          = robins[dsIndex];
            ArcState state          = states[dsIndex];
            long     step           = parentDb.Header.Step;
            long     lastUpdateTime = parentDb.Header.LastUpdateTime;
            long     updateTime     = Util.Normalize(lastUpdateTime, step) + step;
            long     arcStep        = ArcStep;

            while (numUpdates > 0)
            {
                Accumulate(state, data);
                numUpdates--;
                if (updateTime % arcStep == 0)
                {
                    FinalizeStep(state, robin);
                    break;
                }
                else
                {
                    updateTime += step;
                }
            }


            int bulkUpdateCount = (int)Math.Min(numUpdates / steps.Get(), (long)rows.Get());

            robin.BulkStore(data, bulkUpdateCount);

            long remainingUpdates = numUpdates % steps.Get();

            for (long i = 0; i < remainingUpdates; i++)
            {
                Accumulate(state, data);
            }
        }