2016-09-20 15 views
1

私はasp.netコアWebアプリケーションを持っています。私はmetrics.netを使いたいと思います。asp.netコアでmetrics.netを設定しようとしています

前に、私はメトリックを設定して、このようなowin:

Metric.Config 
      .WithInternalMetrics() 
      .WithOwin(middleware => app.Use(middleware), config => config 
       .WithRequestMetricsConfig(c => c.WithErrorsMeter() 
               .WithActiveRequestCounter() 
               .WithPostAndPutRequestSizeHistogram() 
               .WithRequestTimer() 
              , new[] { 
                new Regex("(?i)^metrics"), 
                new Regex("(?i)^health"), 
                new Regex("(?i)^json") 
                } 
              ) 
       .WithMetricsEndpoint(endpointConfig => 
       { 
        endpointConfig 
         .MetricsTextEndpoint(enabled: false);        
       }) 
      ); 

は、どのように私は、ASPネットコアでいくつかの同様の操作を行うことができますか?

+0

Metric.netはまだdotnetコアをサポートしていません。完全なフレームワークでのみ使用できます。こちら[docs.asp.net](https://docs.asp.net/en/latest/fundamentals/owin.html)をご覧ください。 [GitHubの問題](https://github.com/etishor/Metrics.NET/issues/133) – Kalten

+0

@Kalten:ASP.NET Coreを(標準).NET Framework上で実行することができます。 Johanの答えを使用して、Metrics.NETのOWINアダプタを正常に設定できました。 –

答えて

1

app.UseOwinMicrosoft.AspnetCore.Owinパッケージから適切なミドルウェアをパイプラインに接続する必要があります。この

private static Func<IDictionary<string, object>, Task> Engage(dynamic middleware, Func<IDictionary<string, object>, Task> next) 
    { 
     return env => { 
      middleware.Initialize(next); 

      return middleware.Invoke(env); 
     }; 
    } 
+0

ありがとう! –

0

よう

Metric.Config.WithInternalMetrics() 
      .WithOwin(middleware => app.UseOwin(pipeline => pipeline(next => Engage(middleware, next))), config => config 
       .WithRequestMetricsConfig(c => c.WithAllOwinMetrics() 
              , new[] { 
                new Regex("(?i)^metrics"), 
                new Regex("(?i)^health"), 
                new Regex("(?i)^json") 
                } 
              ) 
       .WithMetricsEndpoint(endpointConfig => 
       { 
        endpointConfig 
         .MetricsJsonEndpoint(enabled: true) 
         .MetricsEndpoint(enabled: true) 
         .MetricsHealthEndpoint(enabled: true) 
         .MetricsTextEndpoint(enabled: false) 
         .MetricsPingEndpoint(enabled: false); 
       }) 
      ); 

とエンゲージ機能はMetrics.NETの.NET Standard portがあります。メトリックへのAPIは、.netコアのアプローチに従って書き直されました。

関連する問題