如何在 Application Insights 中禁用标准性能计数器?
How to disable standard performance counters in Application Insights?
Application Insights 中的标准性能计数器生成的量过多。我怎样才能禁用它们并只报告我自己的计数器 + 一些标准计数器(但不是全部),或者只是降低采样频率?
假设您使用的是最新的 .NET SDK,您可以通过 applicationinsights.config 文件配置性能计数器或采样率。
在Telemetry Processors section中,您可以通过添加设置自适应采样:
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
</Add>
</TelemetryProcessors>
设置具体的性能计数器可以在Telemetry Modules section (see also this blog post),例如:
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
<Counters>
<Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
</Counters>
</Add>
删除 PerfCounterCollector 类型将完全禁用性能计数器收集。
阿萨夫
在我的例子中,向 Counters 添加计数器不会影响默认计数器,因此报告了我的设置和默认设置。幸运的是,收集器是 open source 并且有一个明确的线索,你需要做什么才能删除它们。只需像这样定义一个空 DefaultCounters
:
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
<DefaultCounters/>
<Counters>
<Add PerformanceCounter="YOUR COUNTER"/>
</Counters>
</Add>
为 asp.netcore 用户添加此答案。如图所示修改您的 startup.cs。你有两个选择。首先完全禁用性能计数器。
public void ConfigureServices(IServiceCollection services)
{
var serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ImplementationType == typeof(PerformanceCollectorModule));
services.Remove(serviceDescriptor);
}
或第二次删除单个计数器,如果您以后需要,可以添加自己的计数器。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var modules = app.ApplicationServices.GetServices<ITelemetryModule>();
var perfModule = modules.OfType<PerformanceCollectorModule>().First();
perfModule.DefaultCounters.Clear();
}
Application Insights 中的标准性能计数器生成的量过多。我怎样才能禁用它们并只报告我自己的计数器 + 一些标准计数器(但不是全部),或者只是降低采样频率?
假设您使用的是最新的 .NET SDK,您可以通过 applicationinsights.config 文件配置性能计数器或采样率。
在Telemetry Processors section中,您可以通过添加设置自适应采样:
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
</Add>
</TelemetryProcessors>
设置具体的性能计数器可以在Telemetry Modules section (see also this blog post),例如:
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
<Counters>
<Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
</Counters>
</Add>
删除 PerfCounterCollector 类型将完全禁用性能计数器收集。
阿萨夫
在我的例子中,向 Counters 添加计数器不会影响默认计数器,因此报告了我的设置和默认设置。幸运的是,收集器是 open source 并且有一个明确的线索,你需要做什么才能删除它们。只需像这样定义一个空 DefaultCounters
:
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
<DefaultCounters/>
<Counters>
<Add PerformanceCounter="YOUR COUNTER"/>
</Counters>
</Add>
为 asp.netcore 用户添加此答案。如图所示修改您的 startup.cs。你有两个选择。首先完全禁用性能计数器。
public void ConfigureServices(IServiceCollection services)
{
var serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ImplementationType == typeof(PerformanceCollectorModule));
services.Remove(serviceDescriptor);
}
或第二次删除单个计数器,如果您以后需要,可以添加自己的计数器。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var modules = app.ApplicationServices.GetServices<ITelemetryModule>();
var perfModule = modules.OfType<PerformanceCollectorModule>().First();
perfModule.DefaultCounters.Clear();
}