Esempio n. 1
0
 public void IncDefault_Int64()
 {
     for (var i = 0; i < _opIterations; i++)
     {
         _gaugeInt64.Inc();
     }
 }
Esempio n. 2
0
 public void IncDefault()
 {
     for (var i = 0; i < _opIterations; i++)
     {
         _gauge.Inc();
     }
 }
Esempio n. 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));
        }
    public void QueueBackgroundWorkItem(
        Func <CancellationToken, Task> workItem)
    {
        if (workItem == null)
        {
            throw new ArgumentNullException(nameof(workItem));
        }

        _workItems.Enqueue(workItem);
        _queuedItemsGauge.Inc();
        _signal.Release();
    }
Esempio n. 5
0
        public async Task Invoke(HttpContext context)
        {
            _inFlightGauge.Inc();

            try
            {
                await _next(context);
            }
            finally
            {
                _inFlightGauge.Dec();
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 8
0
 public static void Inc(this IGauge gauge, double increment, DateTimeOffset timestamp)
 {
     gauge.Inc(increment, timestamp.ToUnixTime());
 }
 public static void Inc(this IGauge <long> gauge, long increment, DateTimeOffset timestamp)
 {
     gauge.Inc(increment, timestamp.ToUnixTimeMilliseconds());
 }