Ejemplo n.º 1
0
        public void store(long timeStamp, double[] newValues)
        {
            lock (sync)
            {
                if (closed)
                {
                    throw new ApplicationException("RRD already closed, cannot store this sample");
                }

                long lastTime = header.getLastUpdateTime();
                if (lastTime >= timeStamp)
                {
                    throw new ArgumentException("Bad sample time: " + rrd4n.Common.Util.getDate(timeStamp) +
                                                ". Last update time was " + rrd4n.Common.Util.getDate(lastTime) + ", at least one second step is required");
                }
                if (newValues.Length != Datasources.Length)
                {
                    throw new ApplicationException("Datasource mitchmatch. RrdDb datasource count:" + Datasources.Length + ". Datapoint count:" + newValues.Length);
                }

                for (int i = 0; i < Datasources.Length; i++)
                {
                    Datasources[i].process(timeStamp, newValues[i]);
                }
                header.setLastUpdateTime(timeStamp);
            }
        }
Ejemplo n.º 2
0
        public void process(long newTime, double newValue)
        {
            Header header      = parentDb.getHeader();
            long   step        = header.getStep();
            long   oldTime     = header.getLastUpdateTime();
            long   startTime   = Util.normalize(oldTime, step);
            long   endTime     = startTime + step;
            double oldValue    = lastValue.get();
            double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue);

            if (newTime < endTime)
            {
                accumulate(oldTime, newTime, updateValue);
            }
            else
            {
                // should store something
                long boundaryTime = Util.normalize(newTime, step);
                accumulate(oldTime, boundaryTime, updateValue);
                double value = calculateTotal(startTime, boundaryTime);

                // how many updates?
                long numSteps = (boundaryTime - endTime) / step + 1L;

                // ACTION!
                parentDb.archive(this, value, numSteps);

                // cleanup
                nanSeconds.set(0);
                accumValue.set(0.0);

                accumulate(boundaryTime, newTime, updateValue);
            }
        }
Ejemplo n.º 3
0
        public Datasource(RrdDb parentDb, DsDef dsDef)
        {
            bool shouldInitialize = dsDef != null;

            this.parentDb = parentDb;
            dsName        = new RrdString(this);
            dsTypeName    = new RrdString(this);
            if (!shouldInitialize)
            {
                dsType = new DsType(dsTypeName.get());
            }
            heartbeat  = new RrdLong(this);
            minValue   = new RrdDouble(this);
            maxValue   = new RrdDouble(this);
            lastValue  = new RrdDouble(this);
            accumValue = new RrdDouble(this);
            nanSeconds = new RrdLong(this);
            if (shouldInitialize)
            {
                dsName.set(dsDef.getDsName());
                dsType = dsDef.getDsType();
                dsTypeName.set(dsType.Name);
                heartbeat.set(dsDef.getHeartbeat());
                minValue.set(dsDef.getMinValue());
                maxValue.set(dsDef.getMaxValue());
                lastValue.set(Double.NaN);
                accumValue.set(0.0);
                Header header = parentDb.getHeader();
                nanSeconds.set(header.getLastUpdateTime() % header.getStep());
            }
        }
Ejemplo n.º 4
0
 public ArcState(Archive parentArc, bool shouldInitialize)
 {
     this.parentArc = parentArc;
     accumValue     = new RrdDouble(this);
     nanSteps       = new RrdLong(this);
     if (shouldInitialize)
     {
         Header header         = parentArc.getParentDb().getHeader();
         long   step           = header.getStep();
         long   lastUpdateTime = header.getLastUpdateTime();
         long   arcStep        = parentArc.getArcStep();
         long   initNanSteps   = (Util.normalize(lastUpdateTime, step) -
                                  Util.normalize(lastUpdateTime, arcStep)) / step;
         accumValue.set(Double.NaN);
         nanSteps.set(initNanSteps);
     }
 }