Exemplo n.º 1
0
        public MonitorRate(MonitorReport report, string name)
        {
            Verify.IsNotNull(nameof(report), report);
            Verify.IsNotEmpty(nameof(name), name);

            Report = report;
            Name   = name;

            _timer             = new Timer(x => Flush(), null, _period, _period);
            _currentRateDetail = new RateDetail(name);
        }
Exemplo n.º 2
0
        public void Add(RateDetail rateDetail)
        {
            AddNew(rateDetail.NewCount);
            AddRead(rateDetail.ReadCount);
            AddError(rateDetail.ErrorCount);
            AddRetryCount(rateDetail.RetryCount);
            LastErrorMessage = rateDetail.LastErrorMessage ?? LastErrorMessage;

            if (rateDetail.StartTime < StartTime)
            {
                StartTime = rateDetail.StartTime;
            }
        }
Exemplo n.º 3
0
        private void Flush()
        {
            // Only allow one thread in (non blocking)
            int currentLock = Interlocked.CompareExchange(ref _flushLock, 1, 0);

            if (currentLock == 1)
            {
                return;
            }

            RateDetail current = Interlocked.Exchange(ref _currentRateDetail, new RateDetail(Name));

            current.Stop();
            Report.Enqueue(current);

            Interlocked.Exchange(ref _flushLock, 0);
            return;
        }
Exemplo n.º 4
0
        private void DisplayDetail(RateDetail detail)
        {
            int count = detail.NewCount + detail.ReadCount;

            var fields = new List <string>
            {
                $"{Name,-10}",
                $"Service={detail.Name,-20}",
                $"Count=({count,5:D} / {detail.TpsRate:00000.00})",
                $"Read=({detail.ReadCount, 5:D} / {detail.TpsReadRate:00000.00})",
                $"New=({detail.NewCount, 5:D} / {detail.TpsNewRate:00000.00})",
                $"Error Count={detail.ErrorCount, 5:D}",
                $"Retry={detail.RetryCount, 5:D}",
            };

            if (detail.LastErrorMessage.IsNotEmpty())
            {
                fields.Add($"LastError: {detail.LastErrorMessage}");
            }

            Console.WriteLine(string.Join(", ", fields));
        }
Exemplo n.º 5
0
        private void DisplaySummary()
        {
            var list = new List <RateDetail>();

            while (_queue.Count > 0)
            {
                RateDetail detail;
                if (_queue.TryDequeue(out detail))
                {
                    detail.Stop();
                    list.Add(detail);
                }
            }

            RateDetail summary = new RateDetail($"Summary ({list.Count})");

            foreach (var item in list)
            {
                summary.Add(item);
            }

            summary.Stop();
            DisplayDetail(summary);
        }
Exemplo n.º 6
0
        public void Enqueue(RateDetail value)
        {
            Verify.Assert(_timer != null, "Report monitor is not running");

            _queue.Enqueue(value);
        }