/// <inheritdoc/>
        public HystrixHealthCounts GetHealthCounts()
        {
            // we put an interval between snapshots so high-volume commands don't
            // spend too much unnecessary time calculating metrics in very small time periods
            long lastTime    = lastHealthCountsSnapshot;
            long currentTime = dateTimeProvider.GetCurrentTimeInMilliseconds();

            if (((currentTime - lastTime) >= configurationService.GetMetricsHealthSnapshotIntervalInMilliseconds() || healthCountsSnapshot == null) &&
                Interlocked.CompareExchange(ref lastHealthCountsSnapshot, dateTimeProvider.GetCurrentTimeInMilliseconds(), lastTime) == lastTime)
            {
                // our thread won setting the snapshot time so we will proceed with generating a new snapshot
                // losing threads will continue using the old snapshot
                long success = counter.GetRollingSum(HystrixRollingNumberEvent.Success);
                long failure = counter.GetRollingSum(HystrixRollingNumberEvent.Failure); // fallbacks occur on this
                long timeout = counter.GetRollingSum(HystrixRollingNumberEvent.Timeout); // fallbacks occur on this

                // not used in dotnet version
                long threadPoolRejected = counter.GetRollingSum(HystrixRollingNumberEvent.ThreadPoolRejected);
                long semaphoreRejected  = counter.GetRollingSum(HystrixRollingNumberEvent.SemaphoreRejected);

                long totalCount      = failure + success + timeout + threadPoolRejected + semaphoreRejected;
                long errorCount      = failure + timeout + threadPoolRejected + semaphoreRejected;
                int  errorPercentage = 0;

                if (totalCount > 0)
                {
                    errorPercentage = (int)((double)errorCount / totalCount * 100);
                }

                healthCountsSnapshot = new HystrixHealthCounts(totalCount, errorCount, errorPercentage);
            }

            return(healthCountsSnapshot);
        }
Beispiel #2
0
 public long GetRollingCountThreadsExecuted()
 {
     return(counter.GetRollingSum(HystrixRollingNumberEvent.ThreadExecution));
 }