16 Linux Server monitoring commands you need to know

Source: Internet
Author: User
ArticleDirectory
    • Iostat
    • Meminfo and free
    • Mpstat
    • Netstat
    • Nmon
    • Pmap
    • PS and pstree
    • SAR
    • Strace
    • Tcpdump
    • Top
    • Uptime
    • Vmstat
    • Wireshark

Original article link

If you want to know what your server is doing, you need to know some basic commands. Once you are proficient in these commands, you are a professional Linux system administrator.

Some Linux distributions provide the GUIProgramFor example, SuSE Linux has a very good and professional tool YaST, and KDE's KDE System Guard is also very good. Of course, to use these tools, you must operate in front of the server, and these GUI programs occupy a lot of system resources. Therefore, although the GUI is used for basic server health status monitoring, if you want to know what actually happens, turn off the GUI and start a command line trip.

You should only start the GUI as needed, and disable it when not needed. To ensure the optimal performance of the server, you should set the runlevel of the Linux server to 3, that is, the console mode. When you need a graphical desktop, use the startx command to start it.

If your server directly enters the graphic interface after it is started, you need to modify the configuration/etc/inittab to find the same initdefault, and change ID: 5: initdefault to ID: 3: initdefault.

If you cannot find the/etc/inittab file, create a new line with the ID: 3 added to the file content. In this way, the graphic interface will not be displayed when the server is started next time. If you do not want to take effect until the server is restarted, you can run the init 3 command.

Once your server runs in Console mode, you can start the following content.

Iostat

The iostat command is used to display the detailed information of the storage subsystem. It is usually used to monitor disk I/O. Pay special attention to the % iowait value in the iostat statistical result, which indicates that your system storage subsystem has low performance.

Meminfo and free

Meminfo allows you to obtain detailed memory information. You can use the cat and grep commands to display meminfo information:

1 Cat /Proc/meminfo

 

In addition, you can use the free command to display dynamic memory usage information. Free only gives you approximate memory information, while meminfo provides more detailed information. For example, the execution result of the free command on oschina:

Mpstat

Mpstat is short for Multiprocessor statistics and is a real-time system monitoring tool. Its report and CPU statistics are stored in the/proc/STAT file. In a multi-CPUs system, it can not only view the average status information of all CPUs, but also view information about specific CPUs.

Let's take a look at the execution results of the mpstat command on oschina:

Refer to this post for the parameter meanings in the mpstat execution results.

Netstat

Similar to the ps command, netstat is a tool commonly used by Linux administrators every day. It displays a large amount of Network-related information, for example, socket usage, routing, interfaces, protocols, networks, etc. Below are some common parameters:

1 -A show all socket Information
2 -R show routing information
3 -I show Network Interface statistics
4 -S show network protocol statistics

 

Nmon

Nmon is an open-source tool widely used to monitor the performance of Linux systems. Nmon monitors performance data of multiple subsystems, such as processor usage, memory usage, queue, disk I/O statistics, network I/O statistics, Memory Page processing, and process information. Nmon also provides a graphical tool:

To run nmon, you can start it in the command line and select the subsystems to be monitored. Each of these subsystems has a shortcut key. For example, you can enter C to view CPU information, M is used to view memory, D is used to view disk information, etc. You can also use the-F command to save the nmon execution result to a CSV file for future analysis.

In my daily monitoring work, I found that nmon is my most commonly used tool.

Pmap

The pmap command is used to report the memory usage of each process. It can be used to check whether the process has been overspending. The command requires the process ID as a parameter.

PS and pstree

PS and pstree commands are the best friends of Linux system administrators and can be used to list all running processes. PS tells you the memory and CPU processing time occupied by each process, while pstree shows less detailed information, but it displays the dependencies between processes in a tree structure, including sub-process information. Once a process is found to be faulty, you can use kill to kill it.

SAR

SAR programs are Swiss Army knives in system monitoring tools. The program contains three tools: SAR for displaying data, SA1 and SA2 for collecting data and saving. SAR can be used to display CPU usage, Memory Page data, network I/O and transmission statistics, process creation activity, and disk device activity details. The biggest difference between SAR and nmon is that SAR is suitable for long-term monitoring, while nmon allows you to quickly understand the current state of the system.

Strace

Strace is often considered a programmer debugging tool, but more than that. It records the details of system calls by processes, so it is also a good diagnostic tool. For example, you can use it to find that a program is opening a configuration file.

Strace also has a defect, but it will make the performance of a process very poor when tracking a process, so please use it with caution.

Tcpdump

Tcpdump is a simple and reliable network monitoring tool for basic protocol analysis. It can be used to see how and when processes are using the network. Of course, if you want to obtain detailed information, you should use Wireshark (we will introduce it below ).

Top

The top command displays the current active process. By default, it is sorted by CPU consumption. The list is refreshed every 5 seconds. You can also select different sorting methods, for example, M is the shortcut key for sorting by memory usage.

Uptime

The uptime Command tells you how long the server has been running since it was started. It also includes the average server load from startup to the present. Let's take a look at oschina's data:

I have forgotten why I restarted the machine last time. It seems that I changed the cabinet.

Vmstat

You can use vmstat to monitor virtual memory. Generally, Linux developers prefer to use virtual memory for optimal storage performance. This command reports statistics on Kernel threads, virtual memory, disks, traps, and CPU activity. Reports generated by the vmstat command can be used to balance system load activities. The statistical information within the system range (in all processors) calculates the average value in percentage or calculates its sum.

The result of executing vmstat on oschina:

Wireshark

Wireshark, formerly known as ethereal, is a network protocol detection program that allows you to capture information about running websites, including the flow of each package, its content, and information, which can be seen in the operating system language, it is convenient to view and monitor TCP session dynamics.

 

Most of the most valuable Linux monitoring programs are listed here. Of course, you may also use other tools to share with you.

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.