private void ConfigureHealth(IServiceCollection services) { IHealthChecksBuilder builder = services.AddHealthChecks(); string key = Configuration["ApplicationInsights:InstrumentationKey"]; builder.AddApplicationInsightsPublisher(key); services.Configure <HealthCheckPublisherOptions>(options => { options.Delay = TimeSpan.FromSeconds(10); }); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMvc(options => { options.Filters.Add <DomainNotificationFilter>(); options.EnableEndpointRouting = false; }).AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); //Work with Multi-Tenants services.AddMultiTenancy() .WithResolutionStrategy <HostTenantResolutionStrategy>() // .WithResolutionStrategy<HeaderTenantResolutionStrategy>() .WithStore(Module.Base.Bootstrap.GetTenantStoreType()); services.Configure <GzipCompressionProviderOptions>(x => x.Level = CompressionLevel.Optimal); services.AddResponseCompression(x => { x.Providers.Add <GzipCompressionProvider>(); }); services.Configure <KestrelServerOptions>(options => { options.AllowSynchronousIO = true; }); services.Configure <IISServerOptions>(options => { options.AllowSynchronousIO = true; }); if (PlatformServices.Default.Application.ApplicationName != "testhost") { IHealthChecksBuilder healthCheckBuilder = services.AddHealthChecks(); //500 mb healthCheckBuilder.AddProcessAllocatedMemoryHealthCheck(500 * 1024 * 1024, "Process Memory", tags: new[] { "self" }); //500 mb healthCheckBuilder.AddPrivateMemoryHealthCheck(1500 * 1024 * 1024, "Private memory", tags: new[] { "self" }); healthCheckBuilder.AddSqlServer(Configuration["ConnectionStrings:CustomerDB"], tags: new[] { "services" }); //dotnet add <Project> package AspNetCore.HealthChecks.Redis //healthCheckBuilder.AddRedis(Configuration["Data:ConnectionStrings:Redis"], tags: new[] {"services"}); //dotnet add <Project> package AspNetCore.HealthChecks.OpenIdConnectServer //healthCheckBuilder.AddIdentityServer(new Uri(Configuration["WizID:Authority"]), "SSO Wiz", tags: new[] { "services" }); //if (WebHostEnvironment.IsProduction()) //{ //dotnet add <Project> package AspNetCore.HealthChecks.AzureKeyVault //healthCheckBuilder.AddAzureKeyVault(options => //{ // options.UseKeyVaultUrl($"{Configuration["Azure:KeyVaultUrl"]}"); //}, name: "azure-key-vault",tags: new[] {"services"}); //} healthCheckBuilder.AddApplicationInsightsPublisher(); HealthChecksUIBuilder healthCheck = services.AddHealthChecksUI(setupSettings: setup => { setup.AddWebhookNotification("Teams", Configuration["Webhook:Teams"], payload: File.ReadAllText(Path.Combine(".", "MessageCard", "ServiceDown.json")), restorePayload: File.ReadAllText(Path.Combine(".", "MessageCard", "ServiceRestore.json")), customMessageFunc: report => { var failing = report.Entries.Where(e => e.Value.Status == HealthChecks.UI.Core.UIHealthStatus.Unhealthy); return($"{AppDomain.CurrentDomain.FriendlyName}: {failing.Count()} healthchecks are failing"); } ); }).AddInMemoryStorage(); } if (!WebHostEnvironment.IsProduction()) { services.AddOpenApiDocument(document => { document.DocumentName = "v1"; document.Version = "v1"; document.Title = "Whitelabel API"; document.Description = "API de Whitelabel"; document.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT")); document.AddSecurity("JWT", Enumerable.Empty <string>(), new OpenApiSecurityScheme { Type = OpenApiSecuritySchemeType.ApiKey, Name = HeaderNames.Authorization, Description = "Token de autenticação via SSO", In = OpenApiSecurityApiKeyLocation.Header }); }); } services.AddAutoMapper(typeof(Startup)); services.AddHttpContextAccessor(); services.AddApplicationInsightsTelemetry(); RegisterServices(services); }