Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of viewing system load by Linux

2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method of Linux to view the system load, the article is very detailed, has a certain reference value, interested friends must read it!

The load state of the operating system reflects the resource usage of the application, from which we can find out the bottleneck of the application optimization.

The average system load is the average number of processes in a running or undisturbed state. \

Running, indicating running state, occupying CPU, or ready, waiting for CPU scheduling. \

Do not disturb, indicates blocking, waiting for Igamo

On Linux systems, to check the load, you usually use the uptime command (w and top commands are also available) *

1. Uptime command

$uptime\ 16:33:56 up 69 days, 5:10, 1 user, load average: 0.14,0.24,0.29

The above information is parsed as follows:

16:33:56: current time

Up 69 days, 5:10: the system ran for 69 days, 5 hours and 10 minutes

1 user: currently there is 1 user logged in to the system load average: 0.14,0.24,0.29: the average load of the system in the past 1 minute, 5 minutes, 15 minutes

Load average: 0.14,0.24,0.29: average load of the system in the past 1 minute, 5 minutes, 15 minutes

Average load analysis

View the number of logical CPU cores:

$grep 'model name' / proc/cpuinfo | wc-l\ 1\

The running results show that there is 1 logical CPU core. Take a CPU core as an example, assuming that CPU processes up to 100 processes per minute-

Load=0, no process requires CPU

Load=0.5,CPU handled 50 processes

Load=1, CPU handled 100 processes, by this time the CPU was full, but the system still worked smoothly.

Load=1.5, CPU has handled 100 processes, and there are still 50 processes being excluded for CPU processing. By this time, CPU is already overloaded.

For the system to run smoothly, it is best to have a load value of no more than 1. 0, so that there are no processes to wait and all processes can be processed in the first place. \

Obviously, 1.0 is a key value, beyond which the system is not at its best. Generally 0.7 is an ideal value. \

In addition, the health status of the load value is also related to the number of CPU cores of the system. If the number of CPU cores is 2, then the load value health value should be 2, and so on. \

The load of the evaluation system is generally the average load value within 15 minutes.

II. W command

W\ 17:47:40 up 69 days, 6:24, 1 user, load average: 0.46,0.26,0.25\ USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\ lvinkim pts/0 14.18.144.2 15:55 0.00s 0.02s 0.00s w

Line 1: same as uptime one. \

Below line 2, the list of currently logged-in users.

3. Top command

$top\ top-17:51:23 up 69 days, 6:28, 1 user, load average: 0.31,0.30,0.26\ Tasks: 99 total, 1 running, 98 sleeping, 0 stopped, 0 zombie\ Cpu (s): 2.3%us, 0.2%sy, 0.0%ni, 97.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st\ Mem: 1922244k total, 1737480k used 184764k free, 208576k buffers\ Swap: 0k total, 0k used, 0k free 466732k cached\\ PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND\ 1 root 20 0 19232 1004 708 S 0.0 0 010 init\ 2 Root 20 00 00 S 0.0 0 00.01 kthreadd\.

Line 1: same as uptime one.

Line 2: number of processes information.

Tasks: 99 total: a total of 99 processes

1 running: 1 process is occupying CPU

98 sleeping: 98 sleep processes

0 stopped: 0 stopped processes

0 zombie: 0 zombie processes

Line 3: CPU usage

Us (user): the percentage of CPU occupied by non-nice user processes

Sy (system): the percentage of CPU occupied by kernel and kernel processes

Ni (nice): the ratio of CPU occupied by processes that have changed priorities in the user's process space

Id (idle): CPU idle ratio. If the system is slow and this value is high, the reason for the slow system is not the high CPU load.

Wa (iowait): the percentage of time that CPU waits to perform the I _ id operation, which can be used to troubleshoot disk I _ Unio problems, usually in combination with wa and id.

Hi (Hardware IRQ): the percentage of time that CPU takes to handle hardware interrupts

Si (Software Interrupts): the percentage of time taken by CPU to handle software interrupts

St (steal): elapsed time, the ratio of other tasks in the virtual machine to CPU time

Some situations to be aware of:

The proportion of us of user processes is high, while the wa of Igamot operation is low: it shows that the reason why the system is slow is that the process takes up a lot of CPU, and it is usually accompanied by a low idle ratio id, indicating that the idle time of CPU is very little.

Low wa and high idle ratio id of Icano operation: it can eliminate the possibility of CPU resource bottleneck.

Wa is high: it takes up a lot of CPU time and needs to check the use of swap space. Swap space is located on disk and its performance is much lower than memory. When memory is exhausted and starts to use swap space, it will have a serious impact on performance. Therefore, it is recommended to turn off swap space for servers with high performance requirements. On the other hand, if you have plenty of memory, but the wa is high, you need to check which process takes up a lot of Imax O resources.

More load situations can be judged flexibly in practice.

4. Iostat command

The iostat command can view the IO usage of the system partition

$iostat\ Linux 2.6.32-573.22.1.el6.x86_64 (sgs02) 01 steal 20 avg-cpu:% user% nice% system% iowait% steal% idle\ 2.29 0.00 0.25 0.04 0.00 97.41\\ Device: tps Blk_read/s Blk_wrtn/s Blk_ Read Blk_wrtn\ vda 1.15 3.48 21.88 21016084 131997520

Some noteworthy IO metrics:

Device: disk name

Tps: number of transfer requests per second

Blk_read/s: how many blocks are read per second. For more information on block size, please see the command tune2fs.

Blk_wrtn/s: how many blocks are written per second

Blk_read: how many pieces have you read?

-Blk_wrtn: how many pieces have been written?

5. Iotop command

The iotop command is similar to the top command, but shows the situation of each process, which plays an important role in locating the processes with heavy operation. \

# iotop\ Total DISK READ: 0.00Bamp s | Total DISK WRITE: 774.52 K jbd2/vda1 s\ TID PRIO USER DISK READ DISK WRITE SWAPIN IO > COMMAND\ 272 be/3 root 0.00BUnip s 0.00BUnip s 0.00% 4.86% [jbd2/vda1-8]\ 9072 be/4 mysql 0.00 mysqld s 268.71 KAccord s 0.00% 0.00% mysqld\ 5058 be/4 lvinkim 0.00 BAccord s 3.95 KAccord s 0.00% 0.00% php-fpm: pool www\ 1 be/4 root 0.00 BAccord s 0.00% 0.00% init

You can see the reading and writing intensity of different tasks.

VI. Sysstat tools

In many cases, when you detect or know the historical high load situation, you may need to play back the historical monitoring data, then the sar command comes in handy. The sar command also comes from the sysstat toolkit, which can record the system's CPU load, Iamp O status and memory usage records, so as to facilitate the playback of historical data.

The configuration file of sysstat is in the / etc/sysconfig/sysstat file, and the history log is stored in / var/log/sa\

Statistics are recorded every 10 minutes, and the statistics file is split at 23:59 every day, and the frequency of these operations is configured in the / etc/cron.d/sysstat file. \

7. Sar command

Use the sar command to view the current day's CPU usage:

$sar\ Linux 2.6.32-431.23.3.el6.x86_64 (szs01) 01 CPU 20Universe 2017 _ x8631 641 CPU\ 10:50:01 AM CPU% user% system% iowait% steal% idle\ 11:00:01 AM all 0.45 0.00 0.22 0.40 0.00 98.93\ Average: All 0.45 0.00 0.22 0.40 0.00 98.93

Use the sar command to view current-day memory usage:

$sar-r\ Linux 2.6.32-431.23.3.el6.x86_64 (szs01) 01 _ x86 August 641 CPU\\ 10:50:01 AM kbmemfree kbmemused% memused kbbuffers kbcached kbcommit% commit\ 11:00:01 AM 41292 459180 91.75 44072 164620 822392 164.32\ Average: 41292 459180 91.75 44072 164620 822392 164.32

Use the sar command to view the current day's IO statistics:

$sar-b\ Linux 2.6.32-431.23.3.el6.x86_64 (szs01) 01On20 CPU\\ 10:50:01 AM tps rtps wtps bread/s bwrtn/s\ 11:00:01 AM 3.31 2.14 1.17 37.18 16.84\ Average: 3.31 2.14 1.17 37.18 16.84 and above are all the contents of Linux's method of viewing the system load Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report