ZocMonLib.Recorder.Record C# (CSharp) Method

Record() public method

Record the given value to the given monitor configuration, for the given time.
public Record ( string configName, System.DateTime time, double value, MonitorReductionType monitorReductionType ) : void
configName string Name of the config
time System.DateTime Time of the recrod
value double Value that is being recorded
monitorReductionType MonitorReductionType Reduction type that is being used
return void
        public void Record(string configName, DateTime time, double value, MonitorReductionType monitorReductionType)
        {
            try
            {
                configName.ThrowIfNull("configName");
                value.ThrowIfNaN("value");

                // todo: If this is called too quickly by different threads, there will be a problem....
                MonitorInfo monitorInfo = _configSeed.Seed(configName, monitorReductionType);
                if (monitorInfo == null)
                    throw new Exception("Seed failed to find/create a monitorInfo: \"" + configName + "\"");

                MonitorConfig monitorConfig = monitorInfo.MonitorConfig;
                ReduceLevel reduceLevel = monitorInfo.FirstReduceLevel;
                IReduceMethod<double> reduceMethod = reduceLevel.AggregationClass;
                IList<MonitorRecord<double>> updateList = monitorInfo.MonitorRecords;

                MonitorRecord<double> next;
                lock (updateList)
                {
                    if (reduceLevel.Resolution == 0)
                    {
                        next = reduceMethod.IntervalAggregate(time, _cache.Empty, value);
                        updateList.Add(next);
                    }
                    else
                    {
                        DateTime timeBin;
                        DateTime recordTime;

                        //The core purpose of this logic is just to group all events into one or more time buckets.
                        //As a result the actual time that the record occurd is irrelevent. The only time that
                        //matters is the first time that occured since the last reduce and even this is rounded
                        //in accordance with the resolution of the reduceLevel.

                        var last = updateList.LastOrDefault();
                        if (last == null)
                        {
                            //Starting bucket for the events to be aggregated into
                            timeBin = Support.RoundToResolution(time, reduceLevel.Resolution);
                            //As we doing have a previous event to work off
                            recordTime = timeBin.AddMilliseconds((long)(reduceLevel.Resolution / 2));
                        }
                        else
                        {
                            recordTime = last.TimeStamp;
                            //Since the we didn't keep a record of the original timeBin that was worked out
                            //when "last == null", we need to derive the original timeBin from the recorded TimeStamp.
                            timeBin = recordTime.AddMilliseconds(-(long)(reduceLevel.Resolution / 2));
                        }

                        //This logic seems off - it will group like items together per timebin but when the
                        //event time changes beyound the threshold of the current timebin, the timebin isn't
                        //the one that matches the event time, its simply one increment from the last timebin
                        if (last != null && time.Ticks < timeBin.AddMilliseconds(reduceLevel.Resolution).Ticks)
                        {
                            next = reduceMethod.IntervalAggregate(recordTime, last, value);
                            updateList[updateList.Count - 1] = next;
                        }
                        else
                        {
                            if (last != null) recordTime = recordTime.AddMilliseconds(reduceLevel.Resolution);
                            next = reduceMethod.IntervalAggregate(recordTime, _cache.Empty, value);
                            updateList.Add(next);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Fatal("Exception swallowed: ", e);
                if (_settings.Debug)
                    throw;
            }
        }

Same methods

Recorder::Record ( string configName, double value, MonitorReductionType monitorReductionType ) : void

Usage Example

Example #1
0
            public void WhenHasResolutionAllLikeTimesShouldBeGrouped()
            {
                var monitorInfo = BuildDefaultMonitorInfo(1000);
                var recordMocks = BuildRecordMocks(monitorInfo);

                var recorder = new Recorder(recordMocks.Cache.Object, recordMocks.Settings.Object);
                recorder.Record("Test", new DateTime(1995, 06, 06, 1, 32, 23, 452), 1, MonitorReductionType.DefaultAccumulate);
                recorder.Record("Test", new DateTime(1995, 06, 06, 1, 32, 23, 453), 1, MonitorReductionType.DefaultAccumulate);
                recorder.Record("Test", new DateTime(1995, 06, 06, 1, 32, 23, 454), 1, MonitorReductionType.DefaultAccumulate);

                Assert.Equal(monitorInfo.MonitorRecords.Count, 1);
                Assert.Equal(monitorInfo.MonitorRecords[0].Number, 3);
            }
All Usage Examples Of ZocMonLib.Recorder::Record