Custom Search

Friday, June 3, 2016

How to enable request logging of haproxy

1)
Enable debug log in haproxy
$sudo vim /etc/haproxy/haproxy.cfg
global
  log  127.0.0.1 local0 debug


* Please note the name "local0"
* Please note the node "debug"

2)
Open UDP port for syslog

$sudo vim /etc/rsyslog.conf
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514


3)
Configure the location of haproxy log
$sudo vim /etc/rsyslog.d/haproxy.conf

# Send HAProxy messages to a dedicated logfile
#if $programname startswith 'haproxy' then /var/log/haproxy.log
#&~

#note: comment above "if then" and "&~" lines and add line below.
local0.* -/var/log/haproxy.log

* "local0" you can see at /etc/haproxy/haproxy.cfg

4)
Restart rsyslog

$restart rsyslog

5)
Restart haproxy

$sudo service haproxy restart

6)
Check log

$sudo tail -f /var/log/haproxy.log

Jun  3 08:07:56 localhost haproxy[31576]: 192.168.100.158:43738 [03/Jun/2016:08:07:56.830] api api/192.168.100.188 0/0/118 1184 -- 7/1/1/0/0 0/0
Jun  3 08:07:56 localhost haproxy[31576]: 192.168.100.188:52231 [03/Jun/2016:08:07:56.914] api api/192.168.100.158 0/0/61 1513 -- 5/0/0/0/0 0/0
Jun  3 08:07:57 localhost haproxy[31576]: 192.168.100.158:43741 [03/Jun/2016:08:07:57.170] api api/192.168.100.171 0/0/90 634 -- 9/0/0/0/0 0/0

1 comment:

  1. https://transloadit.com/blog/2010/08/haproxy-logging/

    ReplyDelete