Illustration of the use of top commands in CentOS

Source: Internet
Author: User

Illustration of the use of top commands in CentOS
Top commands are often used to monitor linux system conditions, such as cpu and memory usage. Programmers generally know this command, but it is strange that few people can use it well, for example, the memory value in the top monitoring view has many misinterpretations. This article describes the meaning of various data in the top view through top monitoring of a running WEB server, and sorts the fields of various processes (tasks) in the view. Top entry View


Top view 01 [top View 01] is the basic view of top. We will use this view to explain the meaning of each data. Line 1: 13: 42: 59 the current system time is 6 days, the system has been running for 6 days, 6 hours, 29 minutes (during which the system has not restarted) 3 users currently has three users logging on to the system load average: 3.06, 3.01, 1.79 load average. The three numbers following the load average are 1 minute, 5 minutes, and 15 minutes respectively. The load average data checks the number of active processes every five seconds and then calculates the value based on a specific algorithm. If this number is divided by the number of logical CPUs, the system is overloaded when the result is higher than 5. Row 2: Tasks task (process), the system now has a total of 131 processes, of which 3 are running, 127 are sleeping, and 0 are stoped, zombie status (zombie) has one. Row 3: cpu status: 10.6%. The percentage of user space occupied by CPU. 2.2% percentage of CPU occupied by sy kernel space. 0.0% percentage of CPU occupied by processes whose priority has changed by ni 84.5% percentage of idle CPU by id 2.5% percentage of CPU occupied by wa IO 0.1% percentage of hard interrupt by hi (Hardware IRQ) CPU usage 0.0% si Soft Interrupt (Software Interrupts) CPU usage percentage here the CPU usage rate is different from the windows concept. If you do not understand the user space and kernel space, you need to charge. Row 4: memory status 8300124 k total physical memory total (8 GB) 5979476 k used total memory used (5.7 GB) 2320648 k free idle Memory total (2.2 GB) 455544 k buffers cache memory (434 M) Fifth line: swap partition 8193108 k total swap zone total (8 GB) 41568 k used swap zone total (40.6 M) 8151540 k free swap zone total (8 GB) 4217456 k cached buffer swap zone total (4 GB) Here we must note that the concept of memory in windows cannot be used to understand the data, in windows mode, this server is vulnerable: the total 8 GB memory is only MB of available memory. Linux memory management has its own particularity, And the complexity needs to be explained in a book. Here is just a simple introduction and our traditional concepts (windows) are different. In Row 4, the total memory used (used) refers to the number of memories currently controlled by the system kernel. The total idle memory (free) is the amount of memory that the kernel has not yet incorporated into its control scope. The memory included in the kernel management is not always in use, but also the memory that can be reused in the past, the kernel does not return the reusable memory to free. Therefore, free memory will become fewer and fewer on linux, but you don't have to worry about it. If you calculate the number of available memory out of habit, there is an approximate formula: free in the fourth row + buffers in the fourth row + cached in the fifth row, according to this formula, the available memory of this server is 2320648 + 455544 + 4217456 = 6.6 GB. For memory monitoring, we need to monitor the used of the fifth-line swap partition in top. If this value is constantly changing, it means that the kernel is constantly exchanging data between memory and swap, this is the real insufficient memory. The sixth line is the blank line. The seventh line is as follows: the status of each process (task) monitors the PID process idUSER process owner PR process priority NI nice value. A negative value indicates a high priority. A positive value indicates the total virtual memory used by a low-priority VIRT process, in kb. VIRT = the size of the physical memory used by the SWAP + RESRES process, in kb. RES = CODE + DATASHR shared memory size, in the unit of kbS Process status. D = non-disruptive sleep state R = running S = sleep T = tracking/stopping Z = zombie process % percentage of CPU time consumed by the last CPU update to the present % percentage of physical memory used by the MEM Process percentage TIME + total cpu time used by the process, unit: 1/100 seconds COMMAND process name (COMMAND name/COMMAND line) Multi-U multi-core CPU monitoring in the top basic view, press the number 1 on the keyboard to monitor the status of each logical CPU:

Top view 02: the server has four logical CPUs, which are actually one physical CPU. By default, process fields are sorted by CPU usage when they enter top, in [top View 01], mysqld processes with process ID 3527 ranked first (cpu usage 2%), and java processes with process ID 26955 ranked second (cpu usage 1% ). You can use the Keyboard Command to change the sorting field. For example, if you want to monitor which process occupies the most MEM resources, you can use the following methods: 1. press the keyboard B (TURN ON/OFF THE highlighted effect), and the top view changes as follows:

Top view 03 we found that the top process with the process id 20517 is highlighted, and the running process is highlighted, you can press the y key to close or enable the brightening Effect of running processes. 2. Press the keyboard x (enable/disable the highlight effect of the sorting column). The top view changes as follows:

Top view 04: the default top sorting column is % CPU. 3. shift +> or shift + <can be used to change the sorting column to the right or left, which is based on shift +> once:

The top view 05 is now sorted by % MEM. Change the process display field 1. Press the f key and top to enter another view. Here, you can orchestrate the display field in the basic view:

Top view 06 lists all process fields that can be displayed in the top basic view. Fields marked with uppercase letters are displayed, fields without letters * and lowercase letters are not displayed. To display the CODE and DATA fields in the basic view, you can press the r and s keys:

Top view 072. Press enter to return to the basic view. We can see two more fields: CODE and DATA:

Top view 08

Top Command Supplement top command is the first choice for system monitoring on Linux, but sometimes it does not meet our requirements. The minimum monitoring unit of top Command is process, therefore, the number of threads and the number of client connections cannot be seen. Generally, the ps and netstate commands can be used to supplement the lack of top. Number of java threads monitored: ps-eLf | grep java | wc-l number of network customer connections monitored: netstat-n | grep tcp | grep listening port | two commands above wc-l, you can change the grep parameter to meet more detailed monitoring requirements. Under the guidance of the idea that everything in the Linux system is a file, all processes can run in a file. In the system root directory/proc, the name of each digital subdirectory is the PID of the running process. You can enter any process directory and observe the running indicators of the process through the files or directories, for example, the task directory is used to describe the threads in a process. Therefore, you can use the following method to obtain the number of threads running in a process (PID indicates the process ID ): ls/proc/PID/task | wc-l has a command pmap in linux to output the process memory status. It can be used to analyze the thread Stack: pmap PID.

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.