/// <summary>
        /// Add the specified custom sampled metric sample object to the collection
        /// </summary>
        /// <param name="newMetricSample">The new custom sampled metric object to add</param>
        public void Add(EventMetricSample newMetricSample)
        {
            if (newMetricSample == null)
            {
                throw new ArgumentNullException(nameof(newMetricSample), "A new custom sampled metric sample object must be provided to add it to the collection.");
            }

            //our base object does all the work
            base.Add(newMetricSample);
        }
Ejemplo n.º 2
0
        private MetricValueCollection OnCalculateValuesShortest(DateTimeOffset startDateTime, DateTimeOffset endDateTime, IEventMetricValueDefinition trendValue)
        {
            //there are two possibilities for unit caption:  Either use the caption from the trend definition or, if that's null, we'll just do Count.
            string unitCaption = null;

            if (trendValue != null)
            {
                unitCaption = trendValue.UnitCaption;
            }

            if (string.IsNullOrEmpty(unitCaption))
            {
                unitCaption = "Events";
            }

            MetricValueCollection newMetricValueCollection;

            if (trendValue == null)
            {
                //initialize with our metric object for default caption/description behavior
                newMetricValueCollection = new MetricValueCollection(this, MetricSampleInterval.Shortest, 0, unitCaption);
            }
            else
            {
                //initialize with our trend for trend-specific captions and descriptions
                newMetricValueCollection = new MetricValueCollection((EventMetricValueDefinition)trendValue, MetricSampleInterval.Shortest, 0, unitCaption);
            }

            double lastValue = 0.0;

            //First, we need to find the value for the start date & time and the sample index into the collection.
            for (int curSampleIndex = 0; curSampleIndex < Samples.Count; curSampleIndex++)
            {
                //get the sample on deck
                EventMetricSample curSample = Samples[curSampleIndex];

                //Is this sample in our range?
                if (curSample.Timestamp >= startDateTime)
                {
                    //Go ahead and calculate the value, adding it to our set.  We don't use a baseline because we're looking at each individual value.
                    CalculateSample(newMetricValueCollection, new List <EventMetricSample>(new[] { curSample }), lastValue, curSampleIndex, curSample.Timestamp, (EventMetricValueDefinition)trendValue);
                }
                else if (curSample.Timestamp > endDateTime)
                {
                    //we're done - there are no more samples to consider, break out of the for loop
                    break;
                }
            }

            return(newMetricValueCollection);
        }
        /// <summary>
        /// Add a new custom sampled metric sample from the specified sample packet
        /// </summary>
        /// <param name="newMetricSamplePacket">The sample packet to create a new metric sample object from</param>
        internal EventMetricSample Add(EventMetricSamplePacket newMetricSamplePacket)
        {
            if (newMetricSamplePacket == null)
            {
                throw new ArgumentNullException(nameof(newMetricSamplePacket), "A new custom sampled metric sample packet object must be provided to add it to the collection.");
            }

            //now we have to create a new sample object to wrap the provided packet
            EventMetricSample newMetricSample = new EventMetricSample(m_EventMetric, newMetricSamplePacket);

            //and forward to our normal add routine
            Add(newMetricSample);

            //returning our new wrapped object
            return(newMetricSample);
        }
Ejemplo n.º 4
0
        private MetricValueCollection OnCalculateValuesInterval(MetricSampleInterval interval, int intervals, DateTimeOffset startDateTime, DateTimeOffset endDateTime, IEventMetricValueDefinition trendValue)
        {
            //there are two possibilities for unit caption:  Either use the caption from the trend definition or, if that's null, we'll just do Count.
            string unitCaption = null;

            if (trendValue != null)
            {
                unitCaption = trendValue.UnitCaption;
            }

            if (string.IsNullOrEmpty(unitCaption))
            {
                unitCaption = "Events";
            }

            MetricValueCollection newMetricValueCollection;

            if (trendValue == null)
            {
                //initialize with our metric object for default caption/description behavior
                newMetricValueCollection = new MetricValueCollection(this, interval, intervals, unitCaption);
            }
            else
            {
                //initialize with our trend for trend-specific captions and descriptions
                newMetricValueCollection = new MetricValueCollection((EventMetricValueDefinition)trendValue, interval, intervals, unitCaption);
            }

            //And prep for our process loop
            DateTimeOffset windowStartDateTime = startDateTime;
            DateTimeOffset windowEndDateTime   = CalculateOffset(windowStartDateTime, interval, intervals);
            double         lastValue           = 0.0;

            //now loop through all of the intervals in the range to create the sample ranges.
            int lastUsedSampleIndex = 0;

            while (windowStartDateTime < endDateTime)
            {
                //find all of the samples in the current range...
                List <EventMetricSample> samples = new List <EventMetricSample>();
                for (int curSampleIndex = lastUsedSampleIndex; curSampleIndex < Samples.Count; curSampleIndex++)
                {
                    //get the sample on deck
                    EventMetricSample curSample = Samples[curSampleIndex];

                    //if we're outside of the window (before or after) then break out because we've found this whole bucket.
                    if ((curSample.Timestamp < windowStartDateTime) || (curSample.Timestamp > windowEndDateTime))
                    {
                        //we'll need to look at this sample in the next window to see if it fits.
                        lastUsedSampleIndex = curSampleIndex;
                        break;
                    }

                    //this sample is in the bucket
                    samples.Add(curSample);
                }

                //add a metric value for this bucket now that we know everything in it.
                lastValue = CalculateSample(newMetricValueCollection, samples, lastValue, lastUsedSampleIndex, windowEndDateTime, (EventMetricValueDefinition)trendValue);

                //and now we have recorded a metric value for the requested date & time if possible, move that forward.
                windowStartDateTime = windowEndDateTime; //we're moving on to the next window
                windowEndDateTime   = CalculateOffset(windowEndDateTime, interval, intervals);

                //if the target is beyond our end date & time, set to the end date and time so we calculate our last sample
                if (windowEndDateTime > endDateTime)
                {
                    windowEndDateTime = endDateTime;
                }
            }

            return(newMetricValueCollection);
        }