View Linux CPU and memory utilization __linux

Source: Internet
Author: User
Tags memory usage cpu usage

During system maintenance, you may need to look at the CPU usage at any time, and analyze the system condition according to the corresponding information. In CentOS, you can view CPU usage through the top command. When you run the top command, the CPU usage status is displayed in full screen and in a conversational mode-with the command based on top, you can control how the display is displayed, and so on. The command to exit Top is Q (hit Q key once in top run).

Action Example:

Enter top on the command line

You can start top

Top Full Screen Dialog mode can be divided into 3 parts: System Information Bar, command input bar, process list bar.

The first part--The top System Information Bar:

First line (top):

"00:11:04" is the current moment of the system;

"3:35" to the current operating time after the system is started;

"2 users" for the current user login to the system, or, more specifically, the number of users login to the user's terminal-the same user at the same time to the system more than one terminal connection will be considered as multiple users connected to the system, where the number of users will also appear as the number of terminals;

"Load average" is the average of the current system load, the following three values are 1 minutes ago, 5 minutes ago, 15 minutes before the average process, the general can be considered that the number of CPUs, the CPU will be more laborious load the current system contains processes;

Second line (Tasks):

"Total" is the current number of system processes;

"1 Running" is the number of processes currently running;

"Sleeping" is the number of processes currently in the waiting state;

"0 stoped" is the number of system processes stopped;

"0 Zombie" for the number of recovered processes;

Third line (Cpus):

The current utilization rate of CPU is indicated respectively.

Line Four (MEM):

Represents the total amount of memory, current usage, amount of idle memory, and the amount of RAM used in the buffer;

Line Five (Swap):

Represents a category with line fourth (MEM), but this reflects the usage of swap partitions (swap). Typically, swap partitions (swap) are used frequently, and are considered to be the result of insufficient physical memory.

Part Two--internal command prompt bar in the middle section:

The top command allows you to control how the process is displayed through the top's internal commands. The internal command follows the following table:

S

-Change the frequency of the screen update

L-The representation of the first line top information on the first section is closed or opened

T-closes or opens the first part the second line of Tasks and third line Cpus information representation

M-to close or open the first section the representation of the four-line Mem and fifth-line Swap information

N-Arranges the list of processes in the order of the PID size (Part III)

P-Arranges the list of processes in the order of CPU usage (Part III)

M-Arranges the list of processes in the Order of Memory occupancy (Part III)

H-Show help

N-Sets the number of processes displayed in the process list

Q-Exit Top

S-

Change the screen update cycle

Part three--The process list bar in the bottom section:

The PID-Differentiated process list updates periodically according to the set of screens. You can control how this is displayed through the top internal command

View memory under Linux We generally use free command:
[root@scs-2 tmp]# free
              total       used       free      shared    buffers     Cached
mem:        3266180    3250004      16176           0     110652    2668236
-/+ buffers/cache:      471116    2795064
swap:      2048276       80160    1968116

The following is an explanation of these values:
Total: The amount of physical memory.
Used: How big it has been used.
Free: How many are available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How big it has been used.
Free: How many are available.
The line four is not much explained.
Difference: The difference between the used/free of the second line (MEM) and the used/free of the third row (-/+ Buffers/cache). The difference between the two is that the first line is from the OS point of view, because for os,buffers/cached is used, so his available memory is 16176KB, the used memory is 3250004KB, which includes, the kernel (OS) uses + Application (X, oracle,etc) used by +buffers+cached.
The third line refers to the application from the point of view of the application, buffers/cached is equal to available, because buffer/cached is to improve the performance of file read, when the application needs to use memory, the buffer/cached will be quickly recycled.
So from an application perspective, the available memory = System Free memory+buffers+cached.
As in the previous example:
2795064=16176+110652+2668236

Then explain when memory will be exchanged and by what side. When the available memory is less than the rated value, the meeting is exchanged.
How to look at ratings:
Cat/proc/meminfo

[Root@scs-2 tmp]# Cat/proc/meminfo
memtotal:3266180 KB
memfree:17456 KB
buffers:111328 KB
cached:2664024 KB
swapcached:0 KB
active:467236 KB
inactive:2644928 KB
hightotal:0 KB
highfree:0 KB
lowtotal:3266180 KB
lowfree:17456 KB
swaptotal:2048276 KB
swapfree:1968116 KB
Dirty:8 KB
writeback:0 KB
mapped:345360 KB
slab:112344 KB
committed_as:535292 KB
pagetables:2340 KB
vmalloctotal:536870911 KB
vmallocused:272696 KB
vmallocchunk:536598175 KB
hugepages_total:0
hugepages_free:0
hugepagesize:2048 KB

Results viewed with free-m:
[Root@scs-2 tmp]# Free-m
Total used free shared buffers Cached
mem:3189 3173 16 0 107 2605
-/+ buffers/cache:460 2729
swap:2000 78 1921


To view the size of the/proc/kcore file (memory mirroring):
[Root@scs-2 tmp]# ll-h/proc/kcore
-R--------1 root root 4.1G June 12:04/proc/kcore

Note:

Measurement of memory footprint

Measuring how much memory a process consumes, Linux provides us with a convenient way, the/proc directory provides us with all the information, in fact, top and other tools to get the appropriate information.

Memory usage information for/proc/meminfo machines

The/proc/pid/maps PID is the process number that displays the virtual address occupied by the current process.

Memory consumed by the/PROC/PID/STATM process

[Root@localhost ~]# CAT/PROC/SELF/STATM

654 57 44 0 0 334 0

Output explanation

CPU and CPU0 ... The meaning of each parameter (in the first act) of each row is:

Parameter Interpretation/proc//status

Size (pages) task virtual address space VMSIZE/4

The size of the physical memory that the resident (pages) application is using VMRSS/4

Shared (pages) share pages 0

The size of the executable virtual memory owned by the TRS (pages) program VMEXE/4

Lrs (pages) the size of the library that is imaged to the virtual memory space of the task VMLIB/4

Drs (pages) program data segment and user state stack size (vmdata+ VMSTK) 4

DT (pages) 04

View Machine available memory

/proc/28248/>free

Total used free shared buffers Cached

mem:1023788 926400 97388 0 134668 503688

-/+ buffers/cache:288044 735744

swap:1959920 89608 1870312

When we look at the idle memory of the machine by using the free command, we find that the value of the freed is very small. This is mainly because, in Linux, there is such a thought, not white memory, so it as much as possible cache and buffer some data to facilitate the next use. But in fact, these memory can also be used immediately.

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

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.