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?
-
Edit the apache configuration vi /etc/httpd/conf/httpd.con
Inside the file find the LogFormat configuration and add the directive prefix->%D -
Restart apache (E.g: Centos )
systemctl reload httpd
-
Making a request by visiting the website (e.g: website.domain)
https://website.domain
-
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
The last log shows the result
Result: prefix->4215569
References
- https://httpd.apache.org/docs/2.4/mod/mod_log_config.html#logformat
- https://www.sumologic.com/insight/apache-response-time/
- https://www.loggly.com/ultimate-guide/apache-logging-basics/
Comments
Post a Comment