@Override
    protected void doHealthCheck(final Health.Builder builder) {
        FunctionUtils.doAndHandle(bldr -> {
            val statistics = getStatistics();
            bldr.withDetail("name", getName());
            if (statistics == null || statistics.length == 0) {
                bldr.outOfService().withDetail("message", "Cache statistics are not available.");
                return;
            }

            val statuses = Arrays.stream(statistics)
                .map(this::status)
                .collect(Collectors.toSet());

            if (statuses.contains(Status.OUT_OF_SERVICE)) {
                bldr.outOfService();
            } else if (statuses.contains(Status.DOWN)) {
                bldr.down();
            } else if (statuses.contains(new Status("WARN"))) {
                bldr.status("WARN");
            } else {
                bldr.up();
            }

            Arrays.stream(statistics).forEach(cacheStatistics -> {
                val map = new HashMap<String, Object>();
                map.put("size", cacheStatistics.getSize());
                map.put("capacity", cacheStatistics.getCapacity());
                map.put("evictions", cacheStatistics.getEvictions());
                map.put("percentFree", cacheStatistics.getPercentFree());
                map.put("state", cacheStatistics.toString(new StringBuilder()));

                bldr.withDetail(cacheStatistics.getName(), map);
            });
        }, throwable -> {
            builder.down(throwable);
            return builder;
        }).accept(builder);
    }
Abstract base class for monitors that observe cache storage systems.

@author Marvin S. Addison
@since 3.5.1
core/cas-server-core-monitor/src/main/java/org/apereo/cas/monitor/AbstractCacheHealthIndicator.java