Need some guidance for setting upstream logs in NGINX TCP Load Balancer

Maxim Dounin mdounin at mdounin.ru
Tue Jul 20 12:36:10 UTC 2021


Hello!

On Tue, Jul 20, 2021 at 02:05:41PM +0530, awani227 wrote:

[...]

> stream {
> 
>     log_format  timed_combined  '$remote_addr - [$time_local] 
> $session_time $msec $status $protocol ua="$upstream_addr" 
> "$upstream_connect_time" "$upstream_response_time"';

[...]

> I'm able to establish connection for mysql in this setup, but 
> when I'm adding the log_format directive nginx is giving 
> following error,
> 
> 'nginx: [emerg] unknown "upstream_response_time" variable' 
> 
> 
> 
> My motive is to get metrics for this nginx tcp loadbalancer 
> (like requests per seconds, number of active connections).

In the stream load balancing there are no requests or responses 
nginx knows about.  Rather, there are connections (or sessions).  
As such, there is no $upstream_response_time variable, as well as 
other request and response-related variables which are available 
in http load balancing.

Instead, consider using appropriate connection-related variables, 
such as $upstream_connect_time, $upstream_first_byte_time, and 
$upstream_session_time.  Full list of the $upstream_* variables 
can be found here:

https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#variables

Hope this helps.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list