Linux system CPU and memory usage

Source: Internet
Author: User
Tags safe mode switches

1.top

Usage rights: All users

Mode of use: Top [-] [D delay] [Q] [C] [s] [s] [i] [n] [b]

Description: Instant display of process dynamics

D: Change the update speed of the display, or press s in the chat command column (interactive command)

Q: There is no delay in the display speed, if the user has Superuser permissions, then top will be executed with the highest precedence

C: Toggle display mode, a total of two modes, one is to display the name of the execution file only, the other is to display the full path and name S: Cumulative mode, will be completed or disappeared sub-stroke (dead child process) CPU time accumulated

S: Safe mode, cancel conversational instruction, avoid potential crisis

I: Do not display any idle (idle) or useless (zombie) travel

N: The number of updates that will exit the top after completion

B: Batch mode, used with "n" parameter, can be used to output top results in the file

Example:

Show Update 10 times after exiting;

Top-n 10

The user will not be able to use the conversational instruction to command the trip:

Top-s

Enter the results of the update display two times into the file named Top.log:

Top-n 2-b < Top.log

Attach a command brief introduction to Linux traceroutewindows tracert two commands quite, trace network routing

2.vmstat

As the performance comparison of any system we discussed earlier is baseline based, and monitoring CPU performance is the above 3 points, running queue, CPU utilization, and context switching. The following are some of the most common performance requirements for CPUs:

1. For each CPU to run the queue do not exceed 3, for example, if the dual-core CPU should not exceed 6;

2. If the CPU is running at full load, the following distribution should be met

A) User time:65%~70%

b) System time:30%~35%

c) idle:0%~5%

3. Mpstat

For context switches to be combined with CPU usage, a large number of context switches are acceptable if CPU usage satisfies the above distribution.

Common monitoring tools are: Vmstat, Top,dstat and Mpstat.

# vmstat 1

procs-----------Memory-------------Swap-------io------System------CPU----

R b swpd free buff cache si so bi bo in CS US sy ID WA

0 0 104300 16800 95328 72200 0 0 5 26 7 14 4 1 95 0

0 0 104300 16800 95328 72200 0 0 0 24 1021 64 1 1 98 0

0 0 104300 16800 95328 72200 0 0 0 0 1009 59 1 1 98 0

R indicates the size of the running queue,

b indicates the number of threads in the block due to IO waiting,

In indicates the number of interrupts,

CS indicates the number of context switches,

The US represents the user's CPU time,

SYS indicates system CPU time,

WA represents the time that the CPU is idle due to IO wait,

The ID indicates the total amount of time the CPU is in an idle state.

Dstat can give the number of interrupts that are generated by each device:

# dstat-cip 1

----total-cpu-usage--------INTERRUPTS------procs---

USR sys IDL Wai hiq siq| 169 185 |run Blk NEW

6 1 91 2 0 0| 12 0 13 | 0 0 0

1 0 99 0 0 0| 0 0 6 | 0 0 0

0 0 100 0 0 0| 18 0 2 | 0 0 0

0 0 100 0 0 0| 0 0 3 | 0 0 0

We can see there are 3 device numbers 15,169 and 185. The relationship between the device name and the device number we can refer to the file/proc/interrupts, where 185 represents the NIC eth1.

# cat/proc/interrupts

CPU0

0:1277238713 Io-apic-edge Timer

6:5 Io-apic-edge Floppy

7:0 Io-apic-edge parport0

8:1 Io-apic-edge RTC

9:1 Io-apic-level ACPI

14:6011913 Io-apic-edge ide0

15:15761438 Io-apic-edge Ide1

169:26 Io-apic-level Intel 82801BA-ICH2

185:16785489 Io-apic-level eth1

193:0 Io-apic-level UHCI_HCD:USB1

The mpstat can show the health of each CPU, such as a system with 4 CPUs. We can see:

# mpstat–p All 1

Linux 2.4.21-20.ELSMP (Localhost.localdomain) 05/23/2006

05:17:31 PM CPU%user%nice%system%idle intr/s

05:17:32 PM All 0.00 0.00 3.19 96.53 13.27

05:17:32 PM 0 0.00 0.00 0.00 100.00 0.00

05:17:32 PM 1 1.12 0.00 12.73 86.15 13.27

05:17:32 PM 2 0.00 0.00 0.00 100.00 0.00

05:17:32 PM 3 0.00 0.00 0.00 100.00 0.00

In summary, CPU performance monitoring includes the following:

Check the system's running queue to ensure that each CPU runs at a queue of no more than 3.

Ensure that the CPU usage distribution meets the 70/30 principle (user 70%, System 30%).

If the system time is too long, it may be because of frequent scheduling and changing priorities.

The CPU bound process is always punished (lower priority) and the IO bound process is always rewarded (higher priority).

4.prstat command

To display various statistics about the processes and projects currently running on your system, use the Prstat command with the -j option:

%prstat-j

PID USERNAME SIZE RSS State PRI nice time CPU PROCESS/NLWP

21634 jtd 5512K 4848K cpu0 0 0:00.00 0.3% PRSTAT/1

324 root 29M 75M sleep 0 0:08.27 0.2% XSUN/1

15497 jtd 48M 41M sleep 0 0:08.26 0.1% ADEPTEDIT/1

328 root 2856K 2600K sleep 0 0:00.00 0.0% MIBIISA/11

1979 JTD 1568K 1352K sleep 0 0:00.00 0.0% CSH/1

1977 JTD 7256K 5512K sleep 0 0:00.00 0.0% DTTERM/1

192 root 3680K 2856K sleep 0 0:00.36 0.0% AUTOMOUNTD/5

1845 JTD 24M 22M sleep 0 0:00.29 0.0% DTMAIL/11

1009 JTD 9864K 8384K sleep 0 0:00.59 0.0% DTWM/8

Root 1640K 704K sleep 0 0:01.16 0.0% IN.ROUTED/1

Daemon 2704K 1944K sleep 0 0:00.00 0.0% STATD/4

145 root 2120K 1520K sleep 0 0:00.00 0.0% YPBIND/1

181 root 1864K 1336K sleep 0 0:00.00 0.0% LOCKD/1

173 root 2584K 2136K sleep 0 0:00.00 0.0% INETD/1

135 root 2960K 1424K sleep 0 0 0:00.00 0.0% KEYSERV/4

ProjId nproc SIZE RSS MEMORY time CPU PROJECT

400M 271M 68% 0:11.45 0.4% booksite

0 113M 129M 32% 0:10.46 0.2% System

total:87 processes, 205 lwps, Load averages:0.05, 0.02, 0.02

To display various statistics about the processes and tasks currently running on the system, use the Prstat command with the- t option:

%prstat-t

PID USERNAME SIZE RSS State PRI nice time CPU PROCESS/NLWP

23023 Root 26M 20M sleep 0 0:03:18 0.6% XSUN/1

23476 jtd 51M 45M sleep 0 0:04:31 0.5% ADEPTEDIT/1

23432 jtd 6928K 5064K sleep 0 0:00:00 0.1% DTTERM/1

28959 jtd 26M 18M sleep 0 0:00:18 0.0% NETSCAPE.BIN/1

23116 jtd 9232K 8104K sleep 0 0:00:27 0.0% DTWM/5

29010 jtd 5144K 4664K cpu0 0 0:00:00 0.0% PRSTAT/1

Root 3096K 1024K sleep 0 0:00:00 0.0% LPSCHED/1

161 root 2120K 1600K sleep 0 0:00:00 0.0% LOCKD/2

5888K 4248K sleep 0 0:03:10 0.0% AUTOMOUNTD/3

Root 2120K 1408K sleep 0 0:00:00 0.0% YPBIND/1

162 Daemon 2504K 1936K sleep 0 0:00:00 0.0% STATD/2

146 root 2560K 2008K sleep 0 0:00:00 0.0% INETD/1

122 root 2336K 1264K sleep 0 0:00:00 0.0% KEYSERV/2

119 Root 2336K 1496K sleep 0 0:00:02 0.0% RPCBIND/1

104 Root 1664K 672K sleep 0 0:00:03 0.0% IN.RDISC/1

TASKID nproc SIZE RSS MEMORY time CPU PROJECT

222 229M 161M 44% 0:05:54 0.6% group.staff

223 1 26M 20M 5.3% 0:03:18 0.6% group.staff

1 61M 33M 8.9% 0:00:31 0.0% group.staff

1 85M 53M 14% 0:03:33 0.0% System

total:65 processes, 154 lwps, load averages:0.04, 0.05, 0.06

//------------------------------------------------------------------------------------------------------------- ---------------------------------//

1. Top

This command is often used, and on the third line there is a display of current CPU usage.

[Email protected] ~]# top-bn 1-i-ctop-14:19:51 up 138 days, 7:15, 1 user, load average:0.20, 0.33, 0.39tasks:115 t Otal, 1 running, sleeping, 0 stopped, 0 zombiecpu (s): 4.5%us, 3.8%sy, 0.0%ni, 91.0%id, 0.6%wa, 0.0%hi, 0.0%si, 0.0%stm em:1014660k Total, 880512k used, 134148k free, 264904k buffersswap:262140k total, 34788k used, 227352k free, 217144k CAC Hedpid USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND 12760 root 0 15084 1944 1632 R 2.0 0.2 0:00.01 top-bn 1-i-C

As shown above, the top command can see the overall system operating state and CPU usage.

%us: Represents the CPU usage of the User space program (not dispatched via Nice)

%sy: Represents the CPU utilization of the system space, mainly the kernel program.

%ni: CPU Usage for programs that represent user space and are spent through nice.

%id: Idle CPU

%wa:cpu time the runtime waits for IO

%HI:CPU processing the number of hard interrupts

%si:cpu the number of soft interrupts processed

%st: CPU stolen by Virtual machine

2, Vmstat

Before in this blog has introduced the use of Vmstat, detailed use and parameter Introduction reference URL: http://www.sijitao.net/1925.html.

[[email protected] ~]# Vmstat 1 5procs-----------memory-------------Swap-------io------System-------CPU-----R B SWPD Free buff cache si so bi bo in CS us sy ID WA St 2 0 34792 68376 147688 356132 16 16 421 385 2 2 5 4 91 1 0 3 0 34792 973 68 147688 326884 0 0 0 0 133 134 15 6 79 0 0 1 0 34792 62432 147696 360704 0 0 0 88 267 278 63 18 19 0 0 0 0 34792 97160 1 47696 326904 0 0 0 0 71 82 12 4 84 0 0 1 0 34792 56572 147696 364540 0 0 0 4 261 246 61 23 16 0 0
3. Sar

The SAR command syntax is the same as Vmstat. If the command does not exist, you need to install the Sysstat package, this package is useful.

CPU Usage

For example, a CPU usage is collected every 1 seconds and collected 5 times.

[[email protected] ~]# sar-u 1 5Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 02:41:25 PM CPU%user %nice%system%iowait%steal%idle02:41:26 pm All 64.71 0.00 18.63 0.00 0.98 15.6902:41:27 PM all 29.47 0.00 22.11 14.74 0.00 33.6802:41:28 pm All 67.33 0.00 31.68 0.99 0.00 0.0002:41:29 pm All 7.00 0.00 2.00 0.00 0.00 91.0002:41:30 PM All 69. XX 0.00 23.00 0.00 0.00 8.00average:all 47.79 0.00 19.48 3.01 0.20 29.52

As with top, you can see the usage of all CPUs. If you need to see the use of a CPU you can use the-p parameter. For example, specify that No. 0 CPU usage is displayed.

[[email protected] ~]# sar-p 0-u 1 5Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 02:45:14 PM CPU %user%nice%system%iowait%steal%idle02:45:15 PM 0 44.00 0.00 52.00 4.00 0.00 0.0002:45:16 PM 0 9.28 0.00 26.80 62.89 1 .0.0002:45:17 PM 0 3.06 0.00 14.29 81.63 1.02 0.0002:45:18 PM 0 4.12 0.00 22.68 72.16 1.03 0.0002:45:19 PM 0 4.12 0.00 22.68 72.16 1.03 0.00average:0 13.09 0.00 27.81 58.28 0.82 0.00
Process Queue Length and average load status

For example, collected once every 1 seconds, a total of 5 times.

[[email protected] ~]# sar-q 1 5Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 02:48:47 PM Runq-sz p List-sz Ldavg-1 ldavg-5 ldavg-1502:48:48 pm 1 133 0.34 0.43 0.4102:48:49 pm 2 0.34 0.43 0.4102:48:50 pm 1 133 0.34 0.4 3 0.4102:48:51 PM 2 134 0.31 0.42 0.4002:48:52 PM 1 133 0.31 0.42 0.40average:1 133 0.33 0.43 0.41

Output items:

Runq-sz: Length of the run queue (number of processes waiting to run)

Plist-sz: Number of processes (processes) and threads (threads) in the process list

Ldavg-1: Average system load for last 1 minutes (systems load average)

Ldavg-5: System average load over the last 5 minutes

Ldavg-15: System average load over the last 15 minutes

Number of average and context switches created by the process

For example, collected once every 1 seconds, collected 5 times.

[[email protected] ~]# sar-w 1 5 Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 02:54:03 PM proc/s C swch/s02:54:04 pm 1.01 156.5702:54:05 pm 1.00 132.0002:54:06 pm 2.00 201.0002:54:07 pm 2.02 126.2602:54:08 pm 2.00 114.00A verage:1.61 145.98

The SAR command can also get performance parameters for a specified date in the past.

[[email protected] ~]# sar-u-f/var/log/sa/sa20 Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 01:1 0:01 pm CPU%user%nice%system%iowait%steal%idle01:20:02 pm All 25.78 0.00 8.88 3.59 0.15 61.6001:30:01 pm all 26.06 0 .9.96 3.33 0.10 60.5501:40:01 pm All 25.73 0.00 9.17 3.70 0.09 61.3201:50:01 PM all 25.70 0.00 9.50 2.79 0.12 61.8902:0 0:01 pm All 26.70 0.00 9.73 2.20 0.10 61.2802:10:01 pm All 26.16 0.00 9.56 4.34 0.11 59.8202:20:01 pm All 25.49 0.00 9.61 2.76 0.07 62.0702:30:01 pm All 26.47 0.00 9.94 0.64 0.30 62.6502:40:02 pm All 27.32 0.00 10.37 3.86 0.15 58.3002:50:02 pm All 26.98 0.00 10.38 4.56 0.13 57.95average:all 26.24 0.00 9.71 3.18 0.13 60.74
4, Mpstat

This command is also in the Sysstat package, similar in syntax.

For example, collected once every 1 seconds, a total of 5 times.

[[email protected] ~]# Mpstat 1 5Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) 03:01:18 PM CPU%USR %nice%sys%iowait%irq%soft%steal%guest%idle03:01:19 PM all 52.53 0.00 23.23 0.00 0.00 0.00 0.00 0.00 24.2403:01:20 P M All 21.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 75.0003:01:21 PM All 53.00 0.00 18.00 0.00 0.00 0.00 0.00 0.00 29.0003:01:2 2 pm All 26.00 0.00 3.00 0.00 0.00 0.00 0.00 0.00 71.0003:01:23 PM All 46.00 0.00 18.00 0.00 0.00 0.00 0.00 0.00 36.00Aver Age:all 39.68 0.00 13.23 0.00 0.00 0.00 0.00 0.00 47.09

CPU usage is more detailed than SAR, and you can specify a CPU with-p.

5, Iostat

This command is mainly used to view the IO usage, or to view the CPU, personal feeling is not used.

[[email protected] ~]# iostat-c 1 2Linux 3.18.5-x86_64-linode52 (li676-235) 07/20/2015 _x86_64_ (1 CPU) Avg-cpu:%user%ni  Ce%system%iowait%steal%idle 4.53 0.01 3.81 0.63 0.04 90.99avg-cpu:%user%nice%system%iowait%steal%idle 38.00 0.00 14.00 0.00 0.00 48.00
6, Dstat

CPU utilization per second gets

[[email protected] ~]# dstat-c----total-cpu-usage----usr sys idl Wai hiq siq 5 4 91 1 0 0 27 11 62 0 0 0 52 11 37 0 0 0 2 6 10 63 0 0 1 50 13 37 0 0 1 21 6 72 0 0 0

CPU-Most process acquisition

[Email protected] ~]# dstat--top-cpu-most-expensive-cpu process mysqld 1.5php-fpm:pool 24mysqld 59

Linux system CPU and memory usage

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.