Linux server performance Tracking and server monitoring common commands

Source: Internet
Author: User
Tags current time memory usage cpu usage

In Web site performance optimization, we often have to check the various indicators of the server in order to quickly find the black sheep. In most cases, we use monitoring software such as cacti, Nagois, or Zabbix, but this kind of software is cumbersome to install, and in a small server we want to find out as quickly as possible, or use some of the commands that Linux provides.

1. Memory Check: free-m

Note that the focus is on the second line, the-/+ Buffers/cache line, the first digit is the actual memory consumed, and the second is the actual free memory.

2. System process monitoring Top
The top command looks at the second and third lines of output. The second line (Tasks) represents the number of processes the system is running, which is generally not too large, such as more than 300, or even 400-500, this is easier to understand, we generally open the services, processes and system processes are not too much, too many certainly have problems. The third line indicates CPU usage.
Top can be sorted by M by memory, p by CPU usage.

3. Process monitoring and strengthening version htop
Htop offers more powerful features than top, and recommends installation. Can sort, find, display the process tree and other functions.
Htop also has a powerful function, that is, strace, pressing S can directly strace the selected process.

The Strace effect chart is as follows:

4. Find the Black Sheep (PS command)
If we analyze the system through top, htop, free, and Iostat, Vmstat, then we'll find the system's problem process. In the top, htop we can generally intuitively see that the process has gone wrong, but sometimes these two commands are not fully determined, we also use PS to identify the worst process in the system.

Custom output Format-O you can define the columns that we want to display, the column names are basically the same as the headers of the output, only lowercase, as follows:
Ps-a-O%mem,%cpu

Find instances running too many processes (server monitoring is particularly useful)

You can see that there are more httpd processes, (Uniq may be as long as each row, no longer count duplicates), so we can add a sort (k to sort by that column), as follows:

So the httpd process can see 18 of them, helping us find the unusual server behavior. If you want to differentiate users, you can add an output, such as:

Ps-a-O user,comm |sort-k2| Uniq-c |sort-k1-rn

Find the process with the most memory usage

Ps-eo Rss,pmem,pcpu,vsize,args |  Sort-k 1-r-N

Similarly, find the process with the most CPU consumption

Ps-eo Rss,pmem,pcpu,vsize,args |  Sort-k 2-r-N

(In fact, the main is to understand Sort-k and Ps-o can)

4. IO monitoring Iostat
Iostat is also a commonly used command of system monitoring, you can see the IO situation of each disk, other parameters are no longer repeat, the main description of a parameter. Iostat-x will output%util columns.
Defined:
%util: How much time is spent in a second for I/O operations, or how many times in a second I/O queues are non-empty. The delta (use)/s/1000 (because the unit of use is in milliseconds)
If%util is close to 100%, there are too many I/O requests, the I/O system is full, and the disk may have a bottleneck.
In general,%util should be as small as possible, 10% below normal, 30%io more busy. More than 50% is generally problematic. Can be combined with%idle, the value of the small system is certainly problematic.

5. Vmstat System Monitoring
Vmstat and Io Poor however, but the focus is on monitoring CPU, memory and other system resources.
For memory monitoring, we are more concerned about SWPD, free, si, and so. When the general system is not busy, we see that the value of SWPD,SO will not last very high, often 0. If the SWPD is too high, then the system memory is often not enough.
For CPU monitoring, we can view R (run process number), US, SY, ID (Idle CPU), if the number of R is larger than the number of system CPUs, the risk of the CPU is not enough, through the ID (CPU idle ratio) analysis, if too small, you can be judged to be insufficient CPU.
Other parameters are no longer in detail.

6. Network Traffic monitoring Iftop
Finally, we talk about network traffic monitoring, network traffic for the system is also very important. Please install Iftop to monitor network browsing resources. Because the interface scaling more difficult, from the Internet to find a picture reference:

The middle of these two left and right arrows, indicating the direction of the flow.
TX: Send Traffic
RX: Receive Traffic
Total: Gross flow
Cumm: Total flow of running iftop to current time
Peak: Peak Flow
Rates: The average traffic of the past 2s 10s 40s respectively

Some of these commands are useful, press T to toggle the display format to 2 lines/1 lines/Show only send traffic/show only receive traffic, press T to toggle whether the total flow of each connection is displayed, and press p to toggle whether the port information is displayed. Other commands can be entered into the Help view by H.

Append a command, Nethogs, Iftop is the port and host query traffic, but when the need to query the specific process of network traffic, Iftop is a bit powerless. Nethogs official said nethogs = Nettop, which is to find out all the processes by the footprint, can help us find the process with the most bandwidth

Nethogs is a terminal network traffic monitoring tool, which is unique in that you can display the bandwidth consumption of each process, so that more intuitive access to network usage. It supports IPV4 and IPV6 protocols, supports local network cards, and PPP links.

Project home: http://nethogs.sourceforge.net/

# Installation: This program is available in Ubuntu's official source

The code is as follows Copy Code

sudo apt-get install Nethogs

Use

The code is as follows Copy Code

sudo nethogs eth0

The program requires root permissions, the default is to monitor the Eth0 network card, so direct input sudo nethogs can also, if there are multiple network adapters must be specified

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.