tutorial

Monitoring ehcache with Vigilmon

ehcache powers caching in millions of Spring and Hibernate applications. When the cache silently fails, database load climbs and batch jobs slow down. Here's how to monitor ehcache health via Spring Boot Actuator endpoints, SSL certificates, and batch job heartbeats with Vigilmon.

ehcache is Java's most widely used in-memory caching framework — embedded in Spring applications via the Spring Cache abstraction, used as Hibernate's second-level cache, and deployed in JEE enterprise systems worldwide. Unlike standalone cache servers, ehcache runs inside your JVM, which means its health is inseparable from your application's health. Spring Boot Actuator exposes ehcache's state through dedicated health and metrics endpoints, giving Vigilmon a clean external window into cache availability, hit rates, and batch job execution. Vigilmon monitors these endpoints from the outside, catching cache degradation before it silently drives up database load.

What You'll Set Up

  • Health endpoint monitor via Spring Boot Actuator /actuator/health
  • Cache statistics availability check on /actuator/caches
  • Cache hit rate monitoring via /actuator/metrics/cache.gets
  • SSL certificate expiry alerts for HTTPS Spring Boot applications
  • Heartbeat monitor for ehcache-dependent batch processing jobs

Prerequisites

  • Spring Boot application with ehcache configured (spring-boot-starter-cache + ehcache dependency)
  • Spring Boot Actuator enabled with health, caches, and metrics endpoints exposed
  • A free Vigilmon account

Expose Required Actuator Endpoints

In application.properties or application.yml, ensure the necessary endpoints are exposed:

management.endpoints.web.exposure.include=health,caches,metrics
management.endpoint.health.show-details=always

Step 1: Monitor the Actuator Health Endpoint

Spring Boot Actuator's /actuator/health endpoint aggregates the health of all registered health indicators, including the CacheHealthIndicator for ehcache. A 200 OK with "status":"UP" means the application and all caches are healthy.

  1. Log in to vigilmon.online and click Add Monitor.
  2. Set Type to HTTP / HTTPS.
  3. Enter the URL: https://YOUR_APP/actuator/health
  4. Set Check interval to 2 minutes.
  5. Set Expected HTTP status to 200.
  6. Under Advanced, set Expected body contains to "status":"UP".
  7. Click Save.

When ehcache fails to initialize or the cache manager encounters a fatal error, the health indicator returns "status":"DOWN" and the endpoint returns HTTP 503 — both of which Vigilmon will catch.


Step 2: Check Cache Statistics Availability

The /actuator/caches endpoint lists all registered caches by name. A successful response confirms that Spring's cache manager is active, all configured caches are registered, and the CacheManager bean is healthy.

  1. Add MonitorHTTP / HTTPS.
  2. URL: https://YOUR_APP/actuator/caches
  3. Set Expected HTTP status to 200.
  4. Under Advanced, set Expected body contains to "cacheManagers" (the top-level key in the JSON response).
  5. Set Check interval to 5 minutes.
  6. Click Save.

An empty cacheManagers object or a 404 indicates that the cache manager failed to start or the actuator endpoint is misconfigured — both of which result in every cache operation falling through directly to the database.


Step 3: Monitor Cache Hit Rate via Metrics Endpoint

The /actuator/metrics/cache.gets endpoint exposes the cumulative cache hit and miss counts. While Vigilmon doesn't perform arithmetic, you can check that the metrics endpoint is returning data — which confirms that cache operations are being recorded and the metrics subsystem is healthy.

  1. Add MonitorHTTP / HTTPS.
  2. URL: https://YOUR_APP/actuator/metrics/cache.gets
  3. Set Expected HTTP status to 200.
  4. Under Advanced, set Expected body contains to "measurements" (the JSON key containing hit/miss counts).
  5. Set Check interval to 5 minutes.
  6. Click Save.

For more advanced cache hit rate monitoring, expose a custom /actuator/health contributor in your Spring application that returns DOWN when the cache hit rate drops below a configurable threshold — then Vigilmon's health endpoint check (Step 1) will catch degraded cache performance automatically.


Step 4: SSL Certificate Expiry Alerts

Spring Boot applications running over HTTPS have TLS certificates that need renewal. Whether you use Let's Encrypt, a corporate CA, or a cloud load balancer certificate, Vigilmon can alert you before the certificate expires and breaks client connections.

  1. Open the HTTP / HTTPS monitor from Step 1 (using your HTTPS URL).
  2. Enable Monitor SSL certificate.
  3. Set Alert when certificate expires in less than 14 days.
  4. Click Save.

For applications deployed behind a load balancer (AWS ALB, GCP LB, nginx), the certificate is on the load balancer rather than the Spring Boot process — monitor the external HTTPS URL to check the certificate that users actually see.


Step 5: Heartbeat Monitor for ehcache-Dependent Batch Jobs

Spring Batch jobs that use ehcache for intermediate result caching (e.g., caching lookup tables or reference data between steps) are particularly vulnerable to silent cache failures. If ehcache fails mid-batch, steps complete but return degraded results — often without throwing an exception.

Set up a Vigilmon heartbeat to track batch job execution:

  1. In Vigilmon, Add MonitorHeartbeat.
  2. Name it Batch Job Health.
  3. Set Expected interval based on your job schedule (e.g. 1 hour for an hourly batch).
  4. Copy the generated heartbeat ping URL.

In your Spring Batch job configuration, add a heartbeat ping as a JobExecutionListener:

@Component
public class VigilmonHeartbeatListener implements JobExecutionListener {

    private final String heartbeatUrl = "YOUR_HEARTBEAT_URL";

    @Override
    public void afterJob(JobExecution jobExecution) {
        if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
            try (var client = HttpClient.newHttpClient()) {
                client.send(
                    HttpRequest.newBuilder(URI.create(heartbeatUrl)).GET().build(),
                    HttpResponse.BodyHandlers.discarding()
                );
            } catch (Exception ignored) {}
        }
    }
}

Register the listener on your job:

@Bean
public Job myBatchJob(JobRepository jobRepository, Step myStep) {
    return new JobBuilder("myBatchJob", jobRepository)
        .listener(vigilmonHeartbeatListener)
        .start(myStep)
        .build();
}

The heartbeat is only pinged on COMPLETED status — a FAILED or STOPPED job leaves Vigilmon's heartbeat window to expire, triggering an alert.


Step 6: Alert Channels and Grouping

  1. Go to Alert Channels in Vigilmon and configure your preferred channel (email, Slack, or PagerDuty).
  2. Group ehcache monitors under your application's service group alongside the main application health monitor.
  3. Set the /actuator/health monitor with the highest alert priority — a DOWN status means the entire application is degraded, not just the cache layer.
  4. Set Consecutive failures before alert to 2 on the caches endpoint — Spring Boot context restarts can briefly make the endpoint unavailable during application restart.

Summary

| Monitor | Target | What It Catches | |---|---|---| | Actuator health | /actuator/health | CacheManager failure, application DOWN | | Cache list | /actuator/caches | Missing cache registrations, manager startup failure | | Cache metrics | /actuator/metrics/cache.gets | Metrics subsystem failure | | SSL certificate | HTTPS app URL | Certificate expiry | | Heartbeat | Batch job listener | Job failure, missed execution, cache-related batch errors |

ehcache failures don't announce themselves — they quietly degrade application performance by forcing every cache miss to hit the database directly. Vigilmon's external checks on Spring Boot Actuator endpoints give you the earliest possible signal that something has gone wrong in the cache layer, long before query latency spikes and SLA breaches make it obvious.

Monitor your app with Vigilmon

Free plan — 5 monitors, no credit card required. Up and running in 60 seconds.

Start free →