一、系统整体性能监测工具:uptime
[root@WebServer ~]# uptime (同w命令输出的第一行信息)
09:40:52 up 5 days, 57 min, 1 user, load average: 0.00, 0.00, 0.00
uptime命令用于查看服务器运行了多长时间以及有多少个用户登录,快速获知服务器运行的负载情况。
load average,显示了最近1,5,15分钟的负荷情况。
它的值代表等待CPU处理的进程数,如果CPU没有时间处理这些进程,load average值会升高;反之则会降低。
在CPU数量不同的情况下,值有所不同。
二、CPU监测:mpstat (请参考MAN手册)
mpstat 1 111 [1秒刷新,111次]
语法:mpstat [ options... ] [ <interval> [ <count> ] ]
[root@WebServer ~]# mpstat 1
Linux 2.6.9-89.ELsmp (WebServer) 08/18/09
10:08:25 CPU %user %nice %system %iowait %irq %soft %idle intr/s
10:08:26 all 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1005.00
10:08:27 all 0.00 0.00 0.00 0.12 0.00 0.00 99.88 1031.00
10:08:28 all 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1009.00
10:08:29 all 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1030.00
10:08:30 all 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1006.00
1.CPU (处理器编号,all表示所有处理器的平均数值)
Processor number. The keyword all indicates that statistics are calculated as averages among all processors.2.%user (用户态的CPU利用率百分比)
Show the percentage of CPU utilization that occurred while executing at the user level (application).3.%nice (用户态的优先级别CPU的利用率百分比)
Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.4.%system (内核态的CPU利用率百分比)
Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that
this does not include the time spent servicing interrupts or softirqs.5.%iowait (在interval间段内io的等待百分比,interval 为采样频率,如本文的1为每一秒钟采样一次)
Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.6.%irq (在interval间段内,CPU的中断百分比)
Show the percentage of time spent by the CPU or CPUs to service interrupts.7.%soft (在interval间段内,CPU的软中断百分比)
Show the percentage of time spent by the CPU or CPUs to service softirqs. A softirq (software interrupt) is
one of up to 32 enumerated software interrupts which can run on multiple CPUs at once.8.%idle (在interval间段内,CPU的闲置百分比,不包括I/O请求的等待)
Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding
disk I/O request.9.intr/s (在interval间段内所有的CPU每秒中断数)
Show the total number of interrupts received per second by the CPU or CPUs.
三、内存监测:vmstat (请参考MAN手册)
vmstat是一个很全面的性能分析工具,可以观察到系统的进程状态、内存使用、虚拟内存使用、磁盘的IO、中断、上下文切换、CPU使用等。对于 Linux 的性能分析,100%理解 vmstat 输出内容的含义,并能灵活应用,那对系统性能分析的能力就算是基本掌握了。
下面是vmstat命令的输出结果:
[root@monitor-www ~]# vmstat 1 5
procs — ———–memory——————–swap——io—– —-system— —–cpu—
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 84780 909744 267428 1912076 0 0 20 94 0 0 2 1 95 1 0
1 2 84780 894968 267428 1912216 0 0 0 1396 2301 11337 8 3 89 0 0
1 0 84780 900680 267428 1912340 0 0 76 1428 1854 8082 7 2 90 0 0
1 0 84780 902544 267432 1912548 0 0 116 928 1655 7502 7 2 92 0 0
2 0 84780 900076 267432 1912948 0 0 180 904 1963 8703 10 3 87 0 0
对输出解释如下:
1)procs
a.r 列表示运行和等待CPU时间片的进程数,这个值如果长期大于系统CPU个数,就说明CPU资源不足,可以考虑增加CPU;
b.b列表示在等待资源的进程数,比如正在等待I/O或者内存交换等。
2)memory
a.swp 列表示切换到内存交换区的内存数量(以KB为单位)。如果swp的值不为0或者比较大,而且si、so的值长期为0,那么这种情况一般不用担心,不会影响系统性能;
b.free列表示当前空闲的物理内存数量(以KB为单位);
c. buff列表示buffers cache的内存数量,一般对块设备的读写才需要缓冲;
d. cache列表示page cached的内存数量,一般作文件系统的cached,频繁访问的文件都会被cached。如果cached值较大,就说明cached文件数较多。如果此时IO中的bi比较小,就说明文件系统效率比较好。
3)swap
a.si列表示由磁盘调入内存 ,也就是内存进入内存交换区的数量;
b.so 列表示由内存调入磁盘 ,也就是内存交换区进入内存的数量
c.一般情况下,si、so的值都为0,如果si、so的值长期不为0,则表示系统内存不足,需要考虑是否增加系统内存 。
4)I