我正在研究ASP.Net(非核心)WebAPI项目。为此,我希望能够通过捕获请求的遥测并查看每种请求类型花费多少时间来进行性能测试。
分析结果时,我注意到在Application Insights中记录的请求数量只是WebAPI请求数量的一小部分,仅为1/10甚至更少。我想捕获所有请求,以便为性能分析提供更合理的样本量,但是我对造成这种抽样的原因一无所知。
我查阅了以下文档:https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling
我在安装我们的应用程序的服务器上以及在开发计算机上从Visual Studio运行应用程序时都看到了完全相同的行为。两种安装都将遥测发送到不同的Application Insights实例,每个实例都在不同的Azure帐户上。
我从Microsoft咨询了此文档,以检查是否已提供采样:https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling#how-do-i-know-whether-sampling-is-in-operation
let startDateTime = todatetime("2019-03-25 14:00+1:00");
let endDateTime = todatetime("2019-03-25 14:15+1:00");
requests
| where timestamp between(startDateTime..endDateTime)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType
这将产生80%到100%之间的百分比。但是:
let startDateTime = todatetime("2019-03-25 14:00+1:00");
let endDateTime = todatetime("2019-03-25 14:15+1:00");
requests
| where timestamp between(startDateTime..endDateTime)
根据该时间段内我们应用程序处理的实际请求数,这只会产生我期望的记录数的一部分。这让我怀疑微软的抽样检测方法是否还能奏效。
我希望我们的大多数请求都将记录在Application Insights中。我也希望任何应用的采样都能响应我对ApplicationInsights.config中的设置所做的更改,但是其中的设置似乎被忽略了。我茫然为什么。
编辑:添加了ApplicationInsights.config的内容。这主要只是Visual Studio生成的样板内容:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<InstrumentationKey>censored</InstrumentationKey>
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/>
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
<MaxTelemetryItemsPerSecond>500</MaxTelemetryItemsPerSecond>
</Add>
</TelemetryProcessors>
<TelemetryInitializers>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureWebAppRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
<Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
</Add>
<Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector"/>
</TelemetryInitializers>
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
<Handlers>
<Add>System.Web.Handlers.TransferRequestHandler</Add>
<Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
<Add>System.Web.StaticFileHandler</Add>
<Add>System.Web.Handlers.AssemblyResourceLoader</Add>
<Add>System.Web.Optimization.BundleHandler</Add>
<Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
<Add>System.Web.Handlers.TraceHandler</Add>
<Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
<Add>System.Web.HttpDebugHandler</Add>
</Handlers>
</Add>
<Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector"></Add>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector"/>
</TelemetryModules>
</ApplicationInsights>