Symptom

Some users may prefer not to check all the default items listed in PowerServer’s health check pages at http://[Web-API-URL]/health-ui and http://[Web-API-URL]/health, as shown in the screenshot below. 

helth-ui-check


Environment
PowerServer 2022
PowerServer 2025


Resolution

Users can follow the steps below to extend the UserExtensions\HealthChecks\HealthChecksExtensions.cs file in the PowerServer C# Solution to control and select the health check items.

1. Add the following method HealthPredicate in the public static class HealthChecksExtensions to control the health check items to be monitored (by default, all items are checked).

private static bool HealthPredicate(HealthCheckRegistration ctx)
{
        var tags = new HashSet
         {
                // Checks on Network Status
                PowerServerConstants.HealthCheckTags.Network,

                // Checks whether the license is in normal state
                PowerServerConstants.HealthCheckTags.License,

                //Checks on Security Configuration
                PowerServerConstants.HealthCheckTags.Security,

                // Checks whether the database connection is in normal state
                PowerServerConstants.HealthCheckTags.Connection,

               //Checks on Database Performance
               PowerServerConstants.HealthCheckTags.Performance,

               //Checks on Notification Configuration
               PowerServerConstants.HealthCheckTags.Notification,
         };

         return ctx.Tags.Any(tag => tags.Contains(tag));
}

2. Modify the code under public static IApplicationBuilder UsePowerServerHealthChecks(this IApplicationBuilder app).

2.1) Change

endpoints.MapHealthChecks("/health");
into
endpoints.MapHealthChecks("/health", new HealthCheckOptions
{
    Predicate = HealthPredicate,
});
2.2) Change
Predicate = ctx => ctx.Tags.Intersect(PowerServerConstants.HealthCheckTags.All).Any(),
into
Predicate = HealthPredicate,
3. Based on your needs, comment the health check items listed in the HealthPredicate method from step 1 so that they are not checked in the health and health-ui pages.


Note
Please refer to the attached zip file for the HealthChecksExtensions.cs file before and after the modification.

Attachment
1
0