Vmstat & Linux Shell memory monitoring

Source: Internet
Author: User

1. view the current system memory usage (free ):

The free command has the following common options:

-B displays data in bytes.

-K displays data in kilobytes (Kb) (default value ).

-M displays data in MB.

-S delay this option will enable free to refresh continuously. The interval between each refresh is the number of seconds specified by delay. If it contains a decimal point, it will be precise to milliseconds, for example, 0.5 is 500 milliseconds, 1 is a second.

The free command output table contains the following columns:

Total: total physical memory size.

Used: memory used.

Free: The amount of memory available.

Shared: The total memory shared by multiple processes.

Buffers/cached: disk cache size.

See the following examples and output instructions:

[Root @ Rony ~] $ Free-K

Total used free shared buffers cached

Mem: 262328 242000 20328 0 17336 42488

-/+ Buffers/cache: 182176 80152

Swap: 786416 36 786380

For the output of the free command, we only need to pay attention to the output lines highlighted in red and the output lines highlighted in green. For details, see the following:

Red output row: this operation looks at the output data from the operating system perspective. Used (242000) indicates kernel + applications + buffers + cached. Free (20382) indicates the amount of memory available in the system.

Green output line: This line outputs data from the application perspective. Its free = operating system used + buffers + cached, both:

80152 = 20328 + 17336 + 42488

[Root @ Rony ~] $ Free-m

Total used free shared buffers cached

Mem: 256 236 19 0 16 41

-/+ Buffers/cache: 178 78

Swap: 199 0 199

2. Virtual Memory real-time monitoring tool (vmstat):
The vmstat command is used to obtain information about processes, virtual memory, page swap space, and CPU activity in UNIX systems. This information reflects the system load. When vmstat is run for the first time, statistics from the start of the system are displayed. When vmstat is run, statistics from the last run of the command are displayed. You can specify the number and time of statistics to obtain the required statistics.

[Root @ Rony ~] $ Vmstat 1 3 # This is the most common method of vmstat. It means to output one message every 1 second. After three messages are output in total, the program exits.
Procs ----------- memory ---------- --- swap -- ----- Io ---- System -- ----- CPU ------
R B SWPD free buff cache Si so Bi Bo in CS us Sy ID wa st
0 0 36 20740 16888 42212 0 0 0 1 7 1 0 0 100 0
0 0 36 20740 16888 42212 0 0 0 41 38 0 0 100 0
0 0 36 20740 16888 42212 0 0 0 29 42 0 0 100 0

[Root @ Rony ~] $ Vmstat 1 # It means to output one entry every one second until you press Ctrl + C to exit.

The following describes the meaning of each column in the output table:

The process information is as follows: (procs)

R: Number of processes waiting in the ready state.

B: Number of waiting processes.

Memory information: (memory)

SWPD: the size of the SWAp in use, in KB.

Free: idle memory space.

Buff: the size of the used buff to buffer the read/write operations of Block devices.

Cache: used cache size, file system cache.

Information about the page swap space is: (SWAP)

Si: swap memory usage, transferred from disk to memory.

So: swap memory usage, transferred from memory to disk.

Information about Io Block devices is as follows: (IO)

BI: total data read from Block devices (read disk) (kb/s)

Bo: data written to block devices (written to disk) (kb/s)

Fault Information: (system)

In: The number of interruptions per second within the specified time.

Sy: Number of system calls per second within the specified time.

CS: the number of context switches per second within the specified time.

CPU information: (CPU)

US: CPU usage in user mode within a specified time interval.

Sy: CPU usage in the core State within a specified interval.

ID: CPU idle time ratio within the specified time interval.

Wa: the ratio of idle time when the CPU waits for I/O within the specified interval.

Vmstat can be used to determine whether a system is limited by CPU or memory: if the percentage of CPU Sy and US values is close to 100%, or the running Queue (r) the number of waiting processes is always not equal to 0, and often greater than 4, and the ID is often less than 40, the system is limited by the CPU; if the value of Bi and Bo is always not equal to 0, the system is limited by memory.

3. output the five commands that occupy the most memory in the current system:

#1) run the ps command to list all processes running on the current host.

#2) The fifth field is sorted (from small to large) in the numerical form ).

#3) Only the last five outputs are displayed.

[Root @ Rony ~] $ PS aux | sort-K 5N | tail-5

MySQL 25492 0.0 3.3 39860 8680? SL dec13 0: 01/usr/local/MySQL/libexec/mysqld -- basedir =/usr/local/MySQL -- datadir =/usr/local/MySQL/var -- user = MySQL -- log- error =/usr/local/MySQL/var/Rony. err -- PID-file =/usr/local/MySQL/var/Rony. PID -- socket =/tmp/MySQL. sock
-- Port = 3306
WWW 25379 0.0 10.3 40212 27216? S dec13 :20/usr/local/PHP/bin/PHP-CGI -- FPM-config/usr/local/PHP/etc/php-fpm.conf
WWW 25375 0.0 11.0 42016 29052? S dec13 :17/usr/local/PHP/bin/PHP-CGI -- FPM-config/usr/local/PHP/etc/php-fpm.conf
WWW 25376 0.0 11.2 42260 29416? S dec13 :20/usr/local/PHP/bin/PHP-CGI -- FPM-config/usr/local/PHP/etc/php-fpm.conf
WWW 25381 0.0 12.6 45884 33156? S dec13 :19/usr/local/PHP/bin/PHP-CGI -- FPM-config/usr/local/PHP/etc/php-fpm.conf

4. Obtain the total physical memory size of the current system:

#1) output the current memory usage of the system in MB.

#2) locate the mem row through grep, Which is statistical data from the operating system perspective.

#3) print the second column of the row through awk, that is, the total column.

[Root @ Rony ~] $ Free-M | grep "mem" | awk '{print $2, "MB "}'

256 MB

Http://shop104965075.taobao.com

Related Article

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.