Small ape circle to share - to monitor the activities of several Linux server command

In Linux monitoring process, we often use some of the commands that are our work more efficient, shorter working hours, to make us more relaxed when getting action. watch watch command is used to easily reuse a Linux system to detect a series of data commands, such as user activity, running processes, log, memory usage and so on. This command is actually a repeat run a specific command, the output will be displayed before each rewrite, it provides a convenient way to monitor activity occurring in your system. First with a foundation and is not particularly useful commands to start, you can run the watch -n 5 date, then you can see the display of the current date and time in the terminal, the data will be updated once every five seconds. You might have guessed, -n 5 option specifies the number of seconds to run the next time the command to wait. The default is 2 seconds. This command will always run and update the display in accordance with the specified time, until you use ^ C to stop it.

  1. Every 5.0s: date butterfly: Wed Jan 23 15:59:14 2019
  2. Wed Jan 23 15:59:14 EST 2019 The following is a more interesting example of the command, you can monitor a user to log in the server list, the list will be updated regularly in accordance with the specified time. As written below, this command will update the list once every 10 seconds. Log out users will disappear from the list of currently displayed, those newly registered will be added to this table them. If no user is logged on or out again, there will not be any different with this form before display.
  3. $ watch -n 10 who
  4. Every 10.0s: who butterfly: Tue Jan 23 16:02:03 2019
  5. shs :0 2019-01-23 09:45 (:0)
  6. dory pts/0 2019-01-23 15:50 (192.168.0.5)
  7. Memory pts / 1 2019-01-23 16:01 (192.168.0.15)
  8. 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 get the average number of users and loads, as well as working conditions of the system calls the uptime command watch.
  9. $ watch uptime
  10. Every 2.0s: uptime butterfly: Tue Jan 23 16:25:48 2019
  11. 16:25:48 up 22 days, 4:38, 3 users, load average: 1.15, 0.89, 1.02 if you want to watch a repeat contains a command pipeline, will be quoted up the command, such as the following to this command displays every five seconds how much time a process is running.
  12. $ watch -n 5 'ps -ef | wc -l'
  13. Every 5.0s: ps -ef | wc -l butterfly: Tue Jan 23 16:11:54 2019
  14. 245 To see the memory usage, you might want to try a combination of the following command:
  15. $ watch -n 5 free -m
  16. Every 5.0s: free -m butterfly: Tue Jan 23 16:34:09 2019
  17. Every 5.0s: free -m butterfly: Tue Jan 23 16:34:09 2019
  18.            total        used        free      shared  buff/cache   available
    复制代码
  19. Mem: 5959 776 3276 12 1906 4878
  20. Swap: 2047 0 2047 you can add some option to view the processes running under a specific user after the watch, but the top aims to provide a better choice. The top command if you want to see the process under a specific user, -u option top command can easily help you achieve this goal.
  21. $ top -u nemo
  22. top - 16:14:33 up 2 days, 4:27, 3 users, load average: 0.00, 0.01, 0.02
  23. Tasks: 199 total, 1 running, 198 sleeping, 0 stopped, 0 zombie
  24. % People (s): 0.0 us, sy 0.2, 0.0 ni, 99.8 id, 0.0 times, 0.0 hi, si 0.0, 0.0 st
  25. MiB Mem : 5959.4 total, 3277.3 free, 776.4 used, 1905.8 buff/cache
  26. MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 4878.4 avail Mem
  27. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  28. Nemo 23026 20 0 46340 7820 6504 0.0 0.1 0 S: 00.05 systemd
  29. 23033 nemo 20 0 149660 3140 72 S 0.0 0.1 0:00.00 (sd-pam)
  30. 23125 nemo 20 0 63396 5100 4092 S 0.0 0.1 0:00.00 sshd
  31. 23128 nemo 20 0 16836 5636 4284 S 0.0 0.1 0: 00.03 zsh you may not only see the process under a user, you can also view the resource occupied by each process, as well as the overall health of the system work. ac command if you want each user to log in to view the system long, you can use the ac command. Before running the command first you need to install acct (Debian, etc.) or psacct (RHEL, Centos etc.) packages. ac command has a series of options, the command to pull in data from wtmp file. This example shows that the total number of hours the recent user login.
  32. $ ac
  33.      total     1261.72
    复制代码

This command displays the total number of hours of user login:

  1. $ And -p
  2.      shark                                5.24
    复制代码
  3.      nemo                                 5.52
    复制代码
  4.      shs                               1251.00
    复制代码
  5.      total     1261.76
    复制代码

This command displays the number of users logged hours per day:

  1. $ ac -d | tail -10
  2. Jan 11 total 0.05
  3. Jan 12 total 1.36
  4. Jan 13 total 16.39
  5. Jan 15 total 55.33
  6. Jan 16 total 38.02
  7. Jan 17 total 28.51
  8. Jan 19 total 48.66
  9. Jan 20 total 1.37
  10. Jan 22 total 23.48
  11. There on the Today total 9.83 summarizes many of the Linux system commands can be used to examine system activity. watch command allows you to duplicate any way to run a command, and observe what happens to the output. The top command is the best option for a user to focus on the process, and allows you to view the process of change in a dynamic way, you can also use the ac command to check the time a user connects to the system. Well, that is so much, I hope you can understand, the role and use these commands, as well as their principles, so that after you work more easily and efficiently.

Reproduced in: https: //juejin.im/post/5cf478eb5188254484193688

Guess you like

Origin blog.csdn.net/weixin_34393428/article/details/91449702