コード例 #1
0
 public void IncDefault_Int64()
 {
     for (var i = 0; i < _opIterations; i++)
     {
         _gaugeInt64.Inc();
     }
 }
コード例 #2
0
 public void IncDefault()
 {
     for (var i = 0; i < _opIterations; i++)
     {
         _gauge.Inc();
     }
 }
コード例 #3
0
        /// <summary>
        /// Tracks the number of in-progress operations taking place.
        ///
        /// Calling this increments the gauge. Disposing of the returned instance decrements it again.
        /// </summary>
        /// <remarks>
        /// It is safe to track the sum of multiple concurrent in-progress operations with the same gauge.
        /// </remarks>
        public static IDisposable TrackInProgress(this IGauge gauge)
        {
            if (gauge == null)
            {
                throw new ArgumentNullException(nameof(gauge));
            }

            gauge.Inc();

            return(new InProgressTracker(gauge));
        }
コード例 #4
0
    public void QueueBackgroundWorkItem(
        Func <CancellationToken, Task> workItem)
    {
        if (workItem == null)
        {
            throw new ArgumentNullException(nameof(workItem));
        }

        _workItems.Enqueue(workItem);
        _queuedItemsGauge.Inc();
        _signal.Release();
    }
コード例 #5
0
        public async Task Invoke(HttpContext context)
        {
            _inFlightGauge.Inc();

            try
            {
                await _next(context);
            }
            finally
            {
                _inFlightGauge.Dec();
            }
        }
コード例 #6
0
        public Task <ProcessedMessageStatus> QueueBackgroundWorkItem(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var taskCompletionStatus = new TaskCompletionSource <ProcessedMessageStatus>();

            _workItems.Enqueue(new QueueItem <T>(item, taskCompletionStatus));
            _elementsInQueue?.Inc();
            _totalMessages?.Inc();
            _signal.Release();
            ItemCount++;
            return(taskCompletionStatus.Task);
        }
コード例 #7
0
        private async Task PeriodicLicenseChecksAsync()
        {
            var consecutiveFailures = 0;
            var isFirstCheck        = true;

            do
            {
                logger.LogTrace("Performing license check");
                try
                {
                    await licenseValidator.ValidateLicenseAsync(licenseKey,
                                                                moduleInstanceName, hostName, hubName, DateTime.UtcNow, serviceStopping.Token);

                    logger.LogTrace("License is valid");
                    consecutiveLicenseCheckFailures.Set(0);
                    remainingConsecutiveLicenseCheckFailures.Set(maxConsecutiveCheckFailures);
                }
                catch (OperationCanceledException)
                {
                    logger.LogTrace("Canceled in-progress license check");
                }
                catch (Exception ex)
                {
                    consecutiveFailures++;
                    logger.LogCritical(ex, isFirstCheck
                        ? $"Startup license validation failed"
                        : $"Post-startup license validation failed {consecutiveFailures} consecutive time(s) of max {maxConsecutiveCheckFailures}");
                    consecutiveLicenseCheckFailures.Inc();
                    remainingConsecutiveLicenseCheckFailures.Dec();
                    if (isFirstCheck || consecutiveFailures > maxConsecutiveCheckFailures)
                    {
                        throw;
                    }
                }
                isFirstCheck = false;

                await Task.Delay(licenseCheckInterval, serviceStopping.Token);
            } while (!serviceStopping.IsCancellationRequested);
        }
コード例 #8
0
 public static void Inc(this IGauge gauge, double increment, DateTimeOffset timestamp)
 {
     gauge.Inc(increment, timestamp.ToUnixTime());
 }
コード例 #9
0
 public static void Inc(this IGauge <long> gauge, long increment, DateTimeOffset timestamp)
 {
     gauge.Inc(increment, timestamp.ToUnixTimeMilliseconds());
 }