Two Methods to View Nginx Concurrent Connection Count

Publish: 2019-06-03 | Modify: 2019-06-04

More and more projects in the production environment are using Nginx as a web server. At the same time, we need to constantly monitor the status of Nginx, such as checking the current number of concurrent connections to ensure normal operation. This article shares two methods to view the number of concurrent connections in Nginx.

Method 1: View through the web interface

This method relies on the http_stub_status_module module of Nginx. You can use the command nginx -V to check if this module is installed. If it is not installed, you need to recompile Nginx with this module.

Add the following configuration inside any server block:

location /status {
   stub_status on;
}

After modifying the configuration, use the command nginx -t to ensure there are no syntax errors, and then reload the Nginx configuration with nginx -s reload to make it effective. Then access http://youdomain.com/status to see the connection status, as shown in the screenshot below.

Nginx Status

The meanings of the above parameters are as follows:

  • Active connections: the number of active connections Nginx is currently handling (1186), which is the current number of concurrent connections.
  • Server accepts handled requests: a total of 420,484 connections have been handled, with 420,484 successful handshakes and a total of 408,348 requests being processed.
  • Reading: the number of header information read by Nginx from the client.
  • Writing: the number of header information returned by Nginx to the client.
  • Waiting: when keep-alive is enabled, this value is equal to active connections minus (reading + writing), which means Nginx has finished processing the resident connections that are waiting for the next request instruction.

Method 2: Command-line view

If you only want to view the current number of concurrent connections in Nginx without more detailed information, you can use the following command (netstat -apn|grep 'nginx: worker'|wc -l).

[root@rakcdn ~]# netstat -apn|grep 'nginx: worker'|wc -l
1096

References:

Some content in this article is referenced from: NGINX: View Concurrent Connections


Comments