/// <summary> /// Обработчик сообщения /// </summary> /// <param name="context"></param> /// <param name="reporter"></param> /// <returns></returns> public Task Invoke(HttpContext context, MetricReporter reporter) { var path = context.Request.Path.Value; if (path == "/metrics" || path == "/health") { // Call the next delegate/middleware in the pipeline return(_next(context)); } // Start the Timer using Stopwatch var watch = new Stopwatch(); watch.Start(); context.Response.OnCompleted(() => { // Stop the timer and get elapsed time watch.Stop(); long responseTimeForCompleteRequest = watch.ElapsedMilliseconds; reporter.RegisterRequest(); reporter.RegisterResponseTime(context.Response.StatusCode, context.Request.Method + ": " + path, watch.Elapsed); // Add the Response time information in the Item variable return(Task.CompletedTask); }); // Call the next delegate/middleware in the pipeline return(_next(context)); }
public async Task Invoke(HttpContext httpContext, MetricReporter reporter) { Metrics.CreateCounter("PathCounter", "Count request", new CounterConfiguration { LabelNames = new [] { "method", "endpoint" } }).WithLabels(httpContext.Request.Method, httpContext.Request.Path).Inc(); await _next(httpContext); }
/// <summary> /// Starts tests on the selected provider /// </summary> private IList <Metric> RunProviderTests(Type type, TestOptions options) { var reporter = new MetricReporter(); var provider = (DbProviderTest)Activator.CreateInstance(type); provider.Initialize(options, reporter); provider.RunTests(); return(reporter.Metrics); }
/// <summary> /// Called when the Service Fabric is opening the service (part of the standard life cycle) /// </summary> /// <param name="cancellationToken">A token to monitor for cancellation</param> /// <returns>A task that completes when the service is open</returns> protected override async Task OnOpenAsync(CancellationToken cancellationToken) { Guid traceId = Guid.NewGuid(); this.logger.OpenAsyncInvoked(traceId, ComponentName, this.GetType().Name); this.metricReporter?.Dispose(); this.metricReporter = new MetricReporter(traceId, this.logger, ComponentName, this.Context, this.Partition, this.MetricsCallback, TimeSpan.FromSeconds(15)); await this.metricReporter.StartAsync(traceId, cancellationToken).ConfigureAwait(false); await base.OnOpenAsync(cancellationToken).ConfigureAwait(false); }
/// <summary> /// Called when the Service Fabric is closing the service down (part of the standard life cycle) /// </summary> /// <param name="cancellationToken">A token to monitor for cancellation</param> /// <returns>A task that completes when the service is closed</returns> protected override async Task OnCloseAsync(CancellationToken cancellationToken) { Guid traceId = Guid.NewGuid(); this.logger.CloseAsyncInvoked(traceId, ComponentName, this.GetType().Name); if (this.metricReporter != null) { await this.metricReporter.StopAsync(traceId, cancellationToken).ConfigureAwait(false); this.metricReporter.Dispose(); this.metricReporter = null; } await base.OnCloseAsync(cancellationToken).ConfigureAwait(false); }
public OrderService(OrderContext orderContext , UserContext userContext , BucketRepository bucketRepository , PriceServiceClient pricingClient , WarehouseServiceClient warehouseServiceClient , RabbitMQMessageSender mqSender , MetricReporter metricReporter , IDistributedCache distributedCache) { _orderContext = orderContext; _userContext = userContext; _pricingClient = pricingClient; _warehouseServiceClient = warehouseServiceClient; _bucketRepository = bucketRepository; _mqSender = mqSender; _metricReporter = metricReporter; _distributedCache = distributedCache; }
public async Task Invoke(HttpContext context, MetricReporter reporter) { if (context.Request.Path.Value == "/metrics-text") { await _request.Invoke(context); return; } var sw = Stopwatch.StartNew(); try { await _request.Invoke(context); } finally { sw.Stop(); reporter.RegisterRequest(); reporter.RegisterResponseTime(context.Response.StatusCode, context.Request.Method, sw.Elapsed); } }
/// <summary> /// Called when the Service Fabric is aborting the current service (part of the standard life cycle) /// </summary> protected override void OnAbort() { Guid traceId = Guid.NewGuid(); this.logger.AbortInvoked(traceId, ComponentName, this.GetType().Name); using (var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3))) { try { this.metricReporter.StopAsync(traceId, tokenSource.Token).GetAwaiter().GetResult(); } catch (Exception e) { this.logger.Error(traceId, ComponentName, "Error stopping the metrics reporter or timed out", null, e); } this.metricReporter.Dispose(); this.metricReporter = null; } base.OnAbort(); }
public ResponseMetricMiddleware(RequestDelegate request, MetricReporter reporter) { _request = request ?? throw new ArgumentNullException(nameof(request)); _reporter = reporter ?? throw new ArgumentNullException(nameof(reporter)); }
/// <summary> /// Provider initialization /// </summary> public override void Initialize(TestOptions options, MetricReporter reporter) { base.Initialize(options, reporter); }
public CountRequestMiddleware(RequestDelegate next, MetricReporter reporter) { _next = next ?? throw new ArgumentNullException(nameof(next)); _reporter = reporter ?? throw new ArgumentNullException(nameof(reporter)); }
/// <summary> /// Provider initialization /// </summary> public override void Initialize(TestOptions options, MetricReporter reporter) { base.Initialize(options, reporter); }