Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4k stars 780 forks source link

healthcheck ui with error:Could not retrieve health checks data #383

Closed h821463015 closed 4 years ago

h821463015 commented 4 years ago

hi,when I use HealthCheckUI,the page get error:Could not retrieve health checks data

the startup.cs code: ` public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks()

            .AddUrlGroup(new Uri("http://www.baidu.com"), "baidu", HealthStatus.Unhealthy);
        services.AddHealthChecksUI();
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }
        //app.UseHttpsRedirection();
        app.UseHealthChecks("/health", new HealthCheckOptions()
        {
            Predicate = _ => true,
            ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
        });
        app.UseHealthChecksUI(setup => { setup.ApiPath = "/health"; setup.UIPath = "/healthchecks-ui"; });
        app.UseMvc();
    }`
CarlosLanderas commented 4 years ago

We need the whole configuration. Are you configuring endpoints with appsettings?

h821463015 commented 4 years ago

startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHealthChecks()

                .AddUrlGroup(new Uri("http://www.baidu.com"), "baidu", HealthStatus.Unhealthy);
            services.AddHealthChecksUI();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            //app.UseHttpsRedirection();
            app.UseHealthChecks("/health", new HealthCheckOptions()
            {
                Predicate = _ => true,
                ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
            });
            app.UseHealthChecksUI(setup => { setup.ApiPath = "/health"; setup.UIPath = "/healthchecks-ui"; });
            app.UseMvc();
        }
    }

appsetting

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "HealthChecksUI": {
    "HealthChecks": [
      {
        "Name": "health",
        "Uri": "https://localhost:30080/health"
      },
      {
        "Name": "a",
        "Uri": "http://www.baidu.com"
      }
    ],
    "Webhooks": [],
    "EvaluationTimeinSeconds": 10,
    "MinimumSecondsBetweenFailureNotifications": 60
  }
}
h821463015 commented 4 years ago

not support dontcore 2.2?

CarlosLanderas commented 4 years ago

Package versions 2.2.* are for net core 2.2

h821463015 commented 4 years ago

yes,I'm used the Package versions 2.2 in dotnet core 2.2 ,but it doesn't work

CarlosLanderas commented 4 years ago

You configuration is wrong. You are setting the UI Api backend to /health and the healthcheck segment to /health as well. I recommend you to check the samples section