16 Linux Server monitoring commands to be known

Source: Internet
Author: User
Tags memory usage socket

Do you want to know what your server is doing? Then you need to know the basic commands described in this article. Once you've mastered these commands, you're laying the groundwork for becoming a professional Linux system administrator.

You can use graphical user interface (GUI) programs to get the bulk of the information that these shell commands provide, depending on which Linux distribution you are using. For example, SUSE Linux has an excellent, graphical configuration and management tool YAST,KDE KDE System Guard is also excellent.

However, a common sense for Linux administrators is that the GUI should be run on the server only when absolutely necessary. That's because the Linux GUI consumes system resources that could have been used more rationally elsewhere. So, while using GUI programs is ideal for a basic check on server health, if you want to know what's going on, turn off the GUI and start using the tools from the Linux command shell.

This also means that you should open the GUI on the server as long as it is needed, and turn it off in time. To ensure the best performance, the Linux server should run at run level (RunLevel) 3, which fully supports the network and multiple users, but does not open the GUI when the machine is started. If you really need a graphical desktop, you can always run StartX from the shell prompt to get a graphical desktop.

If your server starts and goes to a graphical desktop, you need to change this. To do this, go to the terminal window, switch to root using the SU command, and then open the/etc/inittab file with your favorite editor.

Once into the file, find Initdefault this line, will Id:5:initdefault: Change to Id:3:initdefault:.

If you don't have a/etc/inittab file, create one and add the Id:3 line. Exit after saving. The next time you start to enter the server, it will launch into run Level 3. If you do not want to reboot after making this change, you can also use command init 3 to set the server's run level immediately.

Once your server is running under init 3, you can start using the following shell to see what is happening in your server.

  Iostat

The Iostat command displays a detailed picture of the storage subsystem. You typically use Iostat to monitor the overall health of the storage subsystem, and early detection of input/output slowness before the user notices that the server is running slowly. Believe me, you should find these problems before users find them!

  Meminfo and free

Meminfo shows you the memory aspect in detail. You can usually use another program, such as Cat and grep, to access meminfo information. For example, Cat/proc/meminfo gives you a detailed indication of the server's memory usage at any one time.

If you want to get a quick overview of memory, you can use the free command. In short, free provides you with an overview, and Meminfo provides you with detailed information.

Mpstat

The Mpstat command can report the activity of each available processor on a multiprocessor server. Today, thanks to multi-core processors, this command works for almost any server. Mpstat can also report the average activity of the processors on all servers. It allows you to display the total processor statistics according to the system or according to the processor. This profile can be used to alert you to potential application problems before they annoy users.

  Netstat

Netstat, like PS, is a Linux tool that Linux administrators use every day. It shows a large amount of information about the network, such as socket usage, routing, interfaces, protocols, network statistics, and more. Some of the most commonly used options are as follows:

-a displays all information about the socket interface

-R Display Routing information

-I displays network interface statistics

-S displays network protocol statistics

  Nmon

Nmon is the abbreviation for Nigel's Monitor, a popular Open-source tool used to monitor the performance of Linux systems. Nmon can monitor performance information for 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. You can then view the Nmon real-time system metrics by curses the graphical interface.

To run Nmon, you can start the tool from the shell. Once started, you can select the subsystem you want to monitor as long as you enter a single command. For example, to get statistics on the processor, memory, and disk, just enter C, M, and D separately. You can also use Nmon with the-f flag to save performance statistics to a CSV file for later analysis.

As far as day-to-day server monitoring is concerned, I think Nmon is one of the most useful programs in my Linux System Management Toolkit.

  Pmap

The PMAP command is used to report the amount of memory used by the server's processes. You can use this tool to determine which processes are allocated memory on the server, and who in those processes is using the memory heavily.

  PS and Pstree

The PS and Pstree commands are the two right-hand assistants of the Linux system administrator. All of them can display a list of all currently running processes. PS can tell you how much memory and processor time the server program is using. Pstree displays less information, but highlights which processes are child processes of other processes. With this information in hand, you will be able to detect runaway processes and terminate them with the "do not leave Alive" kill command for Linux.

  Sar

The SAR program is like a Swiss Army knife in the field of system monitoring tools. The SAR command is actually composed of three programs: the SAR that displays the data, the SA1 that collects the data, and the SA2 that holds the data. Once installed, SAR can generate detailed profiles showing processor usage, memory paging activity, network input/output and transport statistics, process creation activities, and disk device activity. A big difference between SAR and Nmon is that the former is more suitable for long-term monitoring systems, and I think Nmon is better suited to help me quickly view the health of the server.

Strace

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

But Strace does have a flaw. When it examines a process, the performance of that process can take a nosedive. Therefore, the use of strace is only used if I have a very good reason to think that a program is causing problems.

  Tcpdump

Tcpdump is a simple and reliable network monitoring utility. Its basic protocol analysis allows you to make a cursory view of the situation on the network. But to really delve into the network, you should use Wireshark (described below).

  Top

The top command shows the context of the active process. By default, it shows the most processor-consuming tasks running on the server and refreshes the list every 5 seconds. You can also categorize processes by multiple criteria, such as PID (process ID), age, the most recent column at the front, time, cumulative time, and the total amount of time that the processor has been used since it was started. I think it provides a quick and easy way to see if a process is starting to get out of hand and causing problems.

  Uptime

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

  Vmstat

Generally speaking, you can use Vmstat to monitor virtual memory. Linux continues to use virtual memory for optimal storage performance.

If your application is consuming too much memory, you will experience frequent swap out of memory (page-out)-The swap space in which the program moves from memory to the system's hard drive. Your server may go through this stage: it spends more time managing memory paging than it does on running applications-a situation called dithering (thrashing). When your computer shakes, performance is a nosedive. Vmstat can display average data or actual samples, which can help you detect large amounts of memory-consuming programs and processes, lest they cause the server to run like a snail.

  Wireshark

Wireshark, previously known as ethereal (and still so often called), is a similar tool for tcpdump, but it is more advanced and has much more advanced protocol analysis and reporting capabilities. Wireshark has both GUI interface and Shell interface. If you are engaged in professional-level network management work, you can only use ethereal. And if you're using wireshark/ethereal, I'd strongly recommend reading the "Practical Packet Analysis" (Practical Packet analyses) of Chris Sander, which explains how to make the most of the utility.

This article is a general overview of some of the most valuable Linux system monitoring programs. However, if you are proficient with these programs, you are laying the groundwork for becoming a top Linux system administrator.

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.