How to Check Current Nginx and MySQL Connection Counts

Check all current Nginx connection counts and connection states:
#netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
TIME_WAIT 17
ESTABLISHED 3254
LAST_ACK 236
FIN_WAIT_1 648
FIN_WAIT_2 581
CLOSING 7
CLOSE_WAIT 4916
Description of state meanings:
CLOSED //No connection is active or in progress
LISTEN //Server is waiting for an incoming call
SYN_RECV //A connection request has arrived, waiting for confirmation
SYN_SENT //Application has started, opening a connection
ESTABLISHED //Normal data transfer state / current concurrent connections
FIN_WAIT1 //Application says it has finished
FIN_WAIT2 //The other side has agreed to release
ITMED_WAIT //Waiting for all packets to die
CLOSING //Both sides attempting to close simultaneously
TIME_WAIT //The other side has initialized a release
LAST_ACK //Waiting for all packets to die
Check current MySQL connections:
1. View detailed information for all current connections:
./mysqladmin -uadmin -p -h10.140.1.1 processlist
2. Only view the current connection count (Threads is the connection count.):
./mysqladmin -uadmin -p -h10.140.1.1 status
Note: (Distinguishing accounts)
Check MySQL connection count and current user MySQL connection count
First, enter the MySQL prompt as an administrator.
#mysql -uroot -pxxxx
mysql> show processlist; can display the first 100 connection entries. show full processlist; can display all. By the way, if you log in with a regular account, it will only show that user’s connections. Note the semicolon after the command.
If we want to check this server’s settings. #vi /etc/my.cnf
set-variable=max_user_connections=30 This is the per-user connection limit
set-variable=max_connections=800 This is the global connection limit
#netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
TIME_WAIT 17
ESTABLISHED 3254
LAST_ACK 236
FIN_WAIT_1 648
FIN_WAIT_2 581
CLOSING 7
CLOSE_WAIT 4916
Description of state meanings:
CLOSED //No connection is active or in progress
LISTEN //Server is waiting for an incoming call
SYN_RECV //A connection request has arrived, waiting for confirmation
SYN_SENT //Application has started, opening a connection
ESTABLISHED //Normal data transfer state / current concurrent connections
FIN_WAIT1 //Application says it has finished
FIN_WAIT2 //The other side has agreed to release
ITMED_WAIT //Waiting for all packets to die
CLOSING //Both sides attempting to close simultaneously
TIME_WAIT //The other side has initialized a release
LAST_ACK //Waiting for all packets to die
Check current MySQL connections:
1. View detailed information for all current connections:
./mysqladmin -uadmin -p -h10.140.1.1 processlist
2. Only view the current connection count (Threads is the connection count.):
./mysqladmin -uadmin -p -h10.140.1.1 status
Note: (Distinguishing accounts)
Check MySQL connection count and current user MySQL connection count
First, enter the MySQL prompt as an administrator.
#mysql -uroot -pxxxx
mysql> show processlist; can display the first 100 connection entries. show full processlist; can display all. By the way, if you log in with a regular account, it will only show that user’s connections. Note the semicolon after the command.
If we want to check this server’s settings. #vi /etc/my.cnf
set-variable=max_user_connections=30 This is the per-user connection limit
set-variable=max_connections=800 This is the global connection limit