Commands to view system resource usage in Linux

Use 'top -i' to see how many processes are in the Running state. There may be memory or I/O bottlenecks in the system. Use free to check the system memory usage and whether swap is occupied a lot. Use iostat to check the I/O load. ..

Another way is ps -ef | sort -k7 , sort the processes by running time and see which process consumes the most cpu time.

top:
main parameter
d: specifies the update interval, calculated in seconds.
q: Updates without any delays. If the user has superuser, the top command will be executed with the highest priority.
c: Display the complete path and name of the process.
S: Accumulation mode, which will accumulate the CPU time of completed or disappeared sub-strokes.
s: Safe mode.
i: Does not display any idle (Idle) or useless (Zombie) itineraries.
n: Display the number of updates. After completion, it will exit to
display parameters:
PID (Process ID): process identification number.
USER: The username of the process owner.
PR: The priority level of the process.
NI: The priority value of the process.
VIRT: The virtual memory value occupied by the process.
RES: The physical memory value occupied by the process.
SHR: Shared memory value used by the process.
S: The state of the process, where S means sleeping, R means running, Z means dead state, and N means that the priority value of the process is negative.
%CPU: The CPU usage occupied by the process.
%MEM: The percentage of physical memory and total memory occupied by the process.
TIME+: The total CPU time occupied by the process after it was started.
Command: The name of the startup command started by the process. If this line cannot be displayed, the process will have a complete command line.
During the use of the top command, you can also use some interactive commands to complete the functions of other parameters. These commands are launched via shortcut keys.
<space>: Refresh immediately.
P: Sort by CPU usage size.
T: Sort by time and accumulated time.
q: Quit the top command.
m: Toggle display of memory information.
t: Toggle to display process and CPU status information.
c: Toggle showing command name and full command line.
M: Sort by memory usage.
W: Write the current settings to the ~/.toprc file. This is the recommended way to write top configuration files.

free
1. Function
The free command is used to display the memory usage, and the usage authority is for all users.

2. Format
free [-b-k-m] [-o] [-s delay] [-t] [-V]

3. Main parameters -
b-k-m: take bytes (KB, MB) as Units show memory usage.
-s delay: Displays how many seconds to display memory usage.
-t: Display the memory sum column.
-o: Do ​​not display the buffer adjustment column.

uptime
18:59:15 up 25 min, 2 users, load average: 1.23, 1.32, 1.21
The current time The elapsed time since the
system powered on
. The number of connected users. The system load in the
last minute, five minutes, and fifteen minutes.
Parameters: -V Display version information.

vmstat
procs -----------memory------------ ---swap-- -----io---- --system-- ----cpu ----
rb swpd free buff cache si so bi bo in cs us sy id wa
0 1 24980 10792 8296 47316 5 19 205 52 1161 698 26 3 1 70
1 Observe disk activity
Disk activity is mainly understood from the following indicators :
bi: Indicates the number of blocks read from disk per second (blocks/s). The higher the number, the more activity reading the disk.
bo: Indicates the number of blocks written to disk per second (blocks/s). Higher numbers indicate more activity writing to disk.
wa: The percentage of time that the cpu waits for disk I/O (pending disk IO). The higher the number, the more the filesystem activity is holding back the cpu as it waits for the slow disk system to provide data. A wa of 0 is ideal. If wa is often greater than 10, the file system may need performance tuning.
2 Observe the cpu activity
vmstat can better reflect the cpu usage than top:
us: the percentage of time that the user program uses the cpu. The higher the number, the more busy the user process is.
sy: The percentage of time the system calls use the CPU. Note that since NFS runs in the kernel, the CPU time occupied by NFS activities is reflected in sy. If this number is often very large, you need to pay attention to whether a certain kernel process, such as NFS, has a heavy task. If both us and sy are relatively large at the same time, it is necessary to consider separating some user programs to another server to avoid mutual influence.
id: The percentage of time the CPU is idle.
wa: The percentage of time that the cpu waits for pending disk IO.

iostat
is used to count CPU usage and I/0 volume of tty devices, hard disks and CD-ROMs
Parameters :
-c only display CPU lines
-d display disk lines
-k display disk output in kilobytes
-t in output include timestamp
in -x include extended disk metrics in output

avg-cpu: %user %nice %sys %iowait %idle
20.25 0.18 2.61 76.39 0.57
%iowait Percentage of CPU idle time waiting for local I/O
%idle not waiting Percentage of CPU idle time during local I/O

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
hda 9.86 284.34 84.48 685407 2036
Transfers per second (tps), 512-byte block reads per second (Blk_read/s), The total number of 512-byte block writes (Blk_wrtn/s) and 512-byte block reads (Blk_read) and writes (Blk_wrtn) per second.
  System
  # uname -a # View kernel/OS/CPU information
  # head -n 1 /etc/issue # View OS version
  # cat /proc/cpuinfo # View CPU information
  # hostname # View computer name
  # lspci -tv # Columns List all PCI devices
  # lsusb -tv # List all USB devices
  # lsmod # List loaded kernel modules
  # env # View environment variables
  Resources
  # free -m # View memory usage and swap usage
  # df -h # View The usage of each partition
  # du -sh # View the size of the specified directory
  # grep MemTotal /proc/meminfo # View the total amount of memory
  # grep MemFree /proc/meminfo # View the amount of free memory
  # uptime # View system running time, number of users, load
  # cat /proc/loadavg # View system load
  disks and partitions
  # mount | column -t # View mounted partition status
  # fdisk -l # View all partitions
  # swapon -s # View all swap partitions
  # hdparm -i /dev/hda # View disk parameters (only for IDE devices)
  # dmesg | grep IDE # View IDE device detection status at startup
  Network
  # ifconfig # View properties of all network interfaces
  # iptables -L # View firewall settings
  # route -n # View routing table
  # netstat -lntp # View all listening ports
  # netstat -antp # View all established connections
  # netstat -s # View network statistics
  Process
  # ps -ef # View all processes
  # top # Real-time Display process status
  User
  # w # View active users
  # id # View specified user information
  # last # View user login log
  # cut -d: -f1 /etc/passwd # View all users in the system
  # cut -d: -f1 /etc/ group # View all groups in the system
  # crontab -l # View the scheduled tasks of the current user
  Services
  # chkconfig --list # List all system services
  # chkconfig --list | grep on # List all started system services
  Program
  # rpm -qa # View all installed packages

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326819718&siteId=291194637