【问题标题】:Is it possible to add performance monitor metrics to AppInsights with an ASP .NET Core app?是否可以使用 ASP .NET Core 应用程序向 AppInsights 添加性能监视器指标?
【发布时间】:2017-10-06 00:11:15
【问题描述】:
我们正在运行一个 ASP .NET 核心应用,并将其配置为将遥测数据发送到 AppInsights。我还想在支持 AppInsights 中的应用程序的服务器上收集 perf mon 计数器,例如内存和 CPU 使用率。这可能吗?我在 AppInsights 中使用我们的标准 .NET 应用程序配置了 perf mon 计数器,但看不到如何使用 .NET Core 对其进行配置。
【问题讨论】:
标签:
asp.net-core
performancecounter
azure-application-insights
【解决方案1】:
如果您的 ASP.NET Core 应用程序是在完整的框架 NET 4.5.1(及更高版本)下编译的,那么应该可以通过在代码中添加计数器来实现,例如:
Type perfModuleType = typeof(PerformanceCollectorModule);
PerformanceCollectorModule perfModule = (PerformanceCollectorModule)server.ApplicationServices.GetServices<ITelemetryModule>()
.FirstOrDefault(m => m.GetType() == perfModuleType);
perfModule.Counters.Add(
new PerformanceCounterCollectionRequest(
@"\.NET CLR Memory(??APP_CLR_PROC??)\# GC Handles", "GC Handles"));
如果它编译为纯 netcoreapp,则目前不支持。