I have a spring-boot application that is monit controlled. The monitor simply checks to see if the / health spring endpoint will be displayed.
Basically, monit logged the following checks:
check host hopsearch_connection with address 127.0.0.1 if failed url http://127.0.0.1:8089/health with timeout 15 seconds then alert check host hopsearch_health with address 127.0.0.1 if failed url http://127.0.0.1:8089/health and content != 'DOWN' with timeout 60 seconds then alert
and the web application will return something like this:
{"status":"UP","jestHealth":{"status":"UP","lastQuerySuccess":true},"diskSpace":{"status":"UP","free":14439550976,"threshold":10485760},"rabbit":{"status":"UP","version":"3.3.2"},"redis":{"status":"UP","version":"3.0.0"},"mongo":{"status":"UP","version":"2.6.1"}}
In this spring application, I have a generic @ExceptionHandler to log all unexpected errors and display the error page:
@ExceptionHandler(Exception.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public String handleDefaultError(Exception ex, HttpServletRequest httpRequest) { logException(httpRequest, ex); return "error"; }
And this @ExceptionHandler logs every call with monit:
<11>May 1 13:20:39 IP 13:20:39.339 t=http-nio-8089-exec-3 l=ERROR c=chswcErrorManager m=Error 500 ---------------------------------------------------------------- Request Path=http://127.0.0.1:8089/health Method=GET ---------------------------------------------------------------- Header : ---------------------------------------------------------------- host = 127.0.0.1:8089 accept = */* connection = close user-agent = monit/5.4 ---------------------------------------------------------------- <11>May 1 13:20:39 IP 13:20:39.340 t=http-nio-8089- exec-3 l=ERROR c=chswcErrorManager m=Unexpected error : java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:1.8.0_25] at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[na:1.8.0_25] at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[na:1.8.0_25] at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[na:1.8.0_25]
From the point of view of monit, everything is fine, and the check works. From my point of view, the application works. But I have a lot of errors flushed to the log.
I canβt play on my curled workstation. This exception occurs only on the server with monit.
Is it possible to ignore an error based on a specific user agent in an ExceptionHandler? (And How?)
This is not the best solution, but I see no other way.
Any thoughts on this?