Example #1
0
 public Archive(RrdDb parentDb, ArcDef arcDef)
 {
    bool shouldInitialize = arcDef != null;
    this.parentDb = parentDb;
    consolFun = new RrdString(this, true);  // constant, may be cached
    xff = new RrdDouble(this);
    steps = new RrdInt(this, true);            // constant, may be cached
    rows = new RrdInt(this, true);            // constant, may be cached
    if (shouldInitialize)
    {
       consolFun.set(arcDef.getConsolFun().Name);
       xff.set(arcDef.getXff());
       steps.set(arcDef.getSteps());
       rows.set(arcDef.getRows());
    }
    int n = parentDb.getHeader().getDsCount();
    states = new ArcState[n];
    robins = new Robin[n];
    for (int i = 0; i < n; i++)
    {
       states[i] = new ArcState(this, shouldInitialize);
       int numRows = rows.get();
       robins[i] = new Robin(this, numRows, shouldInitialize);
    }
 }
Example #2
0
        /**
         * Copies object's internal state to another Robin object.
         *
         * @param other New Robin object to copy state to
         * @Thrown in case of I/O error
         */
        public void copyStateTo(RrdUpdater other)
        {
            if (other.GetType() != typeof(Robin))
            {
                throw new ArgumentException(
                          "Cannot copy Robin object to " + other.GetType().ToString());
            }
            Robin robin    = (Robin)other;
            int   rowsDiff = rows - robin.rows;

            if (rowsDiff == 0)
            {
                // Identical dimensions. Do copy in BULK to speed things up
                robin.pointer.set(pointer.get());
                robin.values.writeBytes(values.readBytes());
            }
            else
            {
                // different sizes
                for (int i = 0; i < robin.rows; i++)
                {
                    int j = i + rowsDiff;
                    robin.store(j >= 0 ? getValue(j) : Double.NaN);
                }
            }
        }
Example #3
0
        public Archive(RrdDb parentDb, ArcDef arcDef)
        {
            bool shouldInitialize = arcDef != null;

            this.parentDb = parentDb;
            consolFun     = new RrdString(this, true); // constant, may be cached
            xff           = new RrdDouble(this);
            steps         = new RrdInt(this, true);    // constant, may be cached
            rows          = new RrdInt(this, true);    // constant, may be cached
            if (shouldInitialize)
            {
                consolFun.set(arcDef.getConsolFun().Name);
                xff.set(arcDef.getXff());
                steps.set(arcDef.getSteps());
                rows.set(arcDef.getRows());
            }
            int n = parentDb.getHeader().getDsCount();

            states = new ArcState[n];
            robins = new Robin[n];
            for (int i = 0; i < n; i++)
            {
                states[i] = new ArcState(this, shouldInitialize);
                int numRows = rows.get();
                robins[i] = new Robin(this, numRows, shouldInitialize);
            }
        }
Example #4
0
        private void finalizeStep(ArcState state, Robin robin)
        {
            // should store
            long   arcSteps = steps.get();
            double arcXff   = xff.get();
            long   nanSteps = state.getNanSteps();
            //double nanPct = (double) nanSteps / (double) arcSteps;
            double accumValue = state.getAccumValue();

            if (nanSteps <= arcXff * arcSteps && !Double.IsNaN(accumValue))
            {
                if (getConsolFun().CSType == ConsolFun.ConsolFunTypes.AVERAGE)
                {
                    accumValue /= (arcSteps - nanSteps);
                }
                robin.store(accumValue);
            }
            else
            {
                robin.store(Double.NaN);
            }
            state.setAccumValue(Double.NaN);
            state.setNanSteps(0);
        }
Example #5
0
        public void archive(int dsIndex, double value, long numUpdates)
        {
            Robin    robin          = robins[dsIndex];
            ArcState state          = states[dsIndex];
            long     step           = parentDb.getHeader().getStep();
            long     lastUpdateTime = parentDb.getHeader().getLastUpdateTime();
            long     updateTime     = Util.normalize(lastUpdateTime, step) + step;
            long     arcStep        = getArcStep();

            // finish current step
            while (numUpdates > 0)
            {
                accumulate(state, value);
                numUpdates--;
                if (updateTime % arcStep == 0)
                {
                    finalizeStep(state, robin);
                    break;
                }
                else
                {
                    updateTime += step;
                }
            }
            // update robin in bulk
            int bulkUpdateCount = (int)Math.Min(numUpdates / steps.get(), (long)rows.get());

            robin.bulkStore(value, bulkUpdateCount);
            // update remaining steps
            long remainingUpdates = numUpdates % steps.get();

            for (long i = 0; i < remainingUpdates; i++)
            {
                accumulate(state, value);
            }
        }
Example #6
0
 private void finalizeStep(ArcState state, Robin robin)
 {
    // should store
    long arcSteps = steps.get();
    double arcXff = xff.get();
    long nanSteps = state.getNanSteps();
    //double nanPct = (double) nanSteps / (double) arcSteps;
    double accumValue = state.getAccumValue();
    if (nanSteps <= arcXff * arcSteps && !Double.IsNaN(accumValue))
    {
       if (getConsolFun().CSType == ConsolFun.ConsolFunTypes.AVERAGE)
       {
          accumValue /= (arcSteps - nanSteps);
       }
       robin.store(accumValue);
    }
    else
    {
       robin.store(Double.NaN);
    }
    state.setAccumValue(Double.NaN);
    state.setNanSteps(0);
 }