0

I'm running HAProxy version 3.0.5 for proxying HTTP requests across a bunch of different backends, and also as a TCP proxy for a RabbitMQ cluster. I have added a custom log format so I can better understand the log message at a glance, like so (only the relevant config is here):

global log 127.0.0.1 len 4096 local0 defaults mode http log global option dontlognull option dontlog-normal option log-separate-errors log-format "Client IP:port = [%ci:%cp], Start Time = [%tr], Frontend Name = [%ft], Backend Name = [%b], Backend Server = [%s], Active time of the request = [%Ta ms], Time to establish TCP connection to the server = [%Tc ms], SSL handshake time = [%Th ms], Idle time before the HTTP request = [%Ti ms], Time to get the client's request = [%Tq ms], Time to receive full request = [%TR ms], Response time = [%Tr ms], Total session duration time = [%Tt ms], Status Code = [%ST], Bytes Read = [%B], Termination state = [%ts], Request = [%{+Q}r]" frontend main bind ... listen rabbitmq bind ... mode tcp log-format "Client IP:port = [%ci:%cp], Start Time = [%tr], Frontend Name = [%ft], Backend Name = [%b], Backend Server = [%s], Active time of the request = [%Ta ms], Time to establish TCP connection to the server = [%Tc ms], SSL handshake time = [%Th ms], Idle time before the TCP request = [%Ti ms], Time to get the client's request = [%Tq ms], Time to receive full request = [%TR ms], Response time = [%Tr ms], Total session duration time = [%Tt ms], Bytes Read = [%B], Termination state = [%ts]" 

The rsyslog conf has been simplified to the following to put everything into a single file:

$FileCreateMode 0644 :programname, startswith, "haproxy" -/var/log/haproxy/haproxy.log & ~ 

If I leave it like this, it generates way too much log, over 30 GB a day. So I'd like to log only the failed requests, or maybe even only a portion of the requests. I have seen some examples, but nothing seems to work.

When I try to add the following settings:

defaults option dontlog-normal option log-separate-errors frontend main bind ... http-response set-log-level err if { status ge 400 } listen rabbitmq bind ... tcp-request content set-log-level silent unless { rand(100) lt 10 } 

Now it logs nothing. Even though I generate correct and failed requests, and there are rabbitmq messages as well, nothing is logged.

1 Answer 1

0

Actually I ended up being dumb... I didn't realize that 404 response, if coming from a backend, is considered "normal" in HAProxy and I had option dontlog-normal which suppressed it, and I tried testing it that way... I ended up removing the dontlog-normal, setting the log level to silent by default, and setting it to notice for ~10% of requests, and err for all failed requests:

frontend main bind ... http-response set-log-level silent http-response set-log-level notice if { rand(100) lt 10 } http-response set-log-level err if { status -m int 400:599 } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.