How to copy nginx logs of requests that took more than n seconds

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to copy nginx logs of requests that took more than n seconds



Consider that the access logs are of this format:



log_format detailed '$remote_addr $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_length $request_time $upstream_connect_time $upstream_header_time $upstream_response_time';



How can I have a new log file that contains only requests that took more than 5 seconds?




2 Answers
2



You can send logs to http-log and process them to figure out if anything is more than the time you are expecting it to.



Stopping logs based on some condition looks little complex to implement. But once logs are generated, extracting the required info from them seems correct approach.



You can do this with built in if statemen on access_log directive like so:


if


access_log


http
...
map $upstream_response_time $under
~^[01234].[0-9]+ 1;
default 0;


server
set $over 1;
if ( $under = 1 ) set $over 0;
access_log /some/folder/under.log combined if=$under;
access_log /some/folder/over.log combined if=$over;
...

...






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard