【问题标题】:Trying to configure metrics.net in asp net core尝试在asp net core中配置metrics.net
【发布时间】:2016-09-20 13:16:34
【问题描述】:

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

【问题讨论】:

  • Metric.net 还不支持 dotnet 核心。您只能在完整的框架中使用它。看这里docs.asp.netGitHub issue
  • @Kalten:您可以在(标准).NET Framework 上运行 ASP.NET Core。使用 Johan 的回答,我能够成功地为 Metrics.NET 配置 OWIN 适配器。

标签: c# asp.net-core metrics


【解决方案1】:

我们必须使用 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);
                })
            );

还有这样的参与功能

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

【讨论】:

  • 非常感谢!
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2019-02-20
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 2022-07-13
    相关资源
    最近更新 更多