haproxy log日志简单记录

haproxy提供了5种日志格式,有default log、tcplog、HTTPlog、CLFHTTPlog、custom log

default log

haproxy的默认日志格式
Nov 26 05:56:17 localhost haproxy[3521]: Connect from 11.2.2.66:51659 to 11.2.3.25:80 (web/HTTP)

format 日志字段
process_name ‘[’ pid ‘]:’ haproxy[3521]:
‘Connect from’ Connect from
source_ip ‘:’ source_port 11.2.2.66:51659
‘to’ to
‘(’ frontend_name ‘/’ mode ‘)’ (www/HTTP)

tcplog

tcplog是纯tcp代理推荐使用的格式,它对提供故障诊断信息具有相当的帮助。由于存在计数器和字节数,它总是在会话结束后发出。如果使用option logasap,则可以更早发出。大多数适用于长会话当中。在前端指定option dontlognull也可以不为客户端和服务器之间没有交换数据的会话发送日志。如果在前端指定option donlog-normal,成功的连接将不会被记录。
日志格式:
Nov 26 06:51:26 localhost haproxy[6308]: 11.2.3.25:60042 [26/Nov/2020:06:51:24.395] mysql sqlserver/sql1 1/0/1710 188 -- 0/0/0/0/0 0/0

format 日志字段
process_name ‘[’ pid ‘]:’ haproxy[3521]:
source_ip ‘:’ source_port 11.2.3.25:60042
‘[’ accept_date ‘]’ [26/Nov/2020:06:51:24.395]
frontend_name mysql
backend_name ‘/’ server_name sqlserver/sql1
Tw ‘/’ Tc ‘/’ Tt* 1/0/1710
bytes_read* 188
termination_state
actconn ‘/’ feconn ‘/’ beconn ‘/’ srv_conn ‘/’ retries* 0/0/0/0/0
srv_queue ‘/’ backend_queue 0/0
  • Tw:在各种队列中消耗的时长,默认为毫秒
  • Tc:等待连接的总时长,从客户端到和服务器之间的最终连接,包括重试
  • Tt:它包含了从接受到最后一次处理完的时长,这期间的时长来自服务器可能处理的时长。如果使用option logasap,则可以更早发出
  • bytes_read*: 从服务器发送到客户端的日志总字节数,如果指定option logasap,则此值将以+号作为前缀,表示最后一个值可能更大
  • termination_state:表示会话是以哪种状态断开了
  • actconn:记录会话时进程上的并发连接数
  • feconn:“feconn”是记录会话时前端的并发连接总数。评估维持高负载所需的资源数量,以及检测何时达到了frontend的“maxconn”是很有用的。最常见的情况是,当此值大幅上升时,是因为后端服务器出现拥塞,但有时也可能是由拒绝服务攻击引起的。
  • beconn:是记录会话时后端的并发连接总数
  • srv_conn:“srv_conn”是记录会话时服务器上仍然活动的并发连接总数。它永远不能超过服务器配置的“maxconn”参数。如果这个值经常接近或等于服务器的“maxconn”,则意味着流量管理涉及很多,意味着服务器的maxconn值太低,或者没有足够的服务器以最佳响应时间来处理负载。当服务器的“srv_conn”只有一个较高时,通常意味着该服务器存在一些问题,导致处理连接的时间比其他服务器更长。
  • retries*:重试次数
  • srv_queque:“srv_queue”是服务器队列中在此请求之前处理的请求总数。当请求未通过服务器队列时,它为零。通过将队列中花费的时间除以队列中请求的数量,可以估计出服务器的响应时间。值得注意的是,如果会话经历被分派并通过两个服务器队列,它们的位置将被累积。除非发生重新分派,否则请求不应同时通过服务器队列和后端队列。
  • backend_queque:后端服务器队列

HTTP log format

HTTP格式的日志最适用于http代理的模式。同tcp一样,提供了非常有用的帮助

Nov 26 07:54:47 localhost haproxy[7202]: 11.2.3.25:38168 [26/Nov/2020:07:54:47.724] web websrv/srv2 0/0/0/1/1 200 256 - - ---- 1/1/0/1/0 0/0 "GET / HTTP/1.1"

format 日志字段
process_name ‘[’ pid ‘]:’ haproxy[7202]:
client_ip ‘:’ client_port 11.2.3.25:38168
‘[’ accept_date ‘]’ [26/Nov/2020:07:54:47.724]
frontend_name web
backend_name ‘/’ server_name websrv/srv2
Tq ‘/’ Tw ‘/’ Tc ‘/’ Tr ‘/’ Tt* 0/0/0/1/1
status_code 200
bytes_read* 256
captured_request_cookie -
captured_response_cookie -
actconn ‘/’ feconn ‘/’ beconn ‘/’ srv_conn ‘/’ retries* 1/1/0/1/0
srv_queue ‘/’ backend_queue 0/0
‘"’ http_request ‘"’ “GET /index.html HTTP/1.1”
  • Tq:是客户端与服务器之间发送一次完整的http请求消耗的时长,单位是毫秒。 如果出现大量的请求,一般是网络问题。 连接失败是-1 web websrvs/<NOSRV> 178/-1/-1/-1/178 "
  • Tw:在队列中等待的时长
  • Tc:客户端连接到最终服务器的时长,包括重试次数
  • Tr:等待服务器发送完整的http响应所花费的时间,不算数据。它通常会和服务器处理请求的时间相匹配,"GET"请求的大量时间通常表明服务器超载
  • Tt:从连接到最后一次关闭消耗的时间。它涵盖了所有可能的处理
  • status_code:响应码
  • bytes_read* :发送日志到客户端的总字节数,包含了http头部。

http模式下的log还可以添加一些选项。

capture cookie <name> len <length>:捕获一个在请求和响应中的cookie并记录到日志中,只能用在frontendlisten

示例:

frontend web
  bind :80
  default_backend websrvs
  option httplog
  log global
  capture cookie RS len 32
backend websrvs
  balance roundrobin
  hash-type consistent
  cookie RS indirect insert nocache
  option forwardfor except 127.0.0.1 header X-RealIP-For
  server web 172.17.0.2:80    cookie web check
  server web1 172.17.0.3:80   check

日志表现:

Nov 26 22:39:58 localhost haproxy[17723]: 192.168.199.111:53144 [26/Nov/2020:22:39:58.077] web websrvs/web 165/0/0/1/166 304 152 RS=web - --VN 1/1/0/1/0 0/0 "GET / HTTP/1.1"


capture request header <name> len <length>:捕获指定请求头信息最后一次的出现

示例:

frotend下

capture request header  HOST len 15

日志显示

Nov 26 23:19:57 localhost haproxy[18352]: 192.168.199.111:55897 [26/Nov/2020:23:19:57.213] web websrvs/web1 456/0/0/1/457 200 282 RS=web - ---- 2/2/0/0/0 0/0 {
    
    192.168.199.155} "GET / HTTP/1.1"

capture response header <name> len <length>:捕获指定响应头信息最后一次的出现
示例:

frontend下
capture response header Server len 40

日志显示:

Nov 26 23:23:50 localhost haproxy[18410]: 192.168.199.111:56117 [26/Nov/2020:23:23:50.430] web websrvs/web 312/0/0/1/313 200 283 RS=web - ---- 2/2/0/1/0 0/0 {
    
    192.168.199.155} {
    
    Apache/2.4.6 (CentOS) PHP/5.4.16} "GET / HTTP/1.1"

custom log

haproxy可以根据自己的需要定义日志

各个参数可以看文档

示例:

capture cookie RS len 32
  capture request header  Cookie len 15
  capture response header Server len 40
  capture request header User-Agent len 30

log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %r\ %b\ %f\ %bi\ %hrl\ %hsl\

%hrl:capture捕获的request报文信息,会以CLF模式显示出来。
%hsl:capture捕获的response报文信息,会以CLF模式显示出来。

日志显示:

Nov 27 00:13:38 localhost haproxy[19180]: 192.168.199.111:59180 172.17.0.2:80 283 560 200 GET / HTTP/1.1 websrvs web 172.17.0.1 RS=web Mozilla/5.0 (Windows NT 10.0;  Apache/2.4.6 (CentOS) PHP/5.4.16\

猜你喜欢

转载自blog.csdn.net/qq_44564366/article/details/110157463
今日推荐