Linux system resource viewing and timing tasks

  In the daily management of the server, the viewing and monitoring of system resources is an important part; at the same time, in the operation of the server, some repetitive tasks (service restart, file backup, etc.) need to be performed regularly. In this article, let's take a look at system resource viewing and timing tasks.

Linux

System resource view

topcommand

  topCommands can view the current system health status (resources and usage information) and process information in real time. For specific usage, please refer to: Super detailed Linux process management and work management analysis and application (manual translation command option help)

vmstatcommand

  vmstatThe command provides the function of refreshing and viewing the status of system resources multiple times at intervals. The syntax is as follows

vmstat <time> <n>
#time,n都为数字,time为每次刷新时间间隔,n为刷新总次数

Command execution result:

vmstat

project Description
procs Process usage
memory Memory usage messing around
swap Exchange partition read and write information
I System IO status
system System resource usage
cpu CPU status information

dmesgcommand

  dmesgThe command displays the kernel detection record information when booting, including a series of record information such as hardware detection, process startup, port opening and so on. The file contains a lot of records. It is recommended to cooperate with the grepcommand to find the required content

freecommand

  freeThe command mainly displays system memory usage information,

free -m #主要参数-m,以MB为单位显示

The main display information are total memory, used memory, free memory, shared memory, buffer memory, and buffer memory

(Cache is used to speed up the reading speed of data from the hard disk. Files are read into the cache for temporary storage. When a process needs to be read, the file is read directly from the memory and the transmission speed is greatly accelerated; the buffer is used to "look" Speed ​​up data writing to the hard disk, the system puts the files to be written to the disk into the memory, and writes the files from the buffer when the disk is idle, the writing speed seems to be faster)

cpuinfofile

  The full path of the cpuinfo file /proc/cpuinfo, which catcan be viewed with commands, including the CPU model and various attributes. This file is located in the memory and will be created every time you boot. If there are multiple cores, the information of each core will be listed.

uptimecommand

  uptimeThe command to view information such as system boot time and average load is exactly the same as the wcommand and topthe first line of the command, so I won't introduce it here.

unamecommand

  unameThe command can view the system and kernel version and other information, there are three main options

uname -a #查看所有内核及操作系统版本信息
uname -r #查看内核版本
uname -s #查看内核名称

 View operating system bits

  Linux does not support directly viewing the system bit number, but when the system is installed, it will be accompanied by some external commands other than the kernel command file. You can find the system bit number by viewing the file information of these command files through commands.

 View the files opened by the process

  Use the lsofcommand to list the file information used by the process, there are three main options for filtering information, and no options are displayed for all

Options Description
-c Only list files used by processes starting with a string
-u List only files used by processes belonging to a certain user
-p List files used by processes matching PID
  • If this command uses more than one of the above options, only the first option is used, and the others are invalid.

System timing task

  The realization of system timing tasks mainly relies on a named cronservice (in some releases crond, d is daemon, daemon process). This service usually starts automatically. After the service starts, you crontabcan use commands to view and configure timed tasks.

 crontab command

  The user crontabsets (own) timed tasks through commands. The specific authority profile of the command is in /etc/cron.allowand /etc/cron.deny, and only users who are not in the latter or the former can use this command.

crontab [options] [parameter]

crontab command options:

parameter Description
-l List a list of scheduled tasks for a user
-e Edit crontab timed task list
-r Delete the scheduled task in the list
-u user Operate the timed tasks of the specified user (default for yourself), root privileges are required

After using the -eoption, you will enter an editor, set according to the command syntax, you can configure the required timing command, file format

[1] [2] [3] [4] [5] <task>
#方括号为参数,数字为参数需要,作用在下面表格中列出。task为要执行的任务
Parameter number Description
1 The first minute of the hour
2 Hour of the day
3 The day of the month
4 Month of the year
5 Day of the week (0-7, 0 and 7 are all Sundays)
  • The parameter is generally a number, which conforms to the law of time. In addition, the parameter *indicates that it will be executed every time . Examples are as follows
  • If a command only needs to be executed once, you should set a specific time point instead of filling in the hour and minute columns *, otherwise the task will be executed every hour or even every minute
  • The relationship between the specified day of the week and the specified date is an OR, the task will be executed every day of the week or day, but it is not recommended to use
  • The special syntax ** is ,used to specify multiple dates/times, -specify a date/time period, which */nmeans to execute once every n units**
  • When a timed task executes a Shell script file, if you want to name the script file with a date, you need to %add an \escape character before the date command parameter , because %it has a special meaning in crontab

Example file format:

Example Description
0 0 * * * Perform tasks at 0:00 every day
11 11 * * 7 Perform the task at 11:11 every Sunday
10 10 1,11,21 * * Perform tasks at 10:10 on the 1, 11, and 21 of each month
18 9 * * 1-5 Perform the task at 9:18 every Monday to Friday
Perform the task at 11:11 every Sunday
10 10 1,11,21 * * Perform tasks at 10:10 on the 1, 11, and 21 of each month
18 9 * * 1-5 Perform the task at 9:18 every Monday to Friday
*/10 0 * * * Execute the task every ten minutes at 0:00 every day

Guess you like

Origin blog.csdn.net/Zheng__Huang/article/details/108228704