How long Apache tooks to process a request?


Retrieve from the Apache logs the time that the server processes a request.


To tracking through DataDog or other tool those slow requests performed by our web server it’s necessary to have in each Apache’s request log the following information:

How long Apache took to process the request


Add to LogFormat configuration the directive %D to measure in microseconds the time each request is processed. If each virtual has already defined custom LogFormat it should be updated also.

Because the intention is to parse the log entry my suggestion is to add a prefix to the log format. Then the directive would be prefixed for example by prefix->%D and the log will hold for example prefix->523484, Where:
prefix->: A custom value defined by developer to be used by the parser.
523484: Value in microseconds of the request processing.

The prefix must be defined in advance by the developer.

How to test it?

  1. Edit the apache configuration vi /etc/httpd/conf/httpd.con
    Inside the file find the LogFormat configuration and add the directive prefix->%D

  2. Restart apache (E.g: Centos )

    systemctl reload httpd

  3. Making a request by visiting the website (e.g: website.domain)


  4. Find the respective log entry of the action performed by step 3

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" prefix->%D" combined

vi /var/log/httpd/access_log

The last log shows the result

Result: prefix->4215569 






Popular posts from this blog

Azure Blob Storage. Overview

Redis as cache for excel generation using Phpspreadsheet