Writing a custom health check

Another critical feature needed when we take our application to production is monitoring it. In the olden days, people would set up a CRON job to ping a server and see if it was up. More intricate systems would track disk usage, memory usage, and ideally page someone when the database was at 95%, so it could be saved before falling over.

Spring Boot provides a new era in health check monitoring. To kick things off, launch the application and visit /application/health:

    {
        status: "UP",
        diskSpace: {
            status: "UP",
            total: 498937626624,
            free: 96519303168,
            threshold: 10485760
        },
        mongo: {
            status: "UP",
            version: "3.4.6"
        }
    }  

Out of the box, this provides us with an endpoint we can ping and additionally, gives ...

Get Developing Java Applications with Spring and Spring Boot now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.