private StatisticsRecord GetStatisticsByQueue(SubscriptionQueueEntry e, MessageStats prevStats) { var record = new StatisticsRecord(); var setting = _statisticsSettings.GetSetting(e.Subscription); if (setting == null) { setting = _statisticsSettings.CreateSetting(e.Subscription); } record.StatisticsSetting = setting; record.Since = DateTime.Now; record.To = record.Since.AddMilliseconds(StatisticsIntervalToMilliseconds(Interval)); record.StatisticsInterval = Interval; var stats = e.Queue.MessageStats; var sumSentFunc = new Func <MessageStats, long> (x => x != null ? x.DeliverGet : 0); var sumPublishFunc = new Func <MessageStats, long> (x => x != null ? x.Publish : 0); if (stats != null) { record.SentCount = GetStatisticValue((int)sumSentFunc(stats), (int)sumSentFunc(prevStats)); record.ReceivedCount = GetStatisticValue((int)sumPublishFunc(stats), (int)sumPublishFunc(prevStats)); record.QueueLength = e.Queue.Messages; } return(record); }
/// <summary> /// Returns current stat record from <see cref="_statData"/>. It creates new record if necessary. /// </summary> /// <returns>Return current statistics record for provided <paramref name="subscription"/>.</returns> private StatisticsRecord GetCurrentStatRecord(Subscription subscription) { var subscriptionId = subscription == null?_statSettings.GetSubscriptionSB() : new Guid(subscription.__PrimaryKey.ToString()); DateTime currentTimestampBucket = GetCurrentTimestampBucket(); Dictionary <Guid?, StatisticsRecord> bucketData; if (!_statData.TryGetValue(currentTimestampBucket, out bucketData)) { _statData[currentTimestampBucket] = bucketData = new Dictionary <Guid?, StatisticsRecord>(); } StatisticsRecord statRecord; if (!bucketData.TryGetValue(subscriptionId, out statRecord)) { var statSetting = _statSettings.GetSetting(subscription) ?? _statSettings.CreateSetting(subscription); bucketData[subscriptionId] = statRecord = new StatisticsRecord() { StatisticsSetting = statSetting, StatisticsInterval = StatisticsInterval.OneSecond, Since = currentTimestampBucket, To = currentTimestampBucket.AddSeconds(1), }; } return(statRecord); }