尝试在 asp net core 中配置 metrics.net

Trying to configure metrics.net in asp net core

我有一个 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 net core 中做一些类似的事情?

我们必须使用 Microsoft.AspnetCore.Owin 包中的 app.UseOwin 并将正确的中间件连接到管道。

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);
                })
            );

和像这样的 Engage 功能

  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);
        };
    }

.NET Standard port 个 Metrics.NET。 API 已按照 .net 核心方法重写了指标