private void ConfigureHealth(IServiceCollection services) { services.AddHealthChecks(checks => { checks .AddUrlCheck(Configuration["SteamApiOptions:BaseUrl"], response => { var status = response.StatusCode == System.Net.HttpStatusCode.NotFound ? CheckStatus.Healthy : CheckStatus.Unhealthy; return(new ValueTask <IHealthCheckResult>(HealthCheckResult.FromStatus(status, "Steam API base URL reachable."))); } ); // Use feature toggle to add this functionality var feature = services.BuildServiceProvider().GetRequiredService <AdvancedHealthFeature>(); if (feature.FeatureEnabled) { checks.AddHealthCheckGroup( "memory", group => group .AddPrivateMemorySizeCheck(200000000) // Maximum private memory .AddVirtualMemorySizeCheck(3000000000000) .AddWorkingSetCheck(200000000), CheckStatus.Unhealthy ); } }); }
public static async ValueTask <IHealthCheckResult> DefaultUrlCheck(HttpResponseMessage response) { var status = response.IsSuccessStatusCode ? CheckStatus.Healthy : CheckStatus.Unhealthy; var data = new Dictionary <string, object> { { "url", response.RequestMessage.RequestUri.ToString() }, { "status", (int)response.StatusCode }, { "reason", response.ReasonPhrase }, { "body", await response.Content?.ReadAsStringAsync() } }; return(HealthCheckResult.FromStatus(status, $"status code {response.StatusCode} ({(int) response.StatusCode})", data)); }
public static async ValueTask <IHealthCheckResult> DefaultUrlCheck(HttpResponseMessage response) { // REVIEW: Should this be an explicit 200 check, or just an "is success" check? var status = response.StatusCode == HttpStatusCode.OK ? CheckStatus.Healthy : CheckStatus.Unhealthy; var data = new Dictionary <string, object> { { "url", response.RequestMessage.RequestUri.ToString() }, { "status", (int)response.StatusCode }, { "reason", response.ReasonPhrase }, { "body", await response.Content?.ReadAsStringAsync() } }; return(HealthCheckResult.FromStatus(status, $"UrlCheck({response.RequestMessage.RequestUri}): status code {response.StatusCode} ({(int)response.StatusCode})", data)); }
public ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) { CheckStatus status = CheckStatus.Unknown; string description = "UNKNOWN"; try { using (var checkConnection = new MySql.Data.MySqlClient.MySqlConnection(_connectionString)) { checkConnection.Open(); status = checkConnection.State == System.Data.ConnectionState.Open ? CheckStatus.Healthy : CheckStatus.Unhealthy; } return(new ValueTask <IHealthCheckResult>(HealthCheckResult.FromStatus(status, description))); } catch (Exception e) { return(new ValueTask <IHealthCheckResult>(HealthCheckResult.FromStatus(CheckStatus.Unhealthy, $"Exception {e.Message}"))); } }
public static HealthCheckBuilder AddMaxValueCheck <T>(this HealthCheckBuilder builder, string name, T maxValue, Func <T> currentValueFunc, TimeSpan cacheDuration) where T : IComparable <T> { Guard.ArgumentNotNull(nameof(builder), builder); Guard.ArgumentNotNullOrEmpty(nameof(name), name); Guard.ArgumentNotNull(nameof(currentValueFunc), currentValueFunc); builder.AddCheck(name, () => { var currentValue = currentValueFunc(); var status = currentValue.CompareTo(maxValue) <= 0 ? CheckStatus.Healthy : CheckStatus.Unhealthy; return(HealthCheckResult.FromStatus( status, $"max={maxValue}, current={currentValue}", new Dictionary <string, object> { { "max", maxValue }, { "current", currentValue } } )); }, cacheDuration); return(builder); }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default) { var sisStorageOk = await _advertStorageService.HealthCheckAsync(); return(HealthCheckResult.FromStatus(sisStorageOk ? CheckStatus.Healthy : CheckStatus.Unhealthy, "")); }
public ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) => new ValueTask <IHealthCheckResult>(HealthCheckResult.FromStatus(_serviceProvider == null ? CheckStatus.Unhealthy : CheckStatus.Healthy , "Dependency Injection test"));
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) { var isServiceOK = await service.CheckHealthAsync(); return(HealthCheckResult.FromStatus(isServiceOK ? CheckStatus.Healthy : CheckStatus.Unhealthy, "")); }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = new CancellationToken()) { var isStorageOk = await _storageService.CheckHealthAsync(); return(HealthCheckResult.FromStatus(isStorageOk ? CheckStatus.Healthy : CheckStatus.Unhealthy, "")); }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) { var isDynamoDBHealthy = await _advertServiceStore.CheckHealthAsync(); return(HealthCheckResult.FromStatus(isDynamoDBHealthy ? CheckStatus.Healthy : CheckStatus.Unhealthy, "")); }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) { var isStorageOk = await _repository.CheckHealthAsync(); return(HealthCheckResult.FromStatus(isStorageOk ? CheckStatus.Healthy : CheckStatus.Unhealthy, "")); }
public ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) { return(new ValueTask <IHealthCheckResult>(HealthCheckResult.FromStatus(CheckStatus.Healthy, $"Status message: alive"))); }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default) { var isStorageOk = await service.CheckHealthAsync(); return(HealthCheckResult.FromStatus(isStorageOk ? CheckStatus.Healthy : CheckStatus.Unhealthy, string.Empty)); }