一、haproxy得日志开通
yum install syslog
1、配置rsyslog
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
2、配置
vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS=”-c 2 -r -m 0″
#-c 2 使用兼容模式,默认是 -c 5
#-r 开启远程日志
#-m 0 标记时间戳。单位是分钟,为0时,表示禁用该功能
2、设置haproxy.cfg
vim /etc/haproxy/haproxy.cfg
log www.iaskjob.com local2 info
#info级别可以答应出access log,local2 对应输出到rsyslog的local2.*上
#log www.iaskjob.com local2 notice
二、log-format设置
根据不同的需求,配置不同的格式,具体可以参考连接地址、或者官方文档解释。
#Log format
#log-format %ci:%cp\%si:%sp\%B\%U\%ST\%r\%b\%f\%bi\%hrl\%hsl\%t\%T\%Tt\%H\%s
capture request header Host len 32
log-format "frontend:"%f%b/%s"client_ip:"%ci"client_port:"%cp"SSL_version:"%sslv"SSL_cypher:"%sslc%ts"Hostnaeme:"%H"RES_time"%Tt
http://blog.haproxy.com/2012/10/29/haproxy-log-customization/
http://www.iyunv.com/thread-275198-1-1.html
https://www.haproxy.org/download/1.4/doc/configuration.txt
- Tq: total time to get the client request (HTTP mode only). It's the time elapsed between the moment the client connection was accepted and the moment the proxy received the last HTTP header. The value "-1" indicates that the end of headers (empty line) has never been seen. This happens when the client closes prematurely or times out. - Tw: total time spent in the queues waiting for a connection slot. It accounts for backend queue as well as the server queues, and depends on the queue size, and the time needed for the server to complete previous requests. The value "-1" means that the request was killed before reaching the queue, which is generally what happens with invalid or denied requests. - Tc: total time to establish the TCP connection to the server. It's the time elapsed between the moment the proxy sent the connection request, and the moment it was acknowledged by the server, or between the TCP SYN packet and the matching SYN/ACK packet in return. The value "-1" means that the connection never established. - Tr: server response time (HTTP mode only). It's the time elapsed between the moment the TCP connection was established to the server and the moment the server sent its complete response headers. It purely shows its request processing time, without the network overhead due to the data transmission. It is worth noting that when the client has data to send to the server, for instance during a POST request, the time already runs, and this can distort apparent response time. For this reason, it's generally wise not to trust too much this field for POST requests initiated from clients behind an untrusted network. A value of "-1" here means that the last the response header (empty line) was never seen, most likely because the server timeout stroke before the server managed to process the request. - Tt: total session duration time, between the moment the proxy accepted it and the moment both ends were closed. The exception is when the "logasap" option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is prefixed with a '+' sign. From this field, we can deduce "Td", the data transmission time, by subtracting other timers when valid : Td = Tt - (Tq + Tw + Tc + Tr)