Five Simple Linux commands help you solve performance problems

Source: Internet
Author: User

Managing Linux Hosts often seems like magic. Many administrators often simplify the process when encountering performance problems. They rely on hardware upgrades, larger memory and stronger CPU to solve the problem. In fact, using some simple commands, you can find many details about managing hosts and quickly and simply solve performance problems.

I. Top

For many administrators, the top command is recently learned. It displays all currently running kernel tasks and provides statistical reports on host statuses. By default, the top command automatically updates the data every five minutes (this update interval is configurable ).

 

 

The top command features are incredibly rich (it is estimated that few have used more than half of the features ). Generally, you will start with the 'H' key, that is, 'help' (the instruction document is also very good ). The help parameters can quickly display the content you can add and subtract, and change the sorting. You can also use K to end the process or use R to mark a special process.

 

The top command displays the normal running time of the day, system load, number of processors, memory usage, and which processes use most CPU resources (including a large amount of related information for each process, for example, online users and commands being executed ).

Ii. vmstat

The vmstat command provides you with a snapshot of the current CPU, Io, process, and memory usage. Like the TOP command, it automatically refreshes dynamically and can be executed using the following command:

 

$ Vmstat 10

 

Here, latency refers to the time in seconds between two refreshes, which is 10 seconds. The vmstat command will refresh the check results on the screen until you end it with the CTRL-C command (or you can set a limit during execution ). This continuous output result is sometimes used to import to a file to analyze the performance trend, but we will find a better way to do this, which will be described later in the article.

 

The first column shows the processor, the R column is the standby processor, and the B column is the sleeping processor. If you see many standby processors, you may encounter performance bottlenecks somewhere. The second column shows the memory: Virtual, idle, buffer, and cache memory. The third column shows the swap storage and the number of exists and exchanges with the disk. The fourth column is the I/O information, showing the block data information received and sent by the block service.

 

The last two columns show information about the system and CPU. The system column displays the number of conflicts and the switch per second. The CPU column displays particularly useful information. Each partition shows the percentage of CPU time. These are as follows:

 

US: Time required to run user tasks and code
Sy: Time required to run the kernel or system code
ID: idle time
Wa: time spent waiting for Io
St: The time occupied by the VM.

 

The vmstat command is good at querying CPU usage. Although it is important to remember that each parameter depends on continuous monitoring, you may not be able to know the real problem of the CPU due to short observation of the CPU. You need to view the long-term running trend to obtain an exact CPU performance information.

Iii. iostat

The following command is iostat. The iostat command (which is provided by the sysstat software package in Ubuntu, red hat, and Fedora Systems) provides three reports: CPU usage, device usage, and Network File System usage. If you run this command without adding any parameters, it displays all the three reports, you can add the-C,-D, and-H parameters to display one of them separately.

 

In the preceding figure, you can see two of the reports. The first is the CPU usage, which lists the CPU usage percentage of each process. You can view User processes, system processes, iowait, and idle time.

 

The second report is about device usage, showing each device installed on the host and some useful information, such as the amount of data transferred per second, data block read/write, and allows you to mark devices with performance problems. You can add the-K or-M parameter to display statistics in kilobytes or megabytes, rather than in data blocks, which makes it easier to view and understand.

 

In the last report, no, the information displayed is similar to the device usage described above, except that the object is replaced by a mounted Network File System from the attached device.

 

Iv. Free

 

The next command is free, which displays the statistics of the primary memory and swap memory.

 

You can add the-t parameter to display the total memory, or add the-B parameter and-M parameter to display the number of cell lines (the unit is kilobytes by default ).

 

You can use the-S parameter to run the free command at a certain interval:

 

$ Free-S 5

 

This command is refreshed every five seconds to run the free command and output the result.

V. SAR

Like many other tools we have seen, we can use SAR commands to collect, view, and record server performance data. It is more powerful than any similar tool we have ever seen and can collect and display data for a long period of time. On Red Hat and Ubuntu, it is installed through the sysstat package. Let's start by running the sar command without adding any parameters:

 

$ SAR

 

 

Here we can see the Basic output information of the SAR command, including CPU statistics (data every 10 minutes and the last average data ). This information is captured from a daily statistical file that keeps collecting information for 24 hours (this file is stored in the/var/log/SA/directory, in the format of saxx, XX represents the date on which the data is collected ). In addition, it also collects statistics on memory, devices, and networks (for example, you can add the-B parameter to view the block device statistics, and-N to view network data, -R parameter depends on memory usage ). You can also use the-a parameter to view all collected data.

 

You can also run the sar command for a long time and import the output data into a file to collect data. To achieve this effect, you need to use the parameter-O and a file name. The time interval between running the command (remember to collect data will cause poor performance, so it is best to ensure that the interval is not too short) and the number of cycles-the number of times you want to record. If you do not enter the number of loops, the sar command will continue to run, for example:

 

$ Sar-a-o/var/log/SAR/sar. Log 600>/dev/null 2> & 1 &

Here we will collect all the data (-A) and record it to the file/var/log/SAR. log is collected every 600 seconds (or 5 minutes) and runs continuously in the background. If we want to display the data, we can use the sar command to add the-F parameter, for example:

$ Sar-a-f/var/log/SAR/sar. Log

This is a very basic introduction to SAR commands. Using SAR commands can also obtain a lot of useful data, which makes it easier and more effective to view host performance. I suggest you check the instructions of the SAR command to obtain more detailed methods to obtain the data you need.

In this article, we see five basic command tools for managing and viewing the performance status on Linux Hosts. In addition, it is worth looking at other tools, such as Munin and collected. They not only collect performance data, but also view applications and services, including using your own plug-ins. These tools support adding graphical input, which allows you to view your data more intuitively with graphics.

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.