microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

Azure Application Insights - Collecting Performance Counter From Azure Service Fabric Nodes Using Azure Application Insights Fails #2101

Closed TestUser0811 closed 3 years ago

TestUser0811 commented 4 years ago

Need to get Performance counter details like CPU, Memory of Azure Service Fabric nodes using Azure Application insights, to understand what specifically limits the load on the Azure SF cluster.

As per link, modified "ConfigureServices" method in our Startup.cs class.

Note: the code shown below is taken from .Netcore2.1 Web API project deployed on Azure service fabric cluster

 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>()));
    });
  }

Also edited .csproj to add the following line

   <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.3.0" />

Still 'PerformanceCounter' table on Azure Application Insights remains empty. What needs done? What I'm missing?

image

image

cijothomas commented 4 years ago

https://docs.microsoft.com/en-us/azure/azure-monitor/app/performance-counters#performance-counters-in-aspnet-core-applications

TestUser0811 commented 4 years ago

@cijothomas,

  1. Code taken from .Net Core2.1 Web API application hosted on Azure service fabric, services.ConfigureTelemetryModule((module) => {
    module.Counters.Add(new PerformanceCounterCollectionRequest( @"\Process([dotnet])\Page Faults/sec", "DotnetPageFaultsPerfSec")); //not sure "dotnet" is right value here? });

  2. BTW data shown on 'PerformanceCounter' table of Azure Application Insights are application related or infrastructure related?

  3. While trying out with "Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" encountering obsolete warning as shown in the attached image, how to overcome?

image

cijothomas commented 4 years ago

Please check the doc link I shared above. Perfcounters are not supported in Asp.Net Core applications.

TestUser0811 commented 4 years ago

@cijothomas,

But I can able to get 'Perfcounters' from Asp.Net Core 2.1 application but after upgrading "Microsoft.ApplicationInsights.AspNetCore" from Version="2.3.0" to Version="2.8.2"

With below code,

   public IServiceProvider ConfigureServices(IServiceCollection services)
     { 
          var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
          aiOptions.EnableAdaptiveSampling = false;
          aiOptions.EnableQuickPulseMetricStream = true;
          aiOptions.InstrumentationKey = "XXXXX-XXX-XXX-a97xxxxxxxxxxb";
         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"));
        });

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

Edited csproj to add,

   <PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.15.0" />
   <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />

Screenshot from Application Insight Instance,

image

TestUser0811 commented 4 years ago

@cijothomas,

Any update? Is the above approach, right approach to get performance counters from .net core2.1 webapi project which inturn runs on Azure SF cluster? Getting performance counters using the approach I have mentioned above, is reliable? Please clarify.

cijothomas commented 4 years ago

There is limited support for perf counters in Asp.Net Core. Are you seeing any perf counters at all? or not seeing the ones you configure additionally?

TestUser0811 commented 4 years ago

With Microsoft.ApplicationInsights.AspNetCore Version="2.8.2", I'm getting below performance counters like "Available Bytes", "% Processor Time" etc (attached image for your reference). Not sure these performance counter values are reliable, as they are retrieved by Aps.net core sdk but not by dedicated oms agents. Are performance counter values retrieved by Asp.Net Core reliable?

My requirement is to get basic performance counters like CPU & Memory utilization by Asp.Net Core web api deployed on each Azure service fabric cluster nodes, any additional or custom performance counters not required for me at this moment.

image

cijothomas commented 4 years ago

Your screenshot shows you are already getting performance counters. So what is the question?

TestUser0811 commented 4 years ago

monitoring the system from within the system using Asp.Net Core, is right approach?

cijothomas commented 4 years ago

monitoring the system from within the system using Asp.Net Core, is right approach?

I cannot offer any official guidance on that part. Here's what I know: PerfCounters are published for a lot of "system" things like Memory, Network, and also for Application specific like "Asp.Net, Process CPU" etc. You can query/ready perfCounters either from Application or from an agent. Its quite likely multiples app read the same data if they run in same host machine - in those cases collecting it via agent might be most efficient. Application Insights SDK support reading perf counters (some limitations aside) - its upto you to decide if you want to leverage that or use an agent based approach.

If you are most interested in knowing about .NET Runtime things like (GC pressure, heap size etc), it may be best to use EventCounters. https://docs.microsoft.com/en-us/azure/azure-monitor/app/eventcounters

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.