Linux checkup, understand your Linux status (network IO, disk, CPU, memory)

Linux checkup, understand your Linux status (network IO, disk, CPU, memory)

1. Core commands

Linux monitors network IO, disk, CPU, and memory:

CPU: vmstat, sar –u, top

Disk IO: iostat –xd, sar –d, top

Network IO: iftop -n, ifstat, dstat –nt, sar -n DEV 2 3

Disk capacity: df –h

Memory usage: free –m, top

2. Common commands

(1) Memory: number of memory sticks, size of each stick, whether the memory is DDR4 or DDR3, memory frequency is 2666MT/S or 1600MT/s

Number of entries: dmidecode|grep -A5 'Memory Device'|grep Size | grep -v Installed |wc -l
Size of each item: dmidecode|grep -A5 'Memory Device'|grep Size | grep -v Installed |uniq
Memory type: dmidecode | grep -A16 "Memory Device" | grep 'Type:' |grep -v Unknown |uniq
Memory frequency: dmidecode | grep -A16 "Memory Device" | grep 'Speed' |grep -v Unknown |uniq

(2) Hard disk: number of blocks, size

fdisk -l | grep "Disk /dev/sd"

(3) Check which process occupies the port

netstat -antp | fgrep <port>

(4) View process resources

jps -l # Get process id jmap -heap 21046

(5) Number of CPUs

cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

(6) Number of CPU cores

cat /proc/cpuinfo| grep "cpu cores"| uniq

(7) CPU main frequency

cat /proc/cpuinfo| grep "model name"| uniq

3. Detailed explanation of core commands

3.1, ps aux

The ps command is used to view the process status of the system

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

USER,進程所有者的用戶名。

PID,進程號,可以唯一標識該進程。

%CPU,進程自最近一次刷新以來所占用的CPU時間和總時間的百分比。

%MEM,進程使用內存的百分比。

VSZ,進程使用的虛擬內存大小,以K為單位。

RSS,進程占用的物理內存的總數量,以K為單位。

TTY,進程相關的終端名。

STAT,進程狀態,用(R--運行或準備運行;S--睡眠狀態;I--空閑;Z--凍結;D--不間斷睡眠;W-進程沒有駐留頁;T停止或跟蹤。)這些字母來表示。

START,進程開始運行時間。

TIME,進程使用的總CPU時間。

COMMAND,被執行的命令行。

3.2 Top

The top command is a commonly used performance analysis tool under Linux. It can display the resource usage of each process in the system in real time, similar to the Windows Task Manager.

1. The upper part shows the overall system load:

  • The top line: from left to right are the current system time, system running time, and the average CPU load value of the system in the previous 1 minute, 5 minutes, and 15 minutes.
  • Tasks row: This row gives the overall statistical information of the process, including the total number of processes in the statistical period, the number of running processes, the number of dormant processes, the number of stopped processes, and the number of zombie processes
  • Cpu(s) line: overall cpu statistics, including the ratio of cpu time occupied by processes in user mode and system mode, the ratio of cpu time occupied by processes with nice values ​​greater than 0 in user mode, the ratio of time the cpu is in idle state and wait state, and the ratio of time processing hard interrupts and soft interrupts
  • Mem line: This line provides memory statistics, including the total physical memory, used memory, free memory, and the amount of memory used as buffers
  • Swap line: virtual memory statistics, including the total swap space, the size of the used swap area, the size of the free swap area, and the size of the swap space used as cache

2. The lower part shows the running status of each process:

PID: 進程pid

USER: 拉起進程的用戶

PR: 該列值加100為進程優先級,若優先級小于100,則該進程為實時(real-time)進程,否則為普通(normal)進程,實時進程的優先級更高,更容易獲得cpu調度,以上輸出結果中,java進程優先級為120,是普通進程,had進程優先級為2,為實時進程,migration 進程的優先級RT對應于0,為最高優先級

NI: 進程的nice優先級值,該列中,實時進程的nice值為0,普通進程的nice值范圍為-20~19

VIRT: 進程所占虛擬內存大小(默認單位kB)

RES: 進程所占物理內存大小(默認單位kB)

SHR: 進程所占共享內存大小(默認單位kB)

S: 進程的運行狀態

%CPU: 采樣周期內進程所占cpu百分比

%MEM: 采樣周期內進程所占內存百分比

TIME+: 進程使用的cpu時間總計

COMMAND: 拉起進程的命令

According to the above commands, set up monitoring warnings in advance. Monitoring and early warning can enable you to timely discover system performance information, such as the disk is almost full or the memory is overloaded, so we can make adjustments in advance.

Finally, don’t panic when you encounter problems. According to experience, use commands to check memory, disk, network, and CPU. The problems are nothing more than these few categories. Don't rush to make changes and complicate simple problems. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Shell script to check server security status (user, login IP, firewall check)
  • Linux Shell+Curl website health status check script, find out the missing sites of China Blog Alliance
  • Two scripts to check the Linux network status
  • Linux firewall status check method example

<<:  CSS to achieve chat bubble effect

>>:  Getting Started Tutorial for Beginners⑧: Easily Create an Article Site

Recommend

Vue implements various ideas for detecting sensitive word filtering components

Table of contents Written in front Requirements A...

Tips for writing concise React components

Table of contents Avoid using the spread operator...

How to implement nested if method in nginx

Nginx does not support nested if statements, nor ...

Two implementations of front-end routing from vue-router

Table of contents Mode Parameters HashHistory Has...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Detailed explanation of the API in Vue.js that is easy to overlook

Table of contents nextTick v-model syntax sugar ....

How to dynamically modify the replication filter in mysql

MySQL dynamically modify replication filters Let ...

Deeply understand how nginx achieves high performance and scalability

The overall architecture of NGINX is characterize...

The pitfalls encountered when learning Vue.js

Table of contents Class void pointing ES6 Arrow F...

Two ways to export csv in win10 mysql

There are two ways to export csv in win10. The fi...

【HTML element】Detailed explanation of tag text

1. Use basic text elements to mark up content Fir...