We deal with Linux servers every day, especially Linux engineers. In order to ensure the security and performance of the server, we often need to monitor some status of the server to ensure that the work can proceed smoothly. The several commands introduced in this article are not only suitable for server monitoring, but also for our daily development. 1. watch The watch command is used frequently. Its basic function is to repeatedly execute a certain instruction at a specified frequency. Using this command, we can repeatedly call some commands to achieve the purpose of monitoring the server. By default, the watch command executes every 2 seconds, but we can use the
One server must be used by many people, especially the colleagues in the department. To see if these friends are taking advantage of the situation, we can use some commands to monitor them. We can execute the who command every 10 seconds to see who is using the server. $ watch -n 10 who Every 10.0s: who butterfly: Tue Jan 23 16:02:03 2019 shs :0 2019-01-23 09:45 (:0) dory pts/0 2019-01-23 15:50 (192.168.0.5) alvin pts/1 2019-01-23 16:01 (192.168.0.15) shark pts/3 2019-01-23 11:11 (192.168.0.27) If we find that the system is running very slowly, we can call the uptime command to view the average system load. $ watch uptime Every 2.0s: uptime butterfly: Tue Jan 23 16:25:48 2019 16:25:48 up 22 days, 4:38, 3 users, load average: 1.15, 0.89, 1.02 Some key processes must not fail, otherwise it may affect business operations, so we can repeatedly count the number of all processes in the server. $ watch -n 5 'ps -ef | wc -l' Every 5.0s: ps -ef | wc -l butterfly: Tue Jan 23 16:11:54 2019 245 To dynamically know the server memory usage, you can execute the free command repeatedly. $ watch -n 5 free -m Every 5.0s: free -m butterfly: Tue Jan 23 16:34:09 2019 total used free shared buff/cache available Mem: 5959 776 3276 12 1906 4878 Swap: 2047 0 2047 Of course, it's not just these. We can also call many commands repeatedly to monitor some key parameters of the server. 2. top Using the top command we can know many key parameters of the system, and they are updated dynamically. By default, top monitors the overall status of the system. If we only want to know the usage of a certain person, we can use the $ top -u alvin top - 16:14:33 up 2 days, 4:27, 3 users, load average: 0.00, 0.01, 0.02 Tasks: 199 total, 1 running, 198 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 5959.4 total, 3277.3 free, 776.4 used, 1905.8 buff/cache MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 4878.4 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23026 alvin 20 0 46340 7820 6504 S 0.0 0.1 0:00.05 systemd 23033 alvin 20 0 149660 3140 72 S 0.0 0.1 0:00.00 (sd-pam) 23125 alvin 20 0 63396 5100 4092 S 0.0 0.1 0:00.00 sshd 23128 alvin 20 0 16836 5636 4284 S 0.0 0.1 0:00.03 zsh In this result, you can not only see the number of all processes run by the user alvin, but also the system resources (CPU, memory) consumed by each process, while still being able to see the key parameters of the entire system. 3. ac If you want to know the time taken by each user logged into the server, you can use the ac command. This command requires you to install If we want to know the total time taken by all users to log in to the server, we can run the ac command directly without any parameters.
If we want to know the time used by each user, we can add the $ ac -p shark 5.24 alvin 5.52 shs 1251.00 total 1261.76 We can also add the $ ac -d | tail -10 Jan 11 total 0.05 Jan 12 total 1.36 Jan 13 total 16.39 Jan 15 total 55.33 Jan 16 total 38.02 Jan 17 total 28.51 Jan 19 total 48.66 Jan 20 total 1.37 Jan 22 total 23.48 Today total 9.83 summary We can use many commands to monitor the running status of the system. This article mainly introduces three commands: the watch command allows you to repeatedly execute a command to monitor the changes of some parameters, the top command can view the number of processes run by a user and the resources consumed, and the ac command can view the server time used by each user. This is the end of this article on how to monitor the Linux server status. For more information about Linux server status, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue uses Baidu Maps to realize city positioning
>>: How to use union all in MySQL to get the union sort
Table of contents 1. Prepare materials 2. Downloa...
Table of contents Preface 1. Project Architecture...
Look at the code: Copy code The code is as follows...
vue+element UI encapsulates a public function to ...
The official document states: By injecting the ro...
This article shares the specific code of js to im...
Table of contents 1. Introduction 2. Direct recov...
The CSS3 category menu effects are as follows: HT...
1. IE8's getElementById only supports id, not ...
This article uses examples to illustrate the usag...
Table of contents Dynamically change themes The f...
Table of contents Pull the image Run the image (g...
Zen Coding It is a text editor plugin. In a text ...
Note: This article is about the basic knowledge p...
Currently, many businesses are conducting promoti...