You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MVC4应用部署在私有负载均衡后Application Insights遥测显示NA

问题排查与解决建议

可能原因及对应解决步骤

1. 应用池权限不足

服务器性能指标(CPU、内存)的采集需要应用进程具备读取系统性能计数器的权限。负载均衡后的生产环境中,IIS应用池默认身份(如ApplicationPoolIdentity)可能没有该权限:

  • 打开计算机管理 → 本地用户和组 → 组,找到Performance Monitor Users组,将应用池对应的身份(如果是自定义账户)或IIS AppPool\[你的应用池名称]添加到该组。
  • 若使用ApplicationPoolIdentity,也可直接通过本地安全策略赋予其“读取性能计数器”权限:打开本地安全策略 → 本地策略 → 用户权限分配,找到“从远程访问性能计数器”和“读取性能数据”,添加IIS AppPool\[你的应用池名称]。

2. 缺少性能计数器采集依赖包

MVC4项目若仅配置了连接字符串,可能未安装负责采集服务器遥测的SDK包:

  • 打开NuGet包管理器,安装Microsoft.ApplicationInsights.PerfCounterCollector和Microsoft.ApplicationInsights.Web包,确保版本与.NET Framework 4.x兼容。

3. 未显式启用服务器遥测模块

默认情况下,服务器遥测模块可能未被初始化。可以在Startup.cs中补充初始化代码:

[assembly: OwinStartup(typeof(DesignHub.WebMvc.Startup))]
public class Startup
{ 
    public void Configuration(IAppBuilder app)
    {
        string appInsightsConnectionString = ConfigurationManager.AppSettings["AppInsightsConnectionString"];

        // Configure Application Insights
        if (!string.IsNullOrEmpty(appInsightsConnectionString))
        {
            var telemetryConfig = TelemetryConfiguration.Active;
            telemetryConfig.ConnectionString = appInsightsConnectionString;
            
            // 显式初始化服务器遥测模块
            var serverTelemetryModule = new ServerTelemetryModule();
            serverTelemetryModule.Initialize(telemetryConfig);
        }
    }
}

同时检查ApplicationInsights.config文件是否包含以下配置节点,没有则添加:

<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.ServerTelemetryModule, Microsoft.AI.PerfCounterCollector" />

4. 性能计数器库损坏

部署后可能存在性能计数器注册异常,可尝试重建:

  • 以管理员身份打开命令提示符,执行lodctr /R重建系统性能计数器库。
  • 若仍有问题,执行%windir%\System32\lodctr.exe /m:Microsoft.ApplicationInsights.PerfCounterCollector.man手动注册App Insights相关计数器。

5. 网络端点访问限制

虽然请求遥测能正常推送,但需确认虚拟机可访问App Insights的 ingestion 端点(如dc.services.visualstudio.com):

  • 检查私有负载均衡器、防火墙或NSG规则,允许出站访问443端口到上述端点。
  • 若使用Azure私有链接,需确保已配置App Insights的私有链接资源。

6. 查看调试日志定位错误

启用App Insights调试日志,采集过程中的错误信息:

  • 在web.config中添加以下配置:
<system.diagnostics>
  <trace autoflush="true" />
  <sources>
    <source name="Microsoft.ApplicationInsights" switchValue="Verbose">
      <listeners>
        <add name="aiListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>
  • 之后在App Insights的**日志(Analytics)**中搜索PerformanceCounter相关错误,定位具体问题。

内容的提问来源于stack exchange,提问作者Mayank

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 21:42:46