Linux Viewing System Resource Usage

Source: Internet
Author: User
Tags switches disk usage high cpu usage

Linux Viewing System Resource Usage

During system maintenance, it may be necessary to review CPU and memory usage at any time, and to analyze the system's health needs based on the corresponding information. This article describes several common Linux system Resource View commands.

1. View of overall memory consumption

Command: Free

Figure 1 The free command to view memory consumption

(1) The free command is displayed by default in kilobytes and can be displayed in MB units with free-m.

(2) Mem line: total = used + free where buffers and cached are calculated within used, but are actually available memory.

(3) Mem Next line: Used is the real memory, free is the real available memory.

(4) Swap: Use of memory swap area.

2. Review the memory footprint of the top five process

Command: PS Auxw | Head-1;ps auxw|sort-rn-k4|head-5

Figure 2.1 Viewing the memory footprint of the top 5 process

2.1, the unit of memory is Kb,vsz is the use of virtual memory, RSS is the actual memory consumption.

Command decomposition:

PS AUXW Display system resource usage;

Head-1 indicates that the first column, the title column, is displayed;

Sort-r indicates a reverse sort,-n means sort by number, and-k4 represents the 4th character of the column.

3. View the top three CPU usage process

Command: PS auxw|head-1;ps auxw|sort-rn-k3|head-3

Figure 3.1 Viewing the top three process of CPU consumption

This command is similar to Figure 2.1, only the 3rd column of the selected resource occupancy (that is, the CPU), denoted by "-k3".

4. View the overall system load

Command: Top

Figure 4.1 Top Display System overall load

(1) The first line: System time + system run time + several users + 1/5/15 minutes system average load

(2) Second line: Total number of processes + number of running processes (running) + Number of sleep processes (sleeping) + number of processes stopped (stopped) + Number of zombie processes (zombie)

(3) Third line: User space CPU ratio (US) + kernel space CPU ratio (SY) + CPU vacancy rate (ID)

Figure 4.2 Resource utilization for each task

Annotations:

PID: Process ID

User: Username

PR: Priority

NI: Negative value indicates high priority, positive value indicates low priority.

VIRT: Virtual Memory

RES: Real Memory

SHR: Shared Memory

S: Process state d= non-interruptible sleep state; r= run; s= sleep; t= track/stop; z= Zombie Process

Parameters:

Top-d 2: Explicit resource usage for all processes at 2-second intervals

TOP-C: The resource usage of the explicit process every 5 seconds and displays the process's command-line arguments (by default, only the process name)

Top-p 12345-p 6789: Display pid every 5 seconds is 12345 and the PID is 6789 of the resource consumption of two processes

top-d 2-c-P 123456: Shows the PID is 12345 of the resource usage of the process every 2 seconds, and explicitly the command-line arguments that the process started

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

A top command

1. Role
The top command is used to display the program process in progress, and the permissions are all users.

2. Format
Top [-] [D delay] [Q] [C] [s] [s] [i] [n]

3. Main parameters
D: Specifies the interval of the update, in seconds.
Q: There are no delayed updates. If the user has a superuser, the top command will be executed with the highest precedence.
C: Displays the full path and name of the process.
S: Cumulative mode, which accumulates the CPU time of a child stroke that has completed or disappeared.
S: Safe mode.
I: Do not display any idle (idle) or useless (Zombie) travel.
N: Displays the number of updates and exits top when finished.



Figure 1 Display of the top command

In Figure 1, the first line represents the current time, the system startup time, the current number of system logon users, and the average load. The second line shows all the processes that were started, the currently running, suspended (sleeping), and the useless (Zombie) process. The third line shows the current usage of the CPU, including the proportion of the system occupied, the user usage ratio, idle (idle) ratio. Row four shows the use of physical memory, including total available memory, used memory, free memory, and memory consumed by the buffer. The five rows show the swap partition usage, including the total swap partition, used, idle, and the size used for the cache. Line six shows the most items, and the detailed explanations are listed below.

PID (Process ID): progress indicator number.
User: The username of the process owner.
PR: The priority level of the process.
NI: The value of the priority level of the process.
VIRT: The virtual memory value that the process occupies.
RES: The physical memory value that the process occupies.
SHR: Shared memory value used by the process.
S: The state of the process, where s indicates hibernation, R is running, Z represents a zombie state, and N indicates that the process precedence value is negative.
%CPU: The CPU usage that the process consumes.
%MEM: The percentage of physical memory and total memory that the process occupies.
Time+: The total CPU time that is consumed after the process is started.
Command: The start command name of the process startup, and if this line does not appear, the process will have a full command line.
While the top command is in use, you can also use some interactive commands to complete the functionality of other parameters. These commands are started by using shortcut keys.
< space;: Refresh now.
P: Sort According to CPU usage size.
T: Sort by time, cumulative time.
Q: Exit the top command.
M: Toggles display memory information.
T: Toggles display of process and CPU status information.
C: Toggle display command name and full command line.
M: Sorts according to the size of the memory used.
W: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.

As you can see, the top command is a very powerful tool for monitoring systems and is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.

Two FREE commands

2. Use
The free command is used to display memory usage, and the use of permissions is for all users.

2. Format
free [-b-k-m] [-O] [-s delay] [-t] [-v]

3. Main parameters
-b-k-M: Displays memory usage in bytes (KB, MB), respectively.
-S delay: Displays the number of seconds per second to show memory usage.
-T: Displays the memory sum column.
-O: Do not display buffer throttling columns.

4. Application examples
The free command is the primary command used to view memory usage. Compared to the top command, it has the advantage of being simple to use and consuming very little system resources. With the-s parameter, you can use the free command to continuously monitor how much memory is in use, which can be used as a handy real-time monitor.
#free-b-S5

With this command, the terminal continuously reports memory usage (in bytes), updated every 5 seconds.

Three uptime commands

In the Linux system, there is a claim that when the load avarage <3 system is good, greater than 5 has serious performance problems. Note that this value should also be divided by the number of CPUs.

If load avarage=8, cpu=3,8/3=2.666,2.66 This value indicates that the system is in good condition

Greater than 5 is not necessarily a serious performance problem, it is possible that the host provides more than he can provide the ability to expand. To see specifically.


Four Vmstat command

The Vmstat command is the most common Linux/unix monitoring tool that can represent the state values of a server at a given time interval, including the server's CPU utilization, and the memory

Use, virtual memory exchange, IO Read and write situations. This command is my view Linux/unix favorite commands, one is Linux/unix support, two is compared to top,

I can see the CPU, memory, and IO usage of the whole machine, not just the CPU usage and memory usage of each process (using a different scenario).

The use of the general Vmstat tool is accomplished by two numeric parameters, the first parameter is the number of time intervals sampled, the unit is seconds, the second parameter is the sampled

Number, such as:

[Email protected]:~# vmstat 2 1procs-----------memory-------------Swap-------io-----system------CPU----r  b   swpd   free   buff  cache   si   so    bi    bo   in   CS US sy ID WA 1  0      0 3498472 315836 3819540    0    0     0     1    2    0  0  0-  0

2 indicates that the server state is collected every two seconds, and 1 means that it is collected only once.

In fact, in the application process, we will be monitoring for a period of time, do not want to monitor the direct end of Vmstat, such as:

[Email protected]:~# vmstat 2  procs-----------memory-------------Swap-------io-----system------CPU----r  b   swpd   free   buff  cache   si   so    bi    bo   in   CS US sy ID WA 1  0      0 3499840 315836 3819660    0    0     0     1    2    0 0 0 0  0  0      0 3499584 315836 3819660    0    0     0     0  158 0 0 +  0 0  0      0 3499708 315836 3819660    0    0     0     2  162 0 0 +  0 0  0      0 3499708 315836 3819660    0    0     0  151  0 0 +  0 1  0      0 3499732 315836 3819660    0    0     0     2  154,  0  0  , 0

This means that Vmstat collects data every 2 seconds and collects it until I have finished the program, and I have collected 5 data and I have finished the program.

Well, the command is complete, now the actual combat to explain the meaning of each parameter.

R means running the queue (that is, how many processes are really allocated to the CPU), the server I am testing is currently idle, there is no program running, when this value exceeds the number of CPUs, there will be a CPU bottleneck. This is also related to top of the load, the general load over 3 is relatively high, more than 5 is high, more than 10 is not normal, the state of the server is very dangerous. The load on top is similar to the run queue per second. If the running queue is too large, it means that your CPU is busy, which generally results in high CPU usage.

b represents the blocking process, which is not much to say, the process is blocked, you understand.

SWPD virtual memory has been used size, if greater than 0, indicates that your machine is out of physical memory, if not the cause of program memory leaks, then you should upgrade the memory or the memory-consuming task to other machines.

Free physical memory size, my machine memory total 8G, the remaining 3415M.

Buff Linux/unix system is used to store, directory inside what content, permissions, etc. of the cache, I am the machine about more than 300 m

The cache cache is used directly to memorize the files we open, to buffer the files, I have about 300 m of this machine (this is the smart place of Linux/unix, the spare part of the physical memory to do the file and directory cache, is to improve the performance of the program execution, when the program uses memory, Buffer/cached will be used very quickly. )

Si reads the size of the virtual memory from disk every second, if this value is greater than 0, it means that the physical memory is not enough or the memory leaks, to find out the memory process. My machine has plenty of memory and everything is fine.

So per second The virtual memory is written to the size of the disk, if this value is greater than 0, ibid.

The number of blocks received per second by the BI block device, where the block device refers to all the disks and other block devices on the system, the default block size is 1024byte, I have no IO operation on this machine, so it's been 0, but I've seen the 140000/s on machines that handle copying large amounts of data (2-3t). Disk write speed of almost 140M per second

The number of blocks that Bo block devices send per second, such as when we read a file, the Bo will be greater than 0. Bi and Bo are generally close to 0, otherwise the IO is too frequent and needs to be adjusted.

In CPU interrupts per second, including time interrupts

CS per second, such as the number of context switches, such as we call the system function, the context switch, the thread of the switch, but also the process context switch, the smaller the value of the better, too big, to consider the number of threads or processes, such as Apache and Nginx in the Web server, We generally do performance testing will carry out thousands of concurrent or even tens of thousands of concurrent tests, the selection of the Web server process can be the process or the peak of the thread has been down, pressure measurement, until CS to a relatively small value, the process and the number of threads is a more appropriate value. System calls are also, each time the system function is called, our code will enter the kernel space, resulting in context switching, this is very resource-intensive, but also try to avoid frequent calls to system functions. Too many context switches means that most of your CPU is wasted in context switching, resulting in less time for the CPU to do serious work, and the CPU not being fully utilized, is undesirable.

US user CPU time, I used to do encryption and decryption very frequently on the server, you can see us approaching 100,r running queue reached 80 (the machine is doing a stress test, poor performance).

SY system CPU time, if too high, indicates a long system call time, for example, the IO operation is frequent.

ID Idle CPU time, in general, ID + US + sy = 100, generally I think ID is idle CPU usage, US is the user CPU usage, SY is the system CPU utilization.

WT waits for IO CPU time.

Five Iostat command

The Iostat in a Linux system is an abbreviation for I/O statistics (input/output statistics), and the Iostat tool monitors the system's disk operation activity. It is characterized by the reporting of disk activity statistics, as well as the reporting of CPU usage. Like Vmstat, Iostat also has a weakness, that is, it cannot analyze a process in depth, only the overall situation of the system. Iostat belongs to the Sysstat package. Can be installed directly with Yum install Sysstat.

1. Command format:

iostat[parameters [TIME] [number]

2. Command function:

Through the Iostat convenient to view the CPU, network card, TTY device, disk, CD-ROM and so on the activity of equipment, load information.

3. Command parameters:

-C Display of CPU usage

-D Display disk usage

-K displays in kilobytes

-m displays in units of M.

-N Display of disk array (LVM) information

-N Display of NFS usage

-p[disk] Displays disk and partition conditions

-t display terminal and CPU information

-X to display detailed information

-V Display version information

4. Usage examples:

Example 1: Show all device load conditions

Command:

Iostat

Output:

[Email protected] ~]# Iostat
Linux 2.6.18-128.el5 (CT1186) December 28, 2012

AVG-CPU:%user%nice%system%iowait%steal%idle
8.30 0.02 5.07 0.17 0.00 86.44

Device:tps blk_read/s blk_wrtn/s Blk_read Blk_wrtn
SDA 22.73 43.70 487.42 674035705 7517941952
SDA1 0.00 0.00 0.00 2658 536
Sda2 0.11 3.74 3.51 57721595 54202216
Sda3 0.98 0.61 17.51 9454172 270023368
SDA4 0.00 0.00 0.00 6 0
Sda5 6.95 0.12 108.73 1924834 1677123536
Sda6 2.20 0.18 31.22 2837260 481488056
Sda7 12.48 39.04 326.45 602094508 5035104240

Description

Description of the CPU attribute value:

%user:cpu the percentage of time in user mode.

%nice:cpu the percentage of time in user mode with nice value.

%system:cpu the percentage of time in system mode.

%iowait:cpu the percentage of time to wait for the input output to finish.

%steal: The percentage of the virtual CPU's unconscious wait time when the hypervisor maintains another virtualized processor.

%IDLE:CPU idle time percentage.

Note: If the value of%iowait is too high, indicating that there is an I/O bottleneck on the hard disk, high%idle value, indicating that the CPU is idle, if the%idle value is high but the system responds slowly, it is possible that the CPU waits for memory allocation, and the memory capacity should be increased. If the%idle value continues below 10, the system's CPU processing power is relatively low, indicating that the most resource to be addressed in the system is the CPU.

Disk Property Value Description:

RRQM/S: The number of read operations per second for the merge. namely RMERGE/S

WRQM/S: The number of write operations per second for the merge. namely WMERGE/S

R/S: Number of Read I/O devices completed per second. namely RIO/S

W/S: Number of write I/O devices completed per second. namely WIO/S

RSEC/S: Number of Read sectors per second. namely RSECT/S

WSEC/S: Number of Write sectors per second. namely WSECT/S

rkb/s: Reads K bytes per second. is half the rsect/s because the size of each sector is 512 bytes.

wkb/s: Writes K bytes per second. is half the wsect/s.

Avgrq-sz: The average data size (sector) per device I/O operation.

Avgqu-sz: Average I/O queue length.

Await: The average wait time (in milliseconds) for each device I/O operation.

SVCTM: The average service time (in milliseconds) per device I/O operation.

%util: How much time in a second is spent on I/O operations, which is the percentage of CPU consumed by IO

Note: If%util is close to 100%, it indicates that there are too many I/O requests and that the I/O system is full, the disk may have bottlenecks. If the SVCTM is closer to await, it indicates that I/O has almost no wait time, and if the await is much larger than SVCTM, indicating that the I/O queue is too long and the IO response is too slow, the necessary optimizations are required. If the Avgqu-sz is larger, it also indicates that there is an equivalent IO waiting.

Linux Viewing System Resource Usage

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.