private HealthCheckResult GetHealthCheck()
 {
     HealthCheck.Result result = HealthChecks.GetStatus().Results.First(r => r.Name == "Workload");
     Console.WriteLine(result.Check.IsHealthy);
     Console.WriteLine(result.Check.Message);
     return(result.Check);
 }
        public void InfluxReport_CanAddRecords_ForHealthCheck()
        {
            var config      = new InfluxConfig("localhost", "testdb");
            var writer      = new InfluxdbTestWriter(config); config.Writer = writer;
            var report      = new InfluxdbHttpReport(config);
            var context     = new DefaultMetricsContext("TestContext");
            var precision   = config.Precision ?? InfluxConfig.Default.Precision;
            var metricsData = context.DataProvider.CurrentMetricsData;

            HealthChecks.UnregisterAllHealthChecks();
            HealthChecks.RegisterHealthCheck("Health Check 1", () => HealthCheckResult.Healthy($"Healthy check!"));
            HealthChecks.RegisterHealthCheck("Health Check 2", () => HealthCheckResult.Unhealthy($"Unhealthy check!"));
            HealthChecks.RegisterHealthCheck("Health Check 3,tag3=key3", () => HealthCheckResult.Healthy($"Healthy check!"));
            HealthChecks.RegisterHealthCheck("Health Check 4,tag 4=key 4", () => HealthCheckResult.Healthy($"Healthy check!"));
            HealthChecks.RegisterHealthCheck("Name=Health Check 5,tag5=key5", () => HealthCheckResult.Healthy($"Healthy check!"));

            metricsData = context.DataProvider.CurrentMetricsData;
            report.RunReport(metricsData, () => HealthChecks.GetStatus(), CancellationToken.None);
            HealthChecks.UnregisterAllHealthChecks();             // unreg first in case something below throws
            writer.LastBatch.Should().HaveCount(5);

            var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);

            writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_1 ishealthy=True,message=""Healthy check!"" {expTime}");
            writer.LastBatch[1].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_2 ishealthy=False,message=""Unhealthy check!"" {expTime}");
            writer.LastBatch[2].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_3,tag3=key3 ishealthy=True,message=""Healthy check!"" {expTime}");
            writer.LastBatch[3].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_4,tag_4=key\ 4 ishealthy=True,message=""Healthy check!"" {expTime}");
            writer.LastBatch[4].ToLineProtocol(precision).Should().Be($@"health_checks,name=health\ check\ 5,tag5=key5 ishealthy=True,message=""Healthy check!"" {expTime}");
        }
示例#3
0
        /// <summary>
        /// Gets the health status and log it
        /// </summary>
        /// <param name="context">The context</param>
        public void RunHealthStatus(string context = null)
        {
            var hs     = HealthChecks.GetStatus();
            var report = new HealthStatusReport(context, _log, _printMode, _decimals);

            report.Report(hs);
        }
        public void ClearAllMonitors()
        {
            _healthMonitor.SetHealthFunction(COMPONENT, () => HealthCheckResult.Unhealthy());
            _healthMonitor.Dispose();
            bool isComponentStillRegisteredToHealthCheck = HealthChecks.GetStatus().Results.Any(_ => _.Name == COMPONENT);

            isComponentStillRegisteredToHealthCheck.ShouldBeFalse();
        }
        public async Task NoFallBackShouldNotHavMasterServiceHealth()
        {
            SetMockToReturnQueryNotFound(_masterService);
            SetMockToReturnHost(_originatingService);
            var nextHost = await GetServiceDiscovey.GetNextHost();

            HealthChecks.GetStatus().Results.Single(_ => _.Name == _originatingService).Check.IsHealthy.ShouldBeTrue();
            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == _masterService);
        }
        public void CreateSeviceDiscoveyWithoutGetNextHostNoServiceHealthShouldAppear()
        {
            SetMockToReturnHost(_masterService);
            SetMockToReturnQueryNotFound(_originatingService);
            var serviceDiscovey = GetServiceDiscovey;

            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == _masterService);
            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == _originatingService);
        }
示例#7
0
        public async Task CreateServiceDiscoveyWithoutGetNextHostNoServiceHealthShouldAppear()
        {
            SetMockToReturnHost(MasterService);
            SetMockToReturnServiceNotDefined(OriginatingService);
            var serviceDiscovey = GetServiceDiscovey();

            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == MasterService);
            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == OriginatingService);
        }
示例#8
0
        public async Task NoFallBackShouldNotHavMasterServiceHealth()
        {
            SetMockToReturnServiceNotDefined(MasterService);
            SetMockToReturnHost(OriginatingService);
            var nextHost = await GetServiceDiscovey().GetNextHost();

            HealthChecks.GetStatus().Results.Single(_ => _.Name == OriginatingService).Check.IsHealthy.ShouldBeTrue();
            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == MasterService);
        }
        public void HealthCheck_RegistryStatusIsHealthyIfAllChecksAreHealthy()
        {
            HealthChecks.UnregisterAllHealthChecks();

            HealthChecks.RegisterHealthCheck(new HealthCheck("ok", () => { }));
            HealthChecks.RegisterHealthCheck(new HealthCheck("another", () => HealthCheckResult.Healthy()));

            var status = HealthChecks.GetStatus();

            status.IsHealthy.Should().BeTrue();
            status.Results.Length.Should().Be(2);
        }
        public void HealthCheck_RegistryStatusIsFailedIfOneCheckFails()
        {
            HealthChecks.UnregisterAllHealthChecks();

            HealthChecks.RegisterHealthCheck(new HealthCheck("ok", () => { }));
            HealthChecks.RegisterHealthCheck(new HealthCheck("bad", () => HealthCheckResult.Unhealthy()));

            var status = HealthChecks.GetStatus();

            status.IsHealthy.Should().BeFalse();
            status.Results.Length.Should().Be(2);
        }
        public void HealthCheck_RegistryExecutesCheckOnEachGetStatus()
        {
            HealthChecks.UnregisterAllHealthChecks();
            int count = 0;

            HealthChecks.RegisterHealthCheck(new HealthCheck("test", () => { count++; }));

            count.Should().Be(0);

            HealthChecks.GetStatus();

            count.Should().Be(1);

            HealthChecks.GetStatus();

            count.Should().Be(2);
        }
 private static HealthCheckResult GetHealthResult()
 {
     return(HealthChecks.GetStatus().Results.First(_ => _.Name == COMPONENT).Check);
 }
示例#13
0
 private HealthCheckResult GetHealthResult()
 {
     return(HealthChecks.GetStatus().Results.First(o => o.Name == serviceContext).Check);
 }
 public void Init()
 {
     _workloadMetrics.Init();
     HealthChecks.GetStatus();
 }
示例#15
0
 public IHttpActionResult Get()
 {
     return(Ok(HealthChecks.GetStatus()));
 }
 public bool Healthy()
 {
     return(HealthChecks.GetStatus().IsHealthy);
 }