vmstat的应用详解

vmstat的应用详解 http://www.chinaunix.net/jh/6/882302.html[@more@]

Virtual Memory Statistics ( vmstat ) vmstat 是报告关于进程,虚拟内存,磁盘,CPU活动的一个统计报告.
在一个多CPU系统中,vmstat统计所有个数的CPU的平均输出.为每个进程进行统计.没有参数时,vmstat显示每一行是自从系统启动以后的虚拟内存的活动情况.(注:vmstat输出的第一行对于实施统计没有意义)

用法:

基本的用法是vmstat interval count

option: 指定我们所需要的输出选项比如: paging -p , cache -c ,.interrupt -i 等等(还有一个比较有用的是S),更加具体的vmstat的参数情况可以参照man手册和系统管理员手册的相应说明.

如果没有指定参数,输出的信息是关于process , memory , paging , disk ,interrupts & cpu的显示.
interval 是在两个输出结果输出的时候给予的间隔时间.. vmstat 4 是给予4秒的间隔.
count 是你需要的输出的数据量.ivmstat 4 5 是间隔4秒输出5次数据.
下面是关于一些参数的描述:
procs
r in run queue
b blocked for resources I/O, paging etc.
w swapped

memory (in Kbytes)
swap - amount of swap space currently available
free - size of the free list

page ( in units per second).
re page reclaims - see -S option for how this field is modified.
mf minor faults - see -S option for how this field is modified.
pi kilobytes paged in
po kilobytes paged out
fr kilobytes freed
de anticipated short-term memory shortfall (Kbytes)
sr pages scanned by clock algorithm

disk ( operations per second )
There are slots for up to four disks, labeled with a single letter and number.
The letter indicates the type of disk (s = SCSI, i = IPI, etc) . The number is
the logical unit number.

faults
in (non clock) device interrupts
sy system calls
cs CPU context switches

cpu - breakdown of percentage usage of CPU time. On multiprocessors this is an average across all processors.
us user time
sy system time
id idle time
CPU问题现象:
1.) 如果在processes中运行的序列(process r)是连续的大于在系统中的CPU的个数表示系统现在运行比较慢,有多数的进程等待CPU.
2.) 如果r的输出数大于系统中可用CPU个数的4倍的话,则系统面临着CPU短缺的问题,或者是CPU的速率过低,系统中有多数的进程在等待CPU,造成系统中进程运行过慢.
3.) 如果空闲时间(cpu id)持续为0并且系统时间(cpu sy)是用户时间的两倍(cpu us) 系统则面临着CPU资源的短缺.

解决办法:
当发生以上问题的时候请先调整应用程序对CPU的占用情况.使得应用程序能够更有效的使用CPU.同时可以考虑增加更多的CPU. 关于CPU的使用情况还可以结合mpstat, ps aux top prstat –a等等一些相应的命令来综合考虑关于具体的CPU的使用情况,和那些进程在占用大量的CPU时间.一般情况下,应用程序的问题会比较大一些.比如一些SQL语句不合理等等都会造成这样的现象.


内存问题现象:
内存的瓶颈是由scan rate (sr)来决定的.scan rate是通过每秒的始终算法来进行页扫描的.如果scan rate(sr)连续的大于每秒200页则表示可能存在内存缺陷.同样的如果page项中的pi和po这两栏表示每秒页面的调入的页数和每秒调出的页数.如果该值经常为非零值,也有可能存在内存的瓶颈,当然,如果个别的时候不为0的话,属于正常的页面调度这个是虚拟内存的主要原理.

解决办法:
1.调节applications & servers使得对内存和cache的使用更加有效.
2.增加系统的内存.
3. Implement priority paging in s in pre solaris 8 versions by adding line "set priority paging=1" in
/etc/system. Remove this line if upgrading from Solaris 7 to 8 & retaining old /etc/system file.
关于内存的使用情况还可以结ps aux top prstat –a等等一些相应的命令来综合考虑关于具体的内存的使用情况,和那些进程在占用大量的内存.一般情况下,如果内存的占用率比较高,但是,CPU的占用很低的时候,可以考虑是有很多的应用程序占用了内存没有释放,但是,并没有占用CPU时间,可以考虑应用程序,对于未占用CPU时间和一些后台的程序,释放内存的占用.

写的不对的地方欢迎朋友帮忙指出。谢谢,并且帮助补充。谢谢!!!

http://www.adminschoice.com/docs/iostat_vmstat_netstat.htm

Solaris Performance Monitoring & Tuning - iostat , vmstat & netstat

Introduction to iostat , vmstat and netstat

This document is primarily written with reference to solaris performance monitoring and tuning but these tools are available in other unix variants also with slight syntax difference.

iostat , vmstat and netstat are three most commonly used tools for performance monitoring . These comes built in with the operating system and are easy to use .iostat stands for input output statistics and reports statistics for i/o devices such as disk drives . vmstat gives the statistics for virtual Memory and netstat gives the network statstics .

Following paragraphs describes these tools and their usage for performance monitoring and if you need more information there are some very good solaris performance monitoring books available at www.besttechbooks.com.

Table of content :

1. Iostat

2. vmstat

3. netstat

4. Next Steps

Input Output statistics ( iostat )

iostat reports terminal and disk I/O activity and CPU utilization. The first line of output is for the time period since boot & each subsequent line is for the prior interval . Kernel maintains a number of counters to keep track of the values.

iostat's activity class options default to tdc (terminal, disk, and CPU). If any other option/s are specified, this default is completely overridden i.e. iostat -d will report only statistics about the disks.

syntax:

Basic synctax is iostat interval count

option - let you specify the device for which information is needed like disk , cpu or terminal. (-d , -c , -t or -tdc ) . x options gives the extended statistics .

interval - is time period in seconds between two samples . iostat 4 will give data at each 4 seconds interval.

count - is the number of times the data is needed . iostat 4 5 will give data at 4 seconds interval 5 times

-->

Example

 $ iostat -xtc 5 2
                          extended disk statistics       tty         cpu
     disk r/s  w/s Kr/s Kw/s wait actv svc_t  %w  %b  tin tout us sy wt id
     sd0   2.6 3.0 20.7 22.7 0.1  0.2  59.2   6   19   0   84  3  85 11 0
     sd1   4.2 1.0 33.5  8.0 0.0  0.2  47.2   2   23
     sd2   0.0 0.0  0.0  0.0 0.0  0.0   0.0   0    0
     sd3  10.2 1.6 51.4 12.8 0.1  0.3  31.2   3   31
 

     The fields have the following meanings:

      disk    name of the disk
      r/s     reads per second
      w/s     writes per second
      Kr/s    kilobytes read per second
      Kw/s    kilobytes written per second
      wait    average number of transactions waiting for service (Q length)
      actv    average number of transactions  actively  
              being serviced (removed  from  the
 	      queue but not yet
              completed)
      %w      percent of time there are transactions  waiting
              for service (queue non-empty)
      %b      percent of time the disk is busy  (transactions
                  in progress)

 

Results and Solutions:

The values to look from the iostat output are:

  • Reads/writes per second (r/s , w/s)
  • Percentage busy (%b)
  • Service time (svc_t)

1.10.4 Use vmstat

The

vmstat utility is the most common Unix monitoring utility, and it is found in the majority of Unix dialects (vmstat is called osview in IRIX). The vmstat utility displays various server values at a given time interval. The first numeric argument to vmstat represents the time interval expressed in seconds. In the example that follows, I execute vmstat 3 and get a line of output every three seconds:

>

vmstat 3

kthr memory cpu

---- ... --------------- ... --------------

r b ... fre re pi sr ... cs us sy id wa

0 0 ... 207 0 1 0 ... 142 18 4 75 4

0 0 ... 187 0 4 0 ... 70 2 1 91 6

0 0 ... 184 0 0 0 ... 99 5 2 89 4

0 0 ... 165 0 0 0 ... 98 1 8 52 40

0 0 ... 150 0 3 0 ... 136 4 2 87 6

0 0 ... 141 0 1 0 ... 192 5 0 91 4

You can exit

The critical

vmstat at any time by pressing Ctrl-C. vmstat values that you need to know about are as follows:

r

The run queue. When this value exceeds the number of CPUs, the server is experiencing a CPU bottleneck. (You can get the number of CPUs by entering

lsdev -C|grep Process|wc -l.)

pi

The page-in count. Non-zero values typically indicate that the server is short on memory and that RAM is being written to the swap disk. However, non-zero values can also occur when numerous programs are accessing memory for the first time. To find out which is the case, check the scan rate (

sr) column. If both the page-in count and the scan rate are non-zero, then you are short on RAM.

sr

The scan rate. If you see the scan rate rising steadily, you know that the paging daemon is busy allocating memory pages.

For AIX and HP-UX,

vmstat also provides the following CPU values. These values are expressed as percentages and will sum to 100:

us

User CPU percentage

sy

System CPU percentage

id

Idle CPU percentage

wa

When the sum of user and system CPU percentages (

When wait CPU percentages (the

1.10.2 Use sar

The

Just like

There are three major flags that you can use with

sar utility (System Activity Reporter) is quite popular in SVR4 environments such as HP-UX and Solaris. It is also becoming widely available for AIX. top, sar gives detailed information about Oracle tasks from the Unix level. You will be able to see the overall consumption of CPU, disk, memory, and Journal File System ( JFS) buffer usage. sar :

sar -u

Shows CPU activity

sar -w

Shows swapping activity

sar -b

Shows buffer activity

1.10.2.1 sar -u (CPU report)

The

1.10.2.2 sar -w (memory switching and swapping activity)

The

The following example shows the swapping activity report that you get from

sar -w command is especially useful if you suspect that your database server is experiencing a memory shortage. When an Oracle server runs short of real memory, segments of RAM are swapped out to a swap disk. Such page-out operations happen frequently, but a page-in indicates that the Oracle server is exceeding the amount of RAM. The usual remedies for swapping are to reduce the size of the SGA and/or to buy more RAM for the database server. sar :

ROOT>

sar -w 5 5

HP-UX corp-hp1 B.11.00 U 9000/800 08/09/00

19:37:57 swpin/s bswin/s swpot/s bswot/s pswch/s

19:38:02 0.00 0.0 0.00 0.0 222

19:38:07 0.00 0.0 0.00 0.0 314

19:38:12 0.00 0.0 0.00 0.0 280

19:38:17 0.00 0.0 0.00 0.0 295

19:38:22 0.00 0.0 0.00 0.0 359

Average 0.00 0.0 0.00 0.0 294

The columns have the following meanings:

swpin/s

Number of process swap-ins per second

swpot/s

Number of process swap-outs per second

bswin/s

Number of 512-byte swap-ins per second

bswot/s

Number of 512-byte swap-outs per second

pswch/s

Number of process context switches per second

sar -u command is very useful for seeing the overall CPU consumption over time. CPU time can be allocated into the following four buckets: user mode, system mode, waiting on I/O, and idle. In the example that follows, I execute sar -u to see the state of the CPU:

Wait CPU percentage

us + sy) approaches 100, then the CPUs are busy, but not necessarily overloaded. The run queue value can indicate a CPU overload, but only when the run queue exceeds the number of CPUs on the server. wa values) exceed 20, then 20% or more of the processing time is waiting for a resource, usually I/O. It is common to see high wait CPU percentages during backups and exports, but they can also indicate an I/O bottleneck.
请使用浏览器的分享功能分享到微信等