Netstat command and awk to view the number of concurrent connections to the Web server and the TCP connection status.
The code is as follows |
Copy Code |
Netstat-n | awk '/^tcp/{++s[$NF]} end {for (a in S) print A, s[a]} '
Or: Netstat-n | awk '/^tcp/{++state[$NF]} end {for (key) print key, "T", State[key]} ' |
Fin_wait2 38
CLOSING 3
SYN_RECV 1
Close_wait 1
Time_wait 261
Established 71
Last_ack 2
Fin_wait1 9
Each state meaning of a TCP connection is described as follows
CLOSED no connection is active or in progress
LISTEN server waiting for incoming call
SYN_RECV A connection request has arrived, waiting for confirmation
Syn_sent application already started, open a connection
Established normal data transfer status/current concurrent connection number
FIN_WAIT1 application says it's done
Fin_wait2 the other side has agreed to release
Itmed_wait waiting for all the groupings to die.
CLOSING Both sides try to close both
Time_wait the other side has initialized a release
Last_ack waiting for all the groupings to die.
The value after the established parameter is the number of concurrent connections for the current system.
To view the number of Nginx run processes
The code is as follows |
Copy Code |
Ps-ef | grep Nginx | The number that Wc-l returns is the number of nginx running processes, and if it is Apache, execute Ps-ef | grep httpd | WC-L3, view the number of Web server process connections: NETSTAT-ANTP | grep 80 | grep established-c4, view the number of MySQL process connections: Ps-axef | grep mysqld-c To view the number of Web server process connections:
NETSTAT-ANTP | grep 80 | grep established-c
To view the number of MySQL process connections: Ps-axef | grep mysqld-c |
Add
To view the current number of Apache connections:
code is as follows |
copy code |
Ps-ef |grep Httpd|wc-l or Ps-aux |grep httpd |wc-l View current number of Apache concurrent connections and TCP connection status: Netstat-n | awk '/^tcp/{++s[$NF]} end {for (A in S) print A, s[a]} ' View number of connections and connection status: Netstat-ant|grep $ip: 80|wc-l netstat-ant|grep $ip: est|wc-l View Tomcat current connection status: Netstat-anlt|grep 8009|grep established netsat-ant |grep 8009|wc-l View MySQL Current Number of connections: Mysqladmin-umysql-pmysql static Mysqladmin-umysql-pmysql processlist |