Top of Linux system performance monitoring command series

Time:2020-11-21

hello everyone! This is Sean!

I haven’t updated the article for a long time. I’m busy recently. Next, I’ll share a series of Linux system performance monitoring commands, which I usually use. I think it’s very practical. I hope it can help you in your work.

Top of Linux system performance monitoring command series

Top (display or manage programs in execution)

When it comes to performance monitoring, the most commonly used command is the top command, which is somewhat similar to the task manager of windows system. The top command can dynamically view the overall operation of the system in real time. It is a practical tool that integrates the performance and operation information of multi-party information monitoring system. Through the interactive interface provided by the top command, it can be managed by hotkeys.

Here’s a brain map of what I summarized about the top command.

Top of Linux system performance monitoring command series

Start command parameters

-b: Operate in batch mode;
-c: Display the entire command line instead of just the command name;
-d: Screen refresh interval time;
-1: The failure process is ignored;
-s: In the secure mode, the top command runs in the safe mode, which will remove the potential danger brought by the interactive command;
-S: Cumulative mode, resource status from the beginning to the present;
-I < time >: set the interval time;
-U < user name >: Specifies the user name;
-P < process number >: Specifies the process;
-N < times >: the number of times to display in a cycle.

Interactive command

h: The help screen is displayed, and some brief command summary instructions are given;
k: To terminate a process; terminate;
i: Ignore idle and dead processes, which is a switch command;
q: Exit the program;
r: Rearrange the priorities of a process;
S: Switch to cumulative mode;
s: Change the delay time (in s) between two refreshes. If there is a decimal, it is converted to Ms. Enter a value of 0 and the system will refresh continuously. The default value is 5S;
F or F: add or delete items from the current display;
O or O: change the order of displayed items;
l: Switch to display the average load and start-up time information;
m: Switch display memory information;
t: Display and switch CPU status information;
c: Switch display command name and complete command line;
M: Sort according to the size of resident memory;
P: Sort according to the CPU usage percentage;
T: Sort by time / cumulative time;
w: Write the current settings in toprc ~;

Usage scenarios

Introduce some commonly used scenarios:

  1. How to see if the machine has been down? You can directly look at the first line of information, which contains the system running time and startup time
  2. How to see CPU usage? We only need to look at two places: 1) the third line% CPU (s) information. This is the CPU utilization status from the system startup to the current time. If it is a multi-core CPU, press the number 1 to see the occupancy status of each CPU core. 2) in the process information, the% CPU column shows the CPU usage of each process in the refresh interval. The value of some processes here is often larger than that in% CPU (s), because here is the The value in% CPU (s) tends to a value with the extension of running time. The data dimensions seen in these two places are different. You can look at the data according to the actual situation.
  3. How to see if there is enough memory? 1) Check whether the free of MEM in the fourth line is sufficient. 2) if free is not enough, continue to check whether the free of swap in the fifth line is sufficient, and observe whether the used value changes all the time. If the free value keeps changing, it indicates that there is constant exchange with the hard disk in the fourth line, indicating that the memory is really insufficient.
  4. How to observe resource usage of a process only? The top-p process number will always display the information of a single process. The top-h-p process number will display the information of all threads in the process. These two commands are very useful for positioning problems.

That’s all for today’s sharing! Thank you for reading! Code is not easy, if this article is helpful to you, please give me a favor ~ ha ha.