public static IHealthCheckFactory RegisterPingHealthCheck( this IHealthCheckFactory factory, string name, string host, TimeSpan timeout, bool degradedOnError = false) { factory.Register( name, async() => { try { var ping = new Ping(); var result = await ping.SendPingAsync(host, (int)timeout.TotalMilliseconds).ConfigureAwait(false); return(result.Status == IPStatus.Success ? HealthCheckResult.Healthy($"OK. {host}") : HealthCheckResultOnError($"FAILED. {host} ping result was {result.Status}", degradedOnError)); } catch (Exception ex) { return(degradedOnError ? HealthCheckResult.Degraded(ex) : HealthCheckResult.Unhealthy(ex)); } }); return(factory); }
public static IHealthCheckFactory RegisterHttpGetHealthCheck( this IHealthCheckFactory factory, string name, Uri uri, TimeSpan timeout, CancellationToken token = default(CancellationToken)) { factory.Register( name, async() => { using (var tokenWithTimeout = CancellationTokenSource.CreateLinkedTokenSource(token)) { tokenWithTimeout.CancelAfter(timeout); var response = await HttpClient.GetAsync(uri, tokenWithTimeout.Token).ConfigureAwait(false); return(response.IsSuccessStatusCode ? HealthCheckResult.Healthy($"OK. {uri}") : HealthCheckResult.Unhealthy($"FAILED. {uri} status code was {response.StatusCode}")); } }); return(factory); }
/// <summary> /// Registers a health check on the process confirming that the current amount of physical memory is below the /// threshold. /// </summary> /// <param name="factory">The health check factory where the health check is registered.</param> /// <param name="name">The name of the health check.</param> /// <param name="thresholdBytes">The physical memory threshold in bytes.</param> /// <returns>The health check factory instance</returns> public static IHealthCheckFactory RegisterProcessPhysicalMemoryHealthCheck(this IHealthCheckFactory factory, string name, long thresholdBytes) { factory.Register(name, () => { var currentSize = Process.GetCurrentProcess().WorkingSet64; return(Task.FromResult(currentSize <= thresholdBytes ? HealthCheckResult.Healthy($"OK. {thresholdBytes} bytes") : HealthCheckResult.Unhealthy($"FAILED. {currentSize} > {thresholdBytes}"))); }); return(factory); }
/// <summary> /// Registers a health check on the process confirming that the current amount of virtual memory is below the /// threshold. /// </summary> /// <param name="factory">The health check factory where the health check is registered.</param> /// <param name="name">The name of the health check.</param> /// <param name="thresholdBytes">The virtual memory threshold in bytes.</param> /// <param name="degradedOnError"> /// WHen the check fails, if true, create a degraded status response. /// Otherwise create an unhealthy status response. (default: false) /// </param> /// <returns>The health check factory instance</returns> public static IHealthCheckFactory RegisterProcessVirtualMemorySizeHealthCheck( this IHealthCheckFactory factory, string name, long thresholdBytes, bool degradedOnError = false) { factory.Register( name, () => { var currentSize = Process.GetCurrentProcess().VirtualMemorySize64; return(Task.FromResult( currentSize <= thresholdBytes ? HealthCheckResult.Healthy($"OK. {thresholdBytes} bytes") : HealthCheckResultOnError($"FAILED. {currentSize} > {thresholdBytes} bytes", degradedOnError))); }); return(factory); }
public static IHealthCheckFactory RegisterPingHealthCheck( this IHealthCheckFactory factory, string name, string host, TimeSpan timeout) { factory.Register( name, async() => { var ping = new Ping(); var result = await ping.SendPingAsync(host, (int)timeout.TotalMilliseconds).ConfigureAwait(false); return(result.Status == IPStatus.Success ? HealthCheckResult.Healthy($"OK. {host}") : HealthCheckResult.Unhealthy($"FAILED. {host} ping result was {result.Status}")); }); return(factory); }
public DefaultAdvancedMetrics( ILogger <DefaultAdvancedMetrics> logger, AppMetricsOptions options, IClock clock, IMetricsFilter globalFilter, IMetricsRegistry registry, IHealthCheckFactory healthCheckFactory) { if (options == null) { throw new ArgumentNullException(nameof(options)); } GlobalFilter = globalFilter ?? new DefaultMetricsFilter(); Clock = clock; _logger = logger; _registry = registry; _healthCheckFactory = healthCheckFactory; }
public HealthCheckService(IHealthCheckFactory healthCheckFactory, IHealthCheckResponseBuilder healthCheckResponseBuilder) { this._healthCheckFactory = healthCheckFactory; this._healthCheckResponseBuilder = healthCheckResponseBuilder; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultHealthProvider" /> class. /// </summary> /// <param name="metrics">Metrics instance to record health results</param> /// <param name="logger">The logger.</param> /// <param name="healthCheckFactory">The health check factory.</param> public DefaultHealthProvider(Lazy <IMetrics> metrics, ILogger <DefaultHealthProvider> logger, IHealthCheckFactory healthCheckFactory) { _metrics = metrics; _logger = logger; _healthCheckFactory = healthCheckFactory ?? new NoOpHealthCheckFactory(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultHealthProvider" /> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="healthCheckFactory">The health check factory.</param> public DefaultHealthProvider(ILogger <DefaultHealthProvider> logger, IHealthCheckFactory healthCheckFactory) { _logger = logger; _healthCheckFactory = healthCheckFactory ?? new NoOpHealthCheckFactory(); }
#pragma warning disable SA1008, SA1009 public static IHealthCheckFactory RegisterMetricCheck( this IHealthCheckFactory factory, string name, ApdexOptions options, Func <ApdexValue, (string message, bool result)> passing,