大网数据广告活动
服务器运维问答

HTTP request duration with HAProxy

· 52CE 我爱测

Is it possible to monitor the duration of HTTP requests ? (from the moment that the request is received by the load balancer, to the time when the response is returned to the client by the load balancer) I would like to monitor t…

问题原文

原帖链接 · collimarco · CC BY-SA 3.0

Is it possible to monitor the duration of HTTP requests? (from the moment that the request is received by the load balancer, to the time when the response is returned to the client by the load balancer)

I would like to monitor this metric in the frontend, because I want to include the queue time. If I measure the duration of the backend I may get good stats but the real performance can be bad (for example if the request gets queued in the load balancer itself).

For example I would like to monitor a web application during traffic spikes to make sure that the responses are still fast, from the point of view of the user (e.g. < 3 seconds).

社区高分解答

原帖链接 · przRocco · CC BY-SA 3.0

HAproxy offers all those informations in the logs .

see Haproxy HTTP Log Format

In particular you are looking for the section number 6 ,

6 TR '/' Tw '/' Tc '/' Tr '/' Ta* 10/0/30/69/109

where

  • "TR" is the total time in milliseconds spent waiting for a full HTTP request from the client (not counting body) after the first byte was received. It can be "-1" if the connection was aborted before a complete request could be received or the a bad request was received. It should always be very small because a request generally fits in one single packet. Large times here generally indicate network issues between the client and haproxy or requests being typed by hand. See "Timers" below for more details.

  • "Tw" is the total time in milliseconds spent waiting in the various queues. It can be "-1" if the connection was aborted before reaching the queue. See "Timers" below for more details.

  • "Tc" is the total time in milliseconds spent waiting for the connection to establish to the final server, including retries. It can be "-1" if the request was aborted before a connection could be established. See "Timers" below for more details.

  • "Tr" is the total time in milliseconds spent waiting for the server to send a full HTTP response, not counting data. It can be "-1" if the request was aborted before a complete response could be received. It generally matches the server's processing time for the request, though it may be altered by the amount of data sent by the client to the server. Large times here on "GET" requests generally indicate an overloaded server. See "Timers" below for more details.

  • "Ta" is the time the request remained active in haproxy, which is the total time in milliseconds elapsed between the first byte of the request was received and the last byte of response was sent. It covers all possible processing except the handshake (see Th) and idle time (see Ti). There is one exception, if "option logasap" was specified, then the time counting stops at the moment the log is emitted. In this case, a '+' sign is prepended before the value, indicating that the final one will be larger. See "Timers" below for more details.

Exporting those metrics from the logs to a more useful format / backend can be done in many ways, Logstash comes to mind since it can parse those logs and send them to many different backends

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。