AspNetCore.Diagnostics.HealthChecks icon indicating copy to clipboard operation
AspNetCore.Diagnostics.HealthChecks copied to clipboard

Group by tags when set by appsettings

Open devbrsa opened this issue 5 years ago • 1 comments
trafficstars

Hi,

I was wondering a way to group by tags in the UI using the appsettings.json like below.

"HealthChecksUI": {
    "HealthChecks": [
      {
        "Name": "WebApp",
        "Uri": "https://localhost:5001",
        "Tags": "dev",
        "Dependencies": [
          {
            "Name": "WebService1",
            "Uri": "https://localhost:5002",
            "Tags": "dev"
          },
          {
            "Name": "WebService2",
            "Uri": "https://localhost:5003",
            "Tags": "dev"
          }
        ]
      }
    ]
  }

The goal is to group by the tag name having the UI reflected as well.

image

Like this picture, but having a feature where it could be set everything through appsettings.json.

The AddUrlGroup kind "hardcodes" the dependencies, and ideally to have a dynamic/external configuration over appsettings, such parent-child (as dependencies).

Is something on the roadmap or workaround?

Thanks in advanced.

devbrsa avatar Mar 13 '20 20:03 devbrsa

You can simply do it yourself. Just create new section in your appsettings:

"HealthChecks": {
  "Services": [
    {
          "Name": "WebService1",
          "Uri": "https://localhost:5002",
          "Tag": "dev"
    }
  ]
},

Map it to class: var hcSection = Configuration.GetSection("HealthChecks:Services").Get<HealthCheckConfig[]>();

And use addUrlGroup:

  var hc = services.AddHealthChecks()
      .AddSqlServer(Configuration["Database:Connection"]);

  var hcSection = Configuration.GetSection("HealthChecks:Services").Get<HealthCheckConfig[]>();

  foreach (var service in hcSection)
  {
      hc.AddUrlGroup(new Uri(service.Uri), service.Name, HealthStatus.Unhealthy, new[] { service.Tag });
  }

kbzowski avatar Mar 20 '22 14:03 kbzowski