Beispiel #1
0
        /// <inheritdoc />
        public async Task <GetStatsResult> GetStatsAsync(Context context)
        {
            try
            {
                GetStatsResult stats = await _innerICache.GetStatsAsync(context);

                GetStatsResult currentStats = GetStatsInternal();

                CounterSet counterSet = new CounterSet();
                if (stats.Succeeded)
                {
                    counterSet.Merge(stats.CounterSet, $"{_innerICache.GetType().Name}.");
                }

                if (currentStats.Succeeded)
                {
                    counterSet.Merge(currentStats.CounterSet, $"{nameof(DistributedCache)}.");
                }

                return(new GetStatsResult(counterSet));
            }
            catch (Exception ex)
            {
                return(new GetStatsResult(ex));
            }
        }
Beispiel #2
0
        private async Task <GetStatsResult> GetStatsInternalAsync(Context context)
        {
            try
            {
                var aggregateStats = new CounterSet();
                var cachestats     = _tracer.GetCounters();

                aggregateStats.Merge(cachestats);
                if (_writeThroughContentStore != null)
                {
                    GetStatsResult writeThrouStoreStats = await _writeThroughContentStore.GetStatsAsync(context);

                    if (writeThrouStoreStats.Succeeded)
                    {
                        aggregateStats.Merge(writeThrouStoreStats.CounterSet, "WriteThroughStore.");
                    }
                }

                return(new GetStatsResult(aggregateStats));
            }
            catch (Exception ex)
            {
                return(new GetStatsResult(ex));
            }
        }
        public override void GetStatsStop(Context context, GetStatsResult result)
        {
            if (_eventSource.IsEnabled())
            {
                _eventSource.GetStatsStop(result.Succeeded, result.ErrorMessage);
            }

            base.GetStatsStop(context, result);
        }
Beispiel #4
0
        public override void GetStatsStop(Context context, GetStatsResult result)
        {
            if (_eventSource.IsEnabled())
            {
                _eventSource.GetStatsStop(result.Succeeded, result.ErrorMessage);
            }

            _getStatsCallCounter.Completed(result.Duration.Ticks);

            base.GetStatsStop(context, result);
        }
        /// <inheritdoc />
        public async Task <Possible <string, Failure> > ShutdownAsync()
        {
            Contract.Requires(!IsShutdown);

            m_isShutdown = true;

            try
            {
                try
                {
                    GetStatsResult stats = await m_cache.GetStatsAsync(new Context(m_logger));

                    if (stats.Succeeded)
                    {
                        using (Stream fileStream = m_fileSystem.Open(m_statsFile, FileAccess.ReadWrite, FileMode.CreateNew, FileShare.None))
                        {
                            using (StreamWriter sw = new StreamWriter(fileStream))
                            {
                                foreach (KeyValuePair <string, long> stat in stats.CounterSet.ToDictionaryIntegral())
                                {
                                    await sw.WriteLineAsync($"{stat.Key}={stat.Value}");
                                }
                            }
                        }
                    }
                    else
                    {
                        m_logger.Debug($"Stats call failed {stats.ErrorMessage}");
                    }
                }
#pragma warning disable ERP022 // Unobserved exception in generic exception handler
                catch
                {
                }
#pragma warning restore ERP022 // Unobserved exception in generic exception handler

                BoolResult shutdownResult = await m_cache.ShutdownAsync(new Context(m_logger));

                if (shutdownResult.Succeeded)
                {
                    return(CacheId.ToString());
                }

                return(new CacheFailure(shutdownResult.ErrorMessage));
            }
            finally
            {
                Dispose();
            }
        }
Beispiel #6
0
        public virtual void GetStatsStop(Context context, GetStatsResult result)
        {
            TracerOperationFinished(context, result, $"{Name}.GetStats stop {result.DurationMs}ms result=[{result}]");

            if (result.Succeeded)
            {
                foreach (var counter in result.CounterSet.Counters)
                {
                    if (!string.IsNullOrWhiteSpace(counter.MetricName))
                    {
                        context.TrackTopLevelStatistic(counter.MetricName, counter.Value);
                    }
                }
            }
        }
Beispiel #7
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;
            return(ShutdownCall <MemoizationStoreTracer> .RunAsync(_tracer, context, async() =>
            {
                GetStatsResult stats = GetStatsInternal();
                if (!stats)
                {
                    context.Debug($"Get stats failed with error {stats.ErrorMessage}; Diagnostics {stats.Diagnostics}");
                }
                else
                {
                    context.Debug("DistributedCache Stats:");
                    stats.CounterSet.LogOrderedNameValuePairs(s => _tracer.Debug(context, s));
                }

                var innerCacheShutdown = await _innerICache.ShutdownAsync(context);
                var metadataCacheShutdown = await _metadataCache.ShutdownAsync(context);

                if (!innerCacheShutdown)
                {
                    // TODO: should print errors as well.
                    context.Error("Shutdown call on inner cache failed.");
                    return new BoolResult(innerCacheShutdown);
                }

                if (!metadataCacheShutdown)
                {
                    context.Error("Shutdown call on metadata cache failed.");
                    return new BoolResult(metadataCacheShutdown);
                }

                ShutdownCompleted = true;

                return BoolResult.Success;
            }));
        }
Beispiel #8
0
 public override void GetStatsStop(Context context, GetStatsResult result)
 {
     _getStatsCallCounter.Completed(result.Duration.Ticks);
     base.GetStatsStop(context, result);
 }