CentOS netstat + awk View TCP's network connection status

Source: Internet
Author: User

execute the following command: #netstat-N | awk '/^tcp/{++state[$NF]} END { for(KeyinchState) Print key."\ t". State[key]} ' will get a result similar to the following, the exact number will be different: fin_wait_1286fin_wait_2960syn_sent3Last_ack +CLOSING1CLOSED $SYN_RCVD144time_wait2520established352#差不多等于连接的并发数这条命令可以把当前系统的网络连接状态分类汇总. This statement was seen at the feast, and it was said to have been obtained from Wang Lu, the technical director of the Sina Interactive Community division, very well. The description of the return parameter is as follows: SYN_RECV indicates the number of requests that are waiting to be processed, established indicates normal data transfer status, time_wait indicates the number of requests that have been processed, waiting for the end of the timeout. ------------------------------------------------------------------Let's take a look at awk:/^tcp/filter out the beginning of the TCP record, blocking UDP, socket and other unrelated records. State[] equivalent to the definition of an array named State NF represents the number of fields recorded, such as the record shown above, NF equals 6$nf represents a field value, such as the record shown above, $NF that is6That represents the value of the 6th field, time_waitstate[$NF] The number of connections that represent the value of the array element, as shown above, the state[time_wait] state++state[$NF] means adding a number to a record, as shown above, is the number of connections to the state[time_wait] state and an end represents the command to be executed in the final stage for(KeyinchState ) to traverse the array print key,"\ t", State[key] Print array of keys and values, in the middle with a \ t tab split, beautify a bit. 

CentOS netstat + awk View TCP's network connection status

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.