In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "what is the command to monitor Linux server activity". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Watch command
Watch is a command used to easily repeatedly detect a series of data in a Linux system, such as user activity, running processes, login, memory usage, and so on. This command actually runs a specific command repeatedly, rewriting the previously displayed output each time, providing a convenient way to monitor what is happening on your system.
Starting with a basic and not particularly useful command, you can run watch-n 5 date, and then you can see that the current date and time are displayed in the terminal, and the data is updated every five seconds. As you may have guessed, the-n 5 option specifies the number of seconds to wait to run the next command. The default is 2 seconds. This command will run and update the display at the specified time until you stop it with ^ C.
Every 5.0s: date butterfly: Wed Jan 23 15:59:14 2019 Wed Jan 23 15:59:14 EST 2019
Here is a more interesting example of the command, where you can monitor a list of users logged in to the server, which is updated at a specified time. As written below, this command updates the list every 10 seconds. Logged-out users will disappear from the currently displayed list, and those newly logged in will be added to the table. If no user logs in or logs out again, this form will not be any different from what was previously shown.
$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) nemo pts/1 2019-01-23 16:01 (192.168.0.15) shark pts/3 2019-01-23 11:11 (192.168.0.27)
If you just want to see how many users are logged in, you can call the uptime command through watch to get the average number of users and load, as well as the working status of the system.
$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
If you want to use watch to repeat a command that contains pipes, you need to enclose the command in quotation marks, such as the following command that shows how many processes are running every five seconds.
$watch-n 5'ps-ef | wc-l 'Every 5.0s: ps-ef | wc-l butterfly: Tue Jan 23 16:11:54 2019 245
To view memory usage, you may want to try the following command combination:
$watch-n 5 free-m Every 5.0s: free-m butterfly: Tue Jan 23 16:34:09 2019 Every 5.0s: free-m butterfly: Tue Jan 23 16:34:09 2019 total used free shared buff/cache availableMem: 5959 776 3276 12 1906 4878Swap: 2047 0 2047
You can add some options after watch to see the processes running under a particular user, but top provides a better choice for this.
Top command
If you want to see the processes under a particular user, the-u option of the top command can easily help you do so.
$top-u nemotop-16:14:33 up 2 days, 4:27, 3 users, load average: 0.00,0.01, 0.02Tasks: 199total, 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 stMiB Mem: 5959.4 total, 3277.3 free, 776.4 used 1905.8 buff/cacheMiB 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+ COMMAND23026 nemo 200 46340 7820 6504 S 0.0 0.1 systemd23033 nemo 00.05 systemd23033 nemo 20 0 149660 3140 72 S 0.0 0.1 MEM TIME+ COMMAND23026 nemo 00.00 (sd-pam) 23125 nemo 20 063 396 5100 4092 S 0.0 0.1 systemd23033 nemo 00.00 sshd23128 nemo 20 0 16836 5636 4284 S 0.0 0.1 0:00.03 zsh
You may be able to see not only the processes under a user, but also the resources consumed by each process, as well as the overall working status of the system.
Ac command
If you want to see how long each user in the system has logged in, you can use the ac command. You first need to install the acct (Debian, etc.) or psacct (RHEL, Centos, etc.) packages before running the command.
The ac command has a series of options for pulling data from the wtmp file. This example shows the total number of hours a user logged in recently.
$ac total 1261.72
This command shows the total number of hours the user logged in:
$ac-p shark 5.24 nemo 5.52 shs 1251.00 total 1261.76
This command shows the number of user hours logged in per day:
$ac-d | tail-10 Jan 11 total 0.05Jan 12 total 1.36Jan 13 total 16.39Jan 15 total 55.33Jan 16 total 38.02Jan 17 total 28.51Jan 19 total 48.66Jan 20 total 1.37Jan 22 total 23.48Today total 9.83 "what are the commands for monitoring Linux server activity", thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.