How long Apache tooks to process a request?

 Goal

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

Problem

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

Solution

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)

    https://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 

References

  1. https://httpd.apache.org/docs/2.4/mod/mod_log_config.html#logformat
  2. https://www.sumologic.com/insight/apache-response-time/ 
  3. https://www.loggly.com/ultimate-guide/apache-logging-basics/

 

 

Comments

Popular posts from this blog

Redis as cache for excel generation using Phpspreadsheet

How to schedule a Symfony Console App execition using supervidord? Not using cron job

Azure Blob Storage. Overview