【问题标题】:Azure Application Insights On Azure Service Fabric with Performance Counter带有性能计数器的 Azure Service Fabric 上的 Azure Application Insights
【发布时间】:2021-02-06 20:13:12
【问题描述】:

在现有的 Azure Service Fabric 实例上,最近使用以下代码合并了“Azure Application Insights”

 return new WebHostBuilder().UseHttpSys()
                            .ConfigureServices(
                                services => services
                                    .AddSingleton<StatelessServiceContext>(serviceContext)
                                    .AddSingleton<ServiceFabricAppContext>(new ServiceFabricAppContext(){
                                            NodeName = serviceContext.NodeContext.NodeName,
                                            ServiceHostIP=serviceContext.NodeContext.IPAddressOrFQDN,
                                            ServiceHostPort=FabricRuntime.GetActivationContext().GetEndpoints()[0].Port
                                    } )
                                        .AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))) // Azure Service Fabric Telemetry Initializer
                            .UseContentRoot(Directory.GetCurrentDirectory())
                               .UseApplicationInsights()
                            .UseStartup<Startup>()
                            .UseEnvironment(environment)
                            .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                            .UseUrls(url)
                            .Build();

基本上在一行附加代码的下方添加,即,

 .AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))

以下是添加的附加包,

 <PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric.Native" Version="2.1.1" /> 
 <PackageReference Include="Microsoft.ServiceFabric.Diagnostics.Internal" Version="4.1.417" /> 

目前在 AzureApplicationInsights => 日志下,只有“requests”表具有数据,而其他必需表尤其是“performanceCounters”为空。

需要做什么/配置,以便已经连接的 Azure 应用程序洞察实例可以记录性能计数器详细信息,例如托管 .Net Core 2.1 Web Api 应用程序的现有服务结构节点的 CPU、内存等?

用于获取性能计数器的代码:

using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector;

public IServiceProvider ConfigureServices(IServiceCollection services)
 {
   var aiOptions = new  Microsoft.ApplicationInsights.AspNetCore.Extensions
  .ApplicationInsightsServiceOptions();

  aiOptions.EnableAdaptiveSampling = false;
  aiOptions.EnableQuickPulseMetricStream = true;
  aiOptions.InstrumentationKey = "cxxxxxx4-2xx6-xxx1-axxf-071xxxxxxxb";
  services.AddApplicationInsightsTelemetry(aiOptions);

// The following configures PerformanceCollectorModule.
services.ConfigureTelemetryModule<PerformanceCollectorModule>((module) =>
{
    // the application process name could be "dotnet" for ASP.NET Core self-hosted applications.
    module.Counters.Add(new PerformanceCounterCollectionRequest(
    @"\Process([**_dotnet_**])\Page Faults/sec", "DotnetPageFaultsPerfSec")); //not sure "dotnet" is right value here?
});

  //Add MVC
  services.AddMvcCore(options =>
  {
    options.Filters.Add(new 
    LoggingFilter(_container.GetInstance<IMemoryCache>()));
  });
 }

【问题讨论】:

    标签: azure azure-service-fabric azure-application-insights azure-monitoring


    【解决方案1】:

    要从集群节点获取遥测数据,您需要将 OMS 代理部署到每个节点。 确保使用 separate 日志分析存储部署 Application Insights,以便您可以对两个数据集使用相同的存储。

    更多信息here

    【讨论】:

    • 如果没有代理,我们不能用它实现“代码”吗? docs.microsoft.com/en-us/azure/azure-monitor/app/…
    • afaik 您需要代理收集有关节点的详细信息并将其上传到 Log Analytics 或使用 WAD
    • 根据docs.microsoft.com/en-us/azure/azure-monitor/app/…,Application Insights Agent 目前仅支持 .Net IIS 托管的应用程序。
    • 我认为您正在将应用程序遥测与操作系统遥测混合在一起。代理/虚拟机扩展只会收集机器信息,而不是应用程序信息。应用程序信息来自您的代码(您已经准备好了)。
    • 我认为你是对的,我将应用程序遥测与操作系统遥测混合在一起。其实我想知道什么具体限制了SF集群节点的负载? Azure 应用程序支持了解节点中的 cpu、内存使用情况的最佳选择是什么?
    猜你喜欢
    • 2017-12-22
    • 2018-01-05
    • 1970-01-01
    • 2019-02-18
    • 2017-01-27
    • 2019-11-30
    • 2017-06-13
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多