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

Pagination Examples and Good Practices

<br />Structure and hierarchy reduce complex...

How to draw a cool radar chart in CocosCreator

Table of contents Preface Preview text Graphics C...

VMware configuration VMnet8 network method steps

Table of contents 1. Introduction 2. Configuratio...

Linux kernel device driver address mapping notes

#include <asm/io.h> #define ioremap(cookie,...

A brief discussion on the implementation of fuzzy query using wildcards in MySQL

In the MySQL database, when we need fuzzy query, ...

Who is a User Experience Designer?

Scary, isn't it! Translation in the picture: ...

Pure CSS to achieve hover image pop-out pop-up effect example code

Implementation principle The main graphics are co...

Sample code for deploying ELK using Docker-compose

environment Host IP 192.168.0.9 Docker version 19...

Detailed explanation of Nginx access restriction configuration

What is Nginx access restriction configuration Ng...

A brief analysis of Vue's asynchronous update of DOM

Table of contents The principle of Vue asynchrono...

Vue implements the magnifying glass function of the product details page

This article shares the specific code of Vue to i...

JavaScript implements circular progress bar effect

This article example shares the specific code of ...