16 monitoring commands on the CentOS server

Source: Internet
Author: User
Tags centos server
Do you want to know what your server is doing? You need to know the basic commands described in this article. Once you are familiar with these commands, it lays the foundation for becoming a professional Linux system administrator. You can use a graphical user interface (GUI) program to obtain a large amount of information provided by these shell commands, depending on which Linux release is used. For example, SUSELinux has an outstanding, graphical configuration and management tool YaST, and KDE's KDESystemGuard is also outstanding. However, L

Do you want to know what your server is doing? You need to know the basic commands described in this article. Once you are familiar with these commands, it lays the foundation for becoming a professional Linux system administrator.

You can use a graphical user interface (GUI) program to obtain a large amount of information provided by these shell commands, depending on which Linux release is used. For example, SUSE Linux has an excellent, graphical configuration and management tool YaST, and KDE's KDE System Guard is also outstanding.

However, what Linux administrators need to understand is that they should run the GUI on the server only when absolutely necessary. This is because the Linux GUI consumes system resources, which can be used in other places more rationally. Therefore, even if you use a GUI program to perform a basic health check on the server, disable the GUI if you want to know what happened, start using these tools from the Linux command shell.

This also means that you should enable the GUI on the server as long as you need it; if you don't need it, turn it off in time. To ensure optimal performance, the Linux server should run under runlevel 3, which fully supports the network and multiple users, but does not enable the GUI when the machine starts. If you really need a graphical desktop, you can always run startx from the shell prompt to get a graphical desktop.

If your server enters the graphical desktop after it is started, you need to change this situation. To this end, enter the terminal window, use the su command to switch to the root user, and then open the/etc/inittab file in your frequently-used editor.

Once you enter the file, find the initdefault line and change id: 5: initdefault: to id: 3: initdefault :.

If the/etc/inittab file does not exist, create one and add the line id: 3. Save and exit. The next time you start to enter the server, it will start to enter the runtime level 3. If you do not want to restart after such changes, you can also use the init 3 Command to set the server running level immediately.

Once your server runs under init 3, you can start to use the following shell programs to see what is happening on your server.

Iostat

The iostat command details the storage subsystem. You usually use iostat to monitor the overall running status of the storage subsystem, and detect the slow input/output before the user notices that the server is running slowly. Believe me, you should discover these problems before the user discovers them!

Meminfo and freE

Meminfo displays the memory details for you. You can use another program, such as cat and grep, to access meminfo information. For example, cat/proc/meminfo shows you the usage of the server at any time.

If you want to quickly understand the memory summary, you can use the free command. In short, free provides you with summary information; meminfo provides you with details.

Mpstat

The mpstat command can report the activity of each available processor on a multi-processor server. Today, thanks to multi-core processors, this command applies to almost all servers. Mpstat can also report the average activity of processors on all servers. It enables you to display the total processor statistics by system or by processor. This summary information can be noticed before potential application problems can cause users.

Netstat

Like ps, netstat is also a Linux tool used by Linux administrators every day. It displays a large amount of information related to the network, such as set interface usage, routing, interface, protocol, network statistics and more information. The most common options are as follows:

-A: displays all information of the set interface.

-R: Display route information

-I: displays the statistics of network interfaces.

-S: Displays network protocol statistics

Nmon

Nmon is the short name of the Nigel's Monitor. this popular open-source tool is used to Monitor the performance of Linux systems. Nmon can monitor the performance information of multiple subsystems, such as processor usage, memory usage, running queue information, disk input/output statistics, network input/output statistics, memory paging activity, and process metrics. Then, you can view the real-time system measurement result of nmon through the "graphical" interface of curses.

To run nmon, you can start the tool from the shell. Once started, you only need to enter the single-key command to select the subsystem to be monitored. For example, if you want to obtain statistics on the processor, memory, and disk, you only need to input c, m, and d respectively. You can also use nmon with the-f flag to save the performance statistics to a CSV file for future analysis.

In terms of daily server monitoring, I think nmon is the most useful program in my Linux system management toolkit.

Pmap

The pmap command is used to report the memory used by the server process. You can use this tool to determine which processes on the server are allocated with memory and who are using large amounts of memory.

Ps and pstree

The ps and pstree commands are two effective assistants of the Linux system administrator. They all display all processes currently running in the form of a list. Ps can tell you how much memory and processor time the server program is using. Pstree displays less information, but focuses on the processes that are sub-processes of other processes. With this information, you can discover out-of-control processes and use the kill command of Linux to terminate these processes.

Sar

Sar programs are like Swiss Army knives in the field of system monitoring tools. The sar Command is actually composed of three programs: sar for displaying data, sa1 for collecting data, and sa2 for storing data. Once the installation is complete, sar will generate detailed summary information, showing statistics on processor usage, memory paging activity, network input/output and transmission, process creation activity, and disk device activity. One major difference between sar and nmon is that the former is more suitable for long-term monitoring systems, and I think nmon is more suitable for helping me quickly view the running status of servers.

Strace

Strace is often considered a programmer's debugging tool, but its function is not only used for debugging. It can intercept and record the process calling system. Therefore, it is a practical diagnostic, teaching and debugging tool. For example, you can use strace to find out which configuration file a program uses at startup.

However, strace does have a defect. When it checks a process, the performance of the process will plummet. Therefore, strace is used only when I have an extremely good reason to think that a program causes a problem.

Tcpdump

Tcpdump is a simple and reliable network monitoring utility. Its basic protocol analysis function allows you to roughly view network conditions. However, to analyze the network situation in depth, you should use Wireshark (which is described below ).

Top

The top command displays the status of active processes. By default, it displays the most processor-consuming task running on the server, and refreshes the list every five seconds. You can also classify processes according to multiple criteria, such as PID (process ID); age, latest column at the beginning; time, by accumulative time; as well as resident memory usage and the total time it has been using the processor since startup. I think it provides a fast and easy way to check whether a process is about to get out of control and cause problems.

Uptime

Uptime can be used to view how long a server has been running and how many users have logged on to it. It also displays the summary of the average server load. The best load value is 1 or smaller, which means that each process can access the processor immediately without any loss of the processor cycle.

Vmstat

In general, you can use vmstat to monitor the virtual memory. Linux constantly uses virtual memory to achieve optimal storage performance.

If your application occupies too much memory, you will encounter frequent page-out (page-out) situations-that is, the swap space from the program memory to the system hard drive. Your server may enter this stage: it takes more time to manage memory pages than to run applications-a situation called thrashing ). When your computer is jitters, the performance will drop. Vmstat can display average data or actual samples to help you discover a large number of memory-consuming programs and processes, so that they do not cause the server to run as a snail bait.

Wireshark

Wireshark, formerly known as Ethereal (which is often called this), is a tool similar to tcpdump. However, Wireshark is more advanced with much advanced protocol analysis and reporting capabilities. Wireshark has both a GUI and a shell interface. If you are engaged in professional network management, you can only use ethereal. If you are using Wireshark/ethereal, I strongly recommend that you read the Practical Packet Analysis by Chris Sander ), this book introduces how to make the most of this utility.

This article only outlines some of the most valuable Linux system monitoring programs in general. However, if you are familiar with these programs, it will lay the foundation for becoming the top Linux system administrator.


Related Article

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.