Пример #1
0
        public TimeWindowSurveyManager(TimeSpan windowSize, Func <IAmbientBottleneckSurvey, Task> onWindowComplete, IAmbientBottleneckDetector?bottleneckDetector, Regex?allow, Regex?block)
        {
            TimeWindowBottleneckSurvey initialSurvey = new TimeWindowBottleneckSurvey(allow, block, AmbientClock.Ticks, windowSize);

            _currentWindowSurvey = initialSurvey;
            System.Timers.ElapsedEventHandler rotateTimeWindow = (s, e) =>
            {
                TimeWindowBottleneckSurvey survey      = new TimeWindowBottleneckSurvey(allow, block, AmbientClock.Ticks, windowSize);
                TimeWindowBottleneckSurvey oldAnalyzer = System.Threading.Interlocked.Exchange(ref _currentWindowSurvey, survey);
                // copy all the accesses still in progress
                survey.SwitchAnalyzer(oldAnalyzer);
                onWindowComplete(oldAnalyzer);
            };
            AmbientEventTimer timer = new AmbientEventTimer();

            timer.AutoReset = true;
            timer.Elapsed  += rotateTimeWindow;
            timer.Interval  = windowSize.TotalMilliseconds;
            timer.Enabled   = true;
            _timer          = timer;
            if (bottleneckDetector != null)
            {
                _bottleneckDetector = bottleneckDetector;
                bottleneckDetector.RegisterAccessNotificationSink(this);
            }
        }
Пример #2
0
        private long _frequencyTicks;                                                                          // interlocked -- the current audit frequency, adjusted based on how long the audit takes (slower audits should run less frequently) and what the resulting rating status is.

        /// <summary>
        /// Constructs an <see cref="StatusAuditor"/> with the specified values.
        /// </summary>
        /// <param name="targetSystem">The name of the target system (if any).</param>
        /// <param name="baselineAuditFrequency">
        /// The baseline frequency with which audits should be run.
        /// The system will start running tests this frequently but will automatically tune the frequency to between one quarter this frequency and ten times this frequency based on the status rating (worse rating means do audits more frequently) and the duration of the audit (fast audits cause more frequent audits).
        /// This means that systems that process status audits faster will automatically be more responsive in reporting issues.
        /// If audits start to timeout, audits will happen less frequently even if they are failing so that the status tests don't contribute to system congestion.
        /// <see cref="TimeSpan.Zero"/> and negative time spans are treated as if they were <see cref="TimeSpan.MaxValue"/>.
        /// </param>
        /// <param name="status">The <see cref="Status"/> this auditor belongs to, or null if this should be a standalone auditor owned by the caller.</param>
        protected internal StatusAuditor(string targetSystem, TimeSpan baselineAuditFrequency, Status?status)
            : base(targetSystem)
        {
            _status = status;
            _baselineAuditFrequency = baselineAuditFrequency;

            _frequencyTicks = baselineAuditFrequency.Ticks;
            _nextAuditTime  = AmbientClock.UtcNow.AddMilliseconds(10).Ticks;
            // create a timer for the initial audit (we'll dispose of this one immediately as soon as that audit finishes)
            _initialAuditTimer           = new System.Timers.Timer(10);
            _initialAuditTimer.Elapsed  += InitialAuditTimer_Elapsed;
            _initialAuditTimer.AutoReset = false;
            // should we update periodically?
            if (baselineAuditFrequency < TimeSpan.MaxValue && baselineAuditFrequency > TimeSpan.FromTicks(0))
            {
                _auditTimer          = new AmbientEventTimer(TimeSpan.FromTicks(_frequencyTicks).TotalMilliseconds);
                _auditTimer.Elapsed += AuditTimer_Elapsed;
            }
            else // other parts of the code assume that _auditTimer is not null, so we will create one here that we don't hook up to any event handler
            {
                _auditTimer = new AmbientEventTimer(Int32.MaxValue - 1);
            }
            _auditTimer.AutoReset = false;
            // note that the audit timer should remain stopped until we start it after the first audit happens
            _shutdownInProgress = StatusResults.GetPendingResults(null, targetSystem);
        }
Пример #3
0
 /// <summary>
 /// Constructs a file buffers instance that uses the specified properties.
 /// </summary>
 /// <param name="baselineFilename">The baseline filename (full path).</param>
 /// <param name="startingSuffix">The starting suffix.</param>
 /// <param name="autoFlushFrequency">A <see cref="TimeSpan"/> indicating how often to autoflush the log files.</param>
 public RotatingFileBuffer(string baselineFilename, string startingSuffix, TimeSpan autoFlushFrequency)
 {
     _baselineFilename = baselineFilename;
     _startingSuffix   = startingSuffix;
     if (autoFlushFrequency > TimeSpan.Zero)
     {
         _timer           = new AmbientEventTimer(autoFlushFrequency);
         _timer.AutoReset = true;
         _timer.Elapsed  += Timer_Elapsed;
         _timer.Enabled   = true;
     }
     else // just create a default timer with nothing attached (so we still have something to dispose)
     {
         _timer = new AmbientEventTimer();
     }
 }
Пример #4
0
 /// <summary>
 /// Constructs a TimeWindowProcessingDistributionTracker.
 /// </summary>
 /// <param name="metrics">A <see cref="IAmbientServiceProfiler"/> to hook into to receive processor change events.</param>
 /// <param name="scopeNamePrefix">A <see cref="TimeSpan"/> indicating the size of the window.</param>
 /// <param name="windowPeriod">A <see cref="TimeSpan"/> indicating how often reports are desired.</param>
 /// <param name="onWindowComplete">An async delegate that receives a <see cref="IAmbientServiceProfile"/> at the end of each time window.</param>
 /// <param name="systemGroupTransform">A <see cref="Regex"/> string to transform the system into a system group.</param>
 public TimeWindowServiceProfiler(IAmbientServiceProfiler metrics, string scopeNamePrefix, TimeSpan windowPeriod, Func <IAmbientServiceProfile, Task> onWindowComplete, Regex?systemGroupTransform)
 {
     if (onWindowComplete == null)
     {
         throw new ArgumentNullException(nameof(onWindowComplete), "Time Window Collection is pointless without a completion delegate!");
     }
     _scopeNamePrefix = scopeNamePrefix;
     using (Rotate(metrics, windowPeriod, systemGroupTransform)) { }
     _timeWindowRotator          = new AmbientEventTimer(windowPeriod);
     _timeWindowRotator.Elapsed +=
         (sender, handler) =>
     {
         ProcessOrSingleTimeWindowServiceProfiler?oldAccumulator = Rotate(metrics, windowPeriod, systemGroupTransform);
         if (oldAccumulator != null)
         {
             Task t = onWindowComplete(oldAccumulator);
             t.Wait();
         }
     };
     _timeWindowRotator.AutoReset = true;
     _timeWindowRotator.Enabled   = true;
 }