Centos memory CPU calculation method

Source: Internet
Author: User
Processor usage here we need to extract four pieces of data from/proc/stat: user mode, nice mode, and system mode) and idle processor time (idle ). They are located in the first line of the/proc/stat file. The CPU usage is calculated using the following formula. CPU Usage = 100 * (user + nice + system)/(user + nice + system + idle)

CPU usage
Here, we need to extract four pieces of data from/proc/stat: user mode, nice mode, and system mode) and idle processor time (idle ). They are located in the first line of the/proc/stat file. The CPU usage is calculated using the following formula.
CPU Usage = 100 * (user + nice + system)/(user + nice + system + idle)

Idle memory = free + buffers + cached = total-used

Available memory = free memory + cached memory + buffers memory
Real Memory Usage = available memory/total memory (note that the available memory here is calculated by the formula above. In fact, this calculation result is already available in the free command Echo, that is, the third row of the Echo result "-/+ buffers/cached". The second value of this row is the memory after buffers and cached are added, that is, the available memory calculated by the above formula ).

In Linux, you can enter the free command to obtain the memory usage of the current system.
# Busybox free
Total used free shared buffers
Mem: 55636 52808 2828 0 3132
Swap: 0 0 0
Total: 55636 52808 2828
When I typed the above Command with joy, I received a burst of cold sweat, 2828 KB. my system only has more than 2 MB of memory. Can the system still run, is there a command error !!!
Let's take a look at what the results look like in a Linux system on a PC.
# Free
Total used free shared buffers cached
Mem: 4091524 4021016 70508 0 7656 1824312
-/+ Buffers/cache: 2189048 1902476
Swap: 4088532 2891732 1196800
Here I will explain several key concepts first.
Buffers: it is mainly used to buffer block devices in Linux.
Cached: used to buffer the files we open.
Memory is a very valuable resource in the system. Linux uses memory to cache some files if the memory is sufficient and you do not need to use it for whitelist. This speeds up the process; when the memory is insufficient, the memory will be recycled for use by the program.
Therefore, the real available memory is free + buffers + cached = 70508 + 7656 + 1824312 = 1902476.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.