简体   繁体   English

请求和响应时的 Haproxy 日志记录

[英]Haproxy Logging At Time of Request & Time of Response

We have been using haproxy for a while now and it has been great for getting detailed logs and being able to customize much of the information we want to extract out of our traffic.我们使用 haproxy 已经有一段时间了,它非常适合获取详细的日志并能够自定义我们想要从流量中提取的大部分信息。

However, I have made some layer 8 mistakes by thinking that timestamps on log entries are the time of the request to the server.但是,我认为日志条目上的时间戳是向服务器发出请求的时间,因此犯了一些第 8 层错误。

Through testing, watching log entries, and studying haproxy documentation it looks like logging takes place at the time of the response and includes information about how long in milliseconds those requests took.通过测试、查看日志条目和研究 haproxy 文档,看起来日志记录发生在响应时,并且包含有关这些请求花费了多长时间的信息(以毫秒为单位)。

This can be helpful, however when trying to align requests from the haproxy log with application logs it ends up being difficult to align log entries without doing some time math to get as close as possible to the true request time.这可能会有所帮助,但是当尝试将来自 haproxy 日志的请求与应用程序日志对齐时,如果不做一些时间数学以尽可能接近真实的请求时间,最终很难对齐日志条目。

Has my own study or experience led me astray in my understanding of when haproxy populates logs and the date/time stamp found in the logs?我自己的研究或经验是否让我对 haproxy 何时填充日志以及在日志中找到的日期/时间戳的理解误入歧途? Or is there a way to configure haproxy to make a log entry at the time of the request as well as at the time of the response?或者有没有办法配置 haproxy 在请求时以及响应时创建日志条目?

Server Type: Centos服务器类型:Centos

HAProxy Version: 1.8 HAProxy 版本:1.8

Example Log Entries:示例日志条目:

Feb 22 03:07:06 unipay-p11 haproxy[2286]: 10.13.6.101:35804 [22/Feb/2022:03:07:06.283] ft-unipay-https~ unipay-api/unipay-p13.zift.io 0/0/6/13/19 200 507 - - ---- 48/48/4/2/0 0/0 {|} "GET /pingdom/index.jsp HTTP/1.1"```
Feb 22 03:07:06 unipay-p11 haproxy[2286]: 10.13.6.103:39836 [22/Feb/2022:03:07:06.285] ft-unipay-https~ unipay-api/unipay-p13.zift.io 0/0/5/12/17 200 507 - - ---- 48/48/3/1/0 0/0 {|} "GET /pingdom/index.jsp HTTP/1.1"
Feb 22 03:07:06 unipay-p11 haproxy[2286]: 10.13.6.103:39836 [22/Feb/2022:03:07:06.285] ft-unipay-https~ unipay-api/unipay-p13.zift.io 0/0/5/12/17 200 507 - - ---- 48/48/3/1/0 0/0 {|} "GET /pingdom/index.jsp HTTP/1.1"
Feb 22 03:07:06 unipay-p11 haproxy[2286]: 10.13.8.102:50888 [22/Feb/2022:03:07:06.260] ft-unipay-https~ unipay-api/unipay-p11.zift.io 0/0/5/47/52 200 507 - - ---- 46/46/2/1/0 0/0 {|} "GET /pingdom/ HTTP/1.1"

Thank you谢谢

James Anderson詹姆斯·安德森

Unfortunately I don't have an absolute answer for you but my experience with HAProxy and a couple of documents that I've found brings me to believe that the timestamp provided in the logs (between [ and ]) is the time when HAProxy received and began processing the request.不幸的是,我没有给你一个绝对的答案,但我在 HAProxy 方面的经验和我发现的一些文件让我相信日志中提供的时间戳(在 [ 和 ] 之间)是 HAProxy 收到和开始处理请求。

In this doc https://cdn.haproxy.com/wp-content/uploads/2017/07/aloha_load_balancer_memo_log.pdf they say:在这个文档https://cdn.haproxy.com/wp-content/uploads/2017/07/aloha_load_balancer_memo_log.pdf他们说:

%t    exact date when the TCP connection was received by haproxy

Also, in the official documentation https://cbonte.github.io/haproxy-dconv/1.7/configuration.html when referring to %t另外,在官方文档https://cbonte.github.io/haproxy-dconv/1.7/configuration.html时提到%%%

 - "accept_date" is the exact date when the connection was received by haproxy

Additionally, when I need to know when the request ended, I add to this timestamp the value of %Tt (milliseconds).此外,当我需要知道请求何时结束时,我会在此时间戳中添加%Tt (毫秒)的值。 Some info here https://www.haproxy.com/blog/haproxy-log-customization/这里有一些信息https://www.haproxy.com/blog/haproxy-log-customization/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM