private static ICounter GetCounter <T>(this ICounterProvider provider, bool distributed) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } return(provider.GetCounter(TypeNameHelper.GetTypeDisplayName(typeof(T)), distributed)); }
public static ICounter GetDistributedCounter <T>(this ICounterProvider provider) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } return(provider.GetCounter <T>(distributed: true)); }
public static ICounter GetLocalCounter(this ICounterProvider provider, string name) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } return(provider.GetCounter(name, distributed: false)); }
public override Task CheckHealthAsync(HealthCheckContext context, CounterCheckSettings settings) { var counter = _counterProvider.GetCounter(settings.Name, settings.Distributed); if (settings.HasReachedErrorThreshold(counter.Value)) { context.Fail( $"Counter {settings.Name} reach the threshold of {settings.ErrorThreshold} for {counter.Value}", properties: new Dictionary <string, object> { { "counter", counter.Value }, { "warning_threshold", settings.WarningThreshold }, { "error_threshold", settings.ErrorThreshold } }); } else if (settings.HasReachedWarningThreshold(counter.Value)) { context.Warn( properties: new Dictionary <string, object> { { "counter", counter.Value }, { "warning_threshold", settings.WarningThreshold }, { "error_threshold", settings.ErrorThreshold } }); } else { context.Succeed( properties: new Dictionary <string, object> { { "counter", counter.Value }, { "warning_threshold", settings.WarningThreshold }, { "error_threshold", settings.ErrorThreshold } }); } return(TaskCache.CompletedTask); }
public async Task OnGetAsync() { CounterModel = await _counterProvider.GetCounter(); }