public MetricsHelper(IMetrics metrics, CacheMetrics allowedMetrics) { MetricsObj = metrics ?? throw new ArgumentNullException(nameof(metrics)); AllowedMetrics = allowedMetrics; this.MetricsTags = new MetricTags("inst", typeof(TCacheInstance).Name.Split('.').Last()); }
public void Setup() { IEnumerable <MMetricWrapper> dummy = getDummyMetricWrapper(); mockOpr = new Mock <IBusinessOperationQuery <MMetricWrapper> >(); mockOpr.Setup(foo => foo.Apply(null, null)).Returns(dummy); mockCache = new Mock <CacheMetrics>() { CallBase = true }; cache = mockCache.Object; cache.SetOperation(mockOpr.Object); realCache = new CacheMetrics(); }
public static IServiceCollection AddMetricsToDistributedCache <TCacheInstance>(this IServiceCollection services, CacheMetrics allowedMetrics = CacheMetrics.HitRatio | CacheMetrics.AllTime | CacheMetrics.ErrorRatio) { services.TryAddSingleton( new AllowedMetrics <DistributedCacheWithMetrics <TCacheInstance> > { AllowedCacheMetrics = allowedMetrics }); if (services.All(d => d.ServiceType != typeof(DistributedCacheOptions <TCacheInstance>))) { throw new InvalidOperationException($"Unable to add metrics to distributed cache, because {typeof(DistributedCacheOptions<TCacheInstance>).FullName} not registered. Try to register normal distributed cache first."); } if (services.All(d => d.ServiceType != typeof(IMetrics))) { throw new InvalidOperationException($"Unable to add metrics to distributed cache, because {typeof(IMetrics).FullName} not registered. Try to register Metrics first."); } services.RemoveAll <IDistributedCache <TCacheInstance> >(); services.TryAddSingleton <IDistributedCache <TCacheInstance>, DistributedCacheWithMetrics <TCacheInstance> >(); return(services); }