Search code examples
tomcatstatus

How to add a health check on Tomcat?


I want to configure a simple health check on Tomcat for Linux, something like: http://localhost:8080/health

I have been checking Tomcat documentation, and I found this built-in server status site /manager/status/all, which indeed has a lot info, but requires that I login in there, so it's not useful if I do a "curl" as it won't retrieve any HTTP Response.

I expect to use something like this: http://localhost:8080/health, which returns a HTTP Response, i.e 200, so that I can add this url to my monitoring tool, in order to display the current status.


Solution

  • In a simple way, you can create a directory like health inside webapps and create an index file named index.html inside webapps/health/ with the following contents.

    <HTML>
      <HEAD>
        <TITLE>Tomcat status</TITLE>
      </HEAD>
      <BODY>
        <H1>Tomcat Running</H1>
       </BODY>
    </HTML>
    

    test with the following URL

    http://localhost:8080/health