简体   繁体   中英

How to configure: HAProxy to log the time for each request twice

I have a web application environment as follows:

Apache web server(172.17.0.82) -> HAProxy -> |-"php-fpm-1" App server
                                          -> |-"php-fpm-2" App server

Requests arrive at Apache server, then passed over to HAProxy which in turn passess them to the two php app servers based on Roundrobin fashion.

I wanted this web app to be structured this way. The rsyslog is enabled and it starts receiving log entries from haproxy to be logged in /var/log/haproxy.log.

My questions:

  • How to configure HAProxy so that each request will have two timestamps: 1) 1st one is the time when HAProxy receives an incoming request forwarded from Apache server. 2) 2nd timestamp is when request finished processing by one of the php App servers and sent back to HAProxy to be forwarded to Apache server.

  • Is it possible to have these two timestamps in single record in haproxy.log ?

  • Can I have all these timestamps recorded in microseconds in haproxy.log ?

Thank you all.

Here is my haproxy configuration file:

 global
    log 127.0.0.1   local0 
    log 127.0.0.1   local1 notice
    user haproxy
    group haproxy
    daemon


defaults
    mode    tcp
    option  tcplog
    #option dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000

frontend http-in
    mode tcp
    option tcplog
    bind    0.0.0.0:9000
    log global
    #which backend
    default_backend php_appservers


backend php_appservers
    mode tcp
    option tcplog
    balance roundrobin
    server php-fpm-1 172.17.0.125:9000 weight 5 check slowstart 5000ms
    server php-fpm-2 172.17.0.126:9000 weight 5 check slowstart 5000ms

When I checked the haproxy.log, it looks like:

May  7 08:28:00 localhost haproxy[4884]: 172.17.0.82:53369 [07/May/2015:08:28:00.287] http-in php_appservers/php-fpm-2 1/0/9 92320 -- 0/0/0/0/0 0/0
May  7 08:28:01 localhost haproxy[4884]: 172.17.0.82:53373 [07/May/2015:08:28:01.683] http-in php_appservers/php-fpm-1 1/0/4 92344 -- 0/0/0/0/0 0/0
May  7 08:28:02 localhost haproxy[4884]: 172.17.0.82:53376 [07/May/2015:08:28:02.514] http-in php_appservers/php-fpm-2 1/0/4 92320 -- 0/0/0/0/0 0/0
May  7 08:28:04 localhost haproxy[4884]: 172.17.0.82:53380 [07/May/2015:08:28:04.808] http-in php_appservers/php-fpm-1 1/0/8 92344 -- 0/0/0/0/0 0/0
May  7 08:28:05 localhost haproxy[4884]: 172.17.0.82:53382 [07/May/2015:08:28:05.247] http-in php_appservers/php-fpm-2 1/0/4 92320 -- 0/0/0/0/0 0/0
May  7 08:28:06 localhost haproxy[4884]: 172.17.0.82:53386 [07/May/2015:08:28:06.754] http-in php_appservers/php-fpm-1 1/0/4 92344 -- 0/0/0/0/0 0/0

Try using %U, upstream response time and %Tr, upstream connect time in the HAproxy logs. These should give you the latency added by the backend server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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