@@ -0,0 +1,2033 @@
+package top.quantic.sentry.health;%0A%0Aimport com.google.common.cache.Cache;%0Aimport com.google.common.cache.CacheStats;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.actuate.health.Health;%0Aimport org.springframework.boot.actuate.health.HealthIndicator;%0Aimport org.springframework.cache.CacheManager;%0Aimport org.springframework.cache.guava.GuavaCache;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport java.util.LinkedHashMap;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors;%0A%0A@Component%0Apublic class CacheHealthIndicator implements HealthIndicator %7B%0A%0A    private final CacheManager cacheManager;%0A%0A    @Autowired%0A    public CacheHealthIndicator(CacheManager cacheManager) %7B%0A        this.cacheManager = cacheManager;%0A    %7D%0A%0A    @Override%0A    public Health health() %7B%0A        Map%3CString, Map%3CString, Object%3E%3E caches = cacheManager.getCacheNames().stream()%0A            .map(name -%3E (GuavaCache) cacheManager.getCache(name))%0A            .map(cache -%3E buildStats(cache.getName(), cache.getNativeCache()))%0A            .collect(Collectors.toMap(stats -%3E (String) stats.get(%22name%22), stats -%3E stats));%0A        Health.Builder builder = Health.up()%0A            .withDetail(%22count%22, caches.size());%0A        caches.forEach(builder::withDetail);%0A        return builder.build();%0A    %7D%0A%0A    private Map%3CString, Object%3E buildStats(String name, Cache%3CObject, Object%3E cache) %7B%0A        Map%3CString, Object%3E map = new LinkedHashMap%3C%3E();%0A        map.put(%22name%22, name);%0A        map.put(%22status%22, %22UP%22);%0A        map.put(%22size%22, cache.size());%0A        CacheStats stats = cache.stats();%0A        map.put(%22hitRate%22, stats.hitRate());%0A        map.put(%22hitCount%22, stats.hitCount());%0A        map.put(%22missCount%22, stats.missRate());%0A        map.put(%22loadSuccessCount%22, stats.loadSuccessCount());%0A        map.put(%22loadExceptionCount%22, stats.loadExceptionCount());%0A        map.put(%22totalLoadTime%22, stats.totalLoadTime());%0A        map.put(%22evictionCount%22, stats.evictionCount());%0A        return map;%0A    %7D%0A%7D%0A

Add a health indicator for caches