internal static void AddCoreServices(IServiceCollection services, IHealthRoot health) { services.TryAddSingleton <IReadOnlyCollection <IHealthOutputFormatter> >(provider => health.OutputHealthFormatters); services.TryAddSingleton <IHealth>(health); services.TryAddSingleton <IHealthRoot>(health); services.TryAddSingleton <HealthOptions>(health.Options); services.TryAddSingleton <IRunHealthChecks>(health.HealthCheckRunner); services.TryAddSingleton <AppMetricsHealthMarkerService, AppMetricsHealthMarkerService>(); }
public static IServiceCollection AddHealth(this IServiceCollection services, IHealthRoot health) { if (health == null) { throw new ArgumentNullException(nameof(health)); } AddCoreServices(services, health); return(services); }
public HealthHandler(IHealthRoot healthRoot) { _healthRoot = healthRoot; _formatter = _healthRoot.DefaultOutputHealthFormatter; _formatter = healthRoot.OutputHealthFormatters .OfType <HealthStatusTextOutputFormatter>() //.OfType<HealthStatusJsonOutputFormatter>() .SingleOrDefault(); if (_formatter == null) { throw new ArgumentException("Include App.Metrics.Health!", nameof(healthRoot)); } }
private static void Init() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.LiterateConsole() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); Health = AppMetricsHealth.CreateDefaultBuilder() .HealthChecks.AddCheck(new SampleHealthCheck()) .HealthChecks.AddProcessPrivateMemorySizeCheck("Private Memory Size", 200) .HealthChecks.AddProcessVirtualMemorySizeCheck("Virtual Memory Size", 200) .HealthChecks.AddProcessPhysicalMemoryCheck("Working Set", 200) .HealthChecks.AddPingCheck("google ping", "google.com", TimeSpan.FromSeconds(10)) .HealthChecks.AddHttpGetCheck("invalid http", new Uri("https://invalid-asdfadsf.com/"), 3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)) .HealthChecks.AddHttpGetCheck("github", new Uri("https://github.com/"), retries: 3, delayBetweenRetries: TimeSpan.FromMilliseconds(100), timeoutPerRequest: TimeSpan.FromSeconds(5)) .HealthChecks.AddHttpGetCheck("google", new Uri("https://google.com/"), TimeSpan.FromSeconds(1)) .HealthChecks.AddCheck("DatabaseConnected", () => new ValueTask <HealthCheckResult>(HealthCheckResult.Healthy("Database Connection OK"))) .HealthChecks.AddCheck( "DiskSpace", () => { var freeDiskSpace = GetFreeDiskSpace(); return(new ValueTask <HealthCheckResult>( freeDiskSpace <= 512 ? HealthCheckResult.Unhealthy("Not enough disk space: {0}", freeDiskSpace) : HealthCheckResult.Unhealthy("Disk space ok: {0}", freeDiskSpace))); }) .HealthChecks.AddSqlCheck("DB Connection", () => new SqliteConnection(ConnectionString), TimeSpan.FromSeconds(10)) .Build(); int GetFreeDiskSpace() { return(1024); } }
private static void Init() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.LiterateConsole() .WriteTo.Seq("http://*****:*****@"UseDevelopmentStorage=true"); var eventHubConnectionString = "todo event hub connection string"; var eventHubName = "todo event hub name"; var serviceBusConnectionString = "todo sb connection string"; var queueName = "todo queue name"; var topicName = "todo topic name"; Health = AppMetricsHealth.CreateDefaultBuilder() .HealthChecks.AddAzureBlobStorageConnectivityCheck("Blob Storage Connectivity Check", storageAccount) .HealthChecks.AddAzureBlobStorageContainerCheck("Blob Storage Container Check", storageAccount, containerName) .HealthChecks.AddAzureQueueStorageConnectivityCheck("Queue Storage Connectivity Check", storageAccount) .HealthChecks.AddAzureQueueStorageCheck("Queue Storage Check", storageAccount, "test") .HealthChecks.AddAzureDocumentDBDatabaseCheck("DocumentDB Database Check", documentDbDatabaseUri, documentDbUri, doucmentDbKey) .HealthChecks.AddAzureDocumentDBCollectionCheck("DocumentDB Collection Check", collectionUri, documentDbUri, doucmentDbKey) .HealthChecks.AddAzureTableStorageConnectivityCheck("Table Storage Connectivity Check", storageAccount) .HealthChecks.AddAzureTableStorageTableCheck("Table Storage Table Exists Check", storageAccount, "test") .HealthChecks.AddAzureEventHubConnectivityCheck("Service EventHub Connectivity Check", eventHubConnectionString, eventHubName) .HealthChecks.AddAzureServiceBusQueueConnectivityCheck("Service Bus Queue Connectivity Check", serviceBusConnectionString, queueName) .HealthChecks.AddAzureServiceBusTopicConnectivityCheck("Service Bus Topic Connectivity Check", serviceBusConnectionString, topicName) .Build(); }
public ReportSchedulerHostedService( IMetrics metrics, MetricsOptions options, IEnumerable <IReportMetrics> reporters, IHealthRoot healthRoot) { _metrics = metrics; _options = options; _healthRoot = healthRoot; var referenceTime = DateTime.UtcNow; _successCounter = new CounterOptions { Context = AppMetricsConstants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, Name = "report_success" }; _failedCounter = new CounterOptions { Context = AppMetricsConstants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, Name = "report_failed" }; foreach (var reporter in reporters) { _scheduledReporters.Add( new SchedulerTaskWrapper { Interval = reporter.FlushInterval, Reporter = reporter, NextRunTime = referenceTime }); } }
public static IHostBuilder ConfigureMetrics( this IHostBuilder hostBuilder, IHealthRoot health) { if (_healthBuilt) { throw new InvalidOperationException("HealthBuilder allows creation only of a single instance of IHealth"); } return(hostBuilder.ConfigureServices( (context, services) => { if (health.Options.ReportingEnabled && health.Reporters != null && health.Reporters.Any()) { services.AddHealthReportingHostedService(); } services.AddHealth(health); _healthBuilt = true; })); }
public HealthReporterBackgroundService( IHealthRoot healthRoot, TimeSpan checkInterval) { if (checkInterval == TimeSpan.Zero) { throw new ArgumentException("Must be greater than zero", nameof(checkInterval)); } _healthRoot = healthRoot ?? throw new ArgumentNullException(nameof(healthRoot)); var referenceTime = DateTime.UtcNow; foreach (var reporter in healthRoot.Reporters) { _scheduledReporters.Add( new SchedulerTaskWrapper { Interval = checkInterval, Reporter = reporter, NextRunTime = referenceTime }); } }
public ValuesController(IMetrics metrics, IHealthRoot health, ITracer tracer) { this.metrics = metrics; this.health = health; this.tracer = tracer; }