A
A
Alexander2015-11-03 16:54:17
linux
Alexander, 2015-11-03 16:54:17

How to configure logging of slow requests in nginx?

There is a server with Ubuntu 14.04, it has Nginx 1.9.4 and various services with REST API that are called from the outside world through Nginx. How can I set up logging in Nginx so that only slow requests are logged? For example, log all requests that are processed for more than 2 seconds, including the connection timeout to REST services?
PS I would like to know how to configure exactly Nginx (not to write any parsers).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2015-11-05
@summerwind

In general, the solution is this:
1. Install the nginx-extras package.
2. In the location configuration we write:

set $logging 0;
log_by_lua '
    if tonumber(ngx.var.upstream_response_time) >= 2 then
        ngx.var.logging=1
    end;
';

access_log /path/to/log format if=$logging

Thanks everyone for trying to help.

V
Vlad Zhivotnev, 2015-11-03
@inkvizitor68sl

if ($upstream_response_time !~* "[0-3]\.[0-9][0-9][0-9]" { access_log /file format; }

Try something like this.

Z
zorruch, 2015-11-03
@zorruch

What language is backend written in?
Maybe it's better to try to use slow log in php-fpm?
The decision "in a forehead" for your task. Write the query execution time to the log - and then parse the log file during the rotation and "grab" the necessary queries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question