My Tomcat access log is currently cluttered with health check requests from a load balancer, so it's rather hard to actually understand what's going on. For example, using GoAccess I can see some misleading statistics:
Hits h% Vis. v% Bandwidth Mtd Proto Data
----- ------ ---- ----- ----------- --- -------- ----
46221 81.20% 2 0.02% 30.72 MiB GET HTTP/1.1 /geoserver/index.html
16 0.03% 1 0.01% 50.23 KiB GET HTTP/1.1 /geoserver/wms?SERVICE=WMS&VERSION=1.1.0&REQUEST=GetMap&FORMAT=image/jpeg.
16 0.03% 1 0.01% 338.80 KiB GET HTTP/1.1 /geoserver/wms?SERVICE=WMS&VERSION=1.1.0&REQUEST=GetMap&FORMAT=image/png.
The log is created using Tomcat's standard Access Log Valve. The valve is supposed to have a parameter, conditionUnless
, which I try to use in order to get rid of all those requests being made to index.html
(that's where health check goes, so I can safely filter out all of them).
According to documentation, conditionUnless
:
Turns on conditional logging. If set, requests will be logged only if
ServletRequest.getAttribute()
isnull
. For example, if this value is set to junk, then a particular request will only be logged ifServletRequest.getAttribute("junk") == null
. The use of Filters is an easy way to set/unset the attribute in the ServletRequest on many different requests.
But I can't figure out how to use Filters to filter out all requests to index.html
and flag them in some what. Obviously, the following in server.xml
is not enough:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="/var/log/tomcat8/accesslogs"
prefix="node1" suffix=".log"
pattern="combined"
renameOnRotate="true"
conditionUnless="index.html" />
How can I exclude all requests to index.html
?