0
votes

On existing Azure Service Fabric Instance, recently incorporated the "Azure Application Insights" using below code

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

Basically added just below one line of additional code ie.,

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

Below are additional packages added,

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

Right now under AzureApplicationInsights => logs, only "requests" table having data where as other required tables especially "performanceCounters" is empty.

What needs to be done/configured, so that already wired Azure Application insights instance can record performance Counters details like CPU, memory etc of existing service fabric nodes, which are hosting .Net Core 2.1 Web Api application?

Code used to get performance counters:

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

enter image description here

1

1 Answers

0
votes

To get telemetry from the cluster nodes, you'll need to deploy the OMS agent to each node. Make sure to deploy Application Insights with a separate log analytics store, so you can use the same store for both data sets.

More info here.