haproxy json 自定义格式日志

haproxy的日志跟nginx日志有所同,有的header信息并不能直接配到日志里面

haproxy提供了一个capture方法可以捕捉一些信息,可以用capture捕获的信息作为log-format的字段

http-request capture req.hdr(Host) len 64   #id 0  capture.req.hdr(0)
capture request header User-Agent len 64    #id 1  capture.req.hdr(1)
log-format {\"local_time\":"%t",\"hostname\":\"%H\",\"clientip\":\"%ci\",\"http_mode\":\"%HM\",\"http_version\":\"%HV\",\"url\":\"%HP\",\"http_code\":\"%ST\",\"backend_name\":\"%b\",\"server_name\":\"%s\",\"server_ip\":\"%si\",\"http_host\":\"%[capture.req.hdr(0)],\"agent\":\"%[capture.req.hdr(1)]\"}

参考文档:

https://www.haproxy.com/documentation/hapee/1-8r1/traffic-management/log-format-rules/

https://www.haproxy.com/documentation/hapee/1-8r1/traffic-management/traffic-capture/

猜你喜欢

转载自www.cnblogs.com/37yan/p/10158496.html