Esempio n. 1
0
        public MonitorRate(MonitorReport report, string name)
        {
            Report = report;
            Name   = name;

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

            if (rateDetail.StartTime < StartTime)
            {
                StartTime = rateDetail.StartTime;
            }
        }
        private void DisplayDetail(RateDetail detail)
        {
            int count = detail.NewCount + detail.BatchCount;

            var fields = new List <string>
            {
                $"{Name,-10}",
                $"Service={detail.Name,-20}",
                $"Count=({count,8:D} / {detail.TpsRate:00000000.00})",
                $"Batches=({detail.BatchCount, 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 (!string.IsNullOrWhiteSpace(detail.LastErrorMessage))
            {
                fields.Add($"LastError: {detail.LastErrorMessage}");
            }

            _logging.Log(() => string.Join(", ", fields));
        }
Esempio n. 4
0
        private void Flush()
        {
            // Only allow one thread in (non blocking)
            int currentLock = Interlocked.CompareExchange(ref _flushLock, 1, 0);

            if (currentLock == 1)
            {
                return;
            }

            try
            {
                RateDetail current = Interlocked.Exchange(ref _currentRateDetail, new RateDetail(Name));
                current.Stop();
                Report.Enqueue(current);
                return;
            }
            finally
            {
                Interlocked.Exchange(ref _flushLock, 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);
        }
 public void Enqueue(RateDetail value)
 {
     _queue.Enqueue(value);
 }