Ejemplo n.º 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);
    }
 }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        private void accumulate(ArcState state, double value)
        {
            if (Double.IsNaN(value))
            {
                state.setNanSteps(state.getNanSteps() + 1);
            }
            else
            {
                ConsolFun cf = new ConsolFun(ConsolFun.ValueOf(consolFun.get()));
                switch (cf.CSType)
                {
                case ConsolFun.ConsolFunTypes.MIN:
                    state.setAccumValue(Util.min(state.getAccumValue(), value));
                    break;

                case ConsolFun.ConsolFunTypes.MAX:
                    state.setAccumValue(Util.max(state.getAccumValue(), value));
                    break;

                case ConsolFun.ConsolFunTypes.LAST:
                    state.setAccumValue(value);
                    break;

                case ConsolFun.ConsolFunTypes.AVERAGE:
                    state.setAccumValue(Util.sum(state.getAccumValue(), value));
                    break;

                case ConsolFun.ConsolFunTypes.TOTAL:
                    state.setAccumValue(Util.sum(state.getAccumValue(), value));
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /**
         * Copies object's internal state to another ArcState object.
         * @param other New ArcState object to copy state to
         * @Thrown in case of I/O error
         */
        public void copyStateTo(RrdUpdater other)
        {
            if ((other.GetType() != typeof(ArcState)))
            {
                throw new ArgumentException("Cannot copy ArcState object to " + other.GetType().ToString());
            }
            ArcState arcState = (ArcState)other;

            arcState.accumValue.set(accumValue.get());
            arcState.nanSteps.set(nanSteps.get());
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 private void accumulate(ArcState state, double value)
 {
    if (Double.IsNaN(value))
    {
       state.setNanSteps(state.getNanSteps() + 1);
    }
    else
    {
       ConsolFun cf = new ConsolFun(ConsolFun.ValueOf(consolFun.get()));
       switch (cf.CSType)
       {
          case ConsolFun.ConsolFunTypes.MIN:
             state.setAccumValue(Util.min(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.MAX:
             state.setAccumValue(Util.max(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.LAST:
             state.setAccumValue(value);
             break;
          case ConsolFun.ConsolFunTypes.AVERAGE:
             state.setAccumValue(Util.sum(state.getAccumValue(), value));
             break;
          case ConsolFun.ConsolFunTypes.TOTAL:
             state.setAccumValue(Util.sum(state.getAccumValue(), value));
             break;
       }
    }
 }