不要追求绝对的公平,红尘之中没有公平而言,人活一世,难得糊涂。                                           it is no use doing what you like, you have got to like what you do.

监控程序MYSQL

上一篇 / 下一篇  2007-06-15 15:14:13 / 个人分类:Mercury LoadRunner

51Testing软件测试网"H\h-NPY

监控程序:

Q%GE PSR0
#!/usr/bin/env python51Testing软件测试网r`9g5nQQ0y(Q
#
-*- coding: cp936 -*-51Testing软件测试网-ZS2aWL[IE n
import threading,os,time51Testing软件测试网ZdMW&m%v.JB

+~IZ_l@A^R0
class Config_th:51Testing软件测试网3h4|3H1h9Cz)bQ#j
    
pn)[d-x_0    
def Config_m(self):51Testing软件测试网;[ l2ha6n5E2cS
        51Testing软件测试网+Ig XW9Z{e~
        
#global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday
_0]w1F*}0
        path = "monitor_config."51Testing软件测试网1b } u [fQ
        monitor_config_path 
= open(path,'r')
d[R(B.h$[9X3@0        config_list 
= monitor_config_path.readlines()51Testing软件测试网"O8n_6\7?-P^
        
#Set WorkPath Config 51Testing软件测试网 C LDUl}h5q&z
        set_workpath = config_list[1][10:-1]51Testing软件测试网.cJ?2m5YqEX&W
        
#set CommandPath Config
6`)N&_-Q/`0
        set_commandpath = config_list[2][13:-1]51Testing软件测试网Q0T8w$P|(n1S
        
#set looptime Config
MLdO)YsL0
        set_looptime = config_list[3][17:-1]
6]z,Y3UsM{0        
#set loopdata Config51Testing软件测试网bX#gOx'h7FX
        set_loophour = config_list[4][14:-1]
Bn.v'_/u i Fu A0        
#set loopday Config51Testing软件测试网F]5l^"@:O
        set_loopday = config_list[5][14:-1]51Testing软件测试网9Be6E8SnN!i{a X
        
#test(os.system("echo %s" % (set_loopday)))51Testing软件测试网:oI t4N F)b] a2_m4T
        return set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday
Kp(u#C mjm051Testing软件测试网^*Z#|9s B.w^
class Cpuinfo_th(threading.Thread,Config_th):51Testing软件测试网 u0i"L J ak
    
!j+{)TF @0    
def __init__(self):51Testing软件测试网'm1\@C/NB
        threading.Thread.
__init__(self)
x2Ea.O8Hd0    
def run(self):
#EF3`jiqr}!eK0        
#global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday
!T MQUQ0
        set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday = self.Config_m()
:^bZp0Ti+zE0        os.system(
"%s/iostat -t -c 1 1 >> %s/cpu_info.txt" % (set_commandpath,set_workpath))
3a9os!wK4t2e]0            
4L'hru9Mh(N;J0
class Memoryinfo_th(threading.Thread,Config_th):51Testing软件测试网c%I+Of(Kf%s4L
    51Testing软件测试网x"f/om$D qR
    
def __init__(self):
0zJ0R-d(]~Lt0        threading.Thread.
__init__(self)
lLU/n8B:{,Y*P0    
def run(self):
)qA3DX7PsJw0        
#global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday
r\4\4ey0
        set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday = self.Config_m()
2Mc e j(M4W0        os.system(
"/usr/bin/vmstat -S K 1 1 >> %s/memory_info.txt" % (set_workpath))
&BEL @tz9^[ Q&o0        
V@,S]XhrR6z0
class Deciveinfo_th(threading.Thread,Config_th):51Testing软件测试网rJN+dgQ
    51Testing软件测试网S[&p+Q1F-Y`D
    
def __init__(self):
[ {djQ?k0        threading.Thread.
__init__(self)
5[;c_%W&cMX0tM0    
def run(self):51Testing软件测试网+J ASR O#Or.Y$v;P?
        
#global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday51Testing软件测试网f/T5JAt1X
        set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday = self.Config_m()51Testing软件测试网.{/w^O)BP
        os.system(
"%s/iostat -d 1 1 >> %s/decive_io_info.txt" % (set_commandpath,set_workpath))
l-o rT[)e051Testing软件测试网#r3PW8o)rz
class Totalinfo_th(threading.Thread,Config_th):51Testing软件测试网7c!h7U1X,P An+O5V8z
    
x8|(z'q!Uoe0    
def __init__(self):51Testing软件测试网R O_qgy
        threading.Thread.
__init__(self)51Testing软件测试网:p]y/[y]|f9Uh
    
def run(self):51Testing软件测试网Z)sv0|mI
        
#global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday
JK&uh-[0p,HE0
        set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday = self.Config_m()51Testing软件测试网5zX6{m/L7WM)a7K
        os.system(
"%s/sar -u 1 1 >> %s/total_info.txt" % (set_commandpath,set_workpath))51Testing软件测试网A,Im!X"|b!P+n5L
        
a9NxQ B0
class Control(Config_th):
?b QwZSl.G0    
?D5ij w0    
def console(self):
z2DK+n0Q\S0        
#application object
Or9P oD `6p0
        global set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday51Testing软件测试网Q"SEl*CzW\+C"c
        cpuinfo_th 
= Cpuinfo_th()
H4mCt!j0        memoryinfo_th 
= Memoryinfo_th()51Testing软件测试网,O#v'o+e.R4~@|
        deciveinfo_th 
= Deciveinfo_th()51Testing软件测试网v+X*XK*L ~E ^
        totalinfo_th 
= Totalinfo_th()51Testing软件测试网Z4uR$?^/d
        set_workpath,set_commandpath,set_looptime,set_loophour,set_loopday 
= self.Config_m()
N)^opN \*] B0B0        
#loop control main()51Testing软件测试网(I/w ^3N q,M(N%}
        for i in range(float(str(set_loopday))):51Testing软件测试网(f/r/Q2v/q
            
for i in range(float(str(set_loophour))):51Testing软件测试网u?5v_Ck#u E5O i
                time.sleep(float(str(set_looptime)))51Testing软件测试网4lL3Wa`%Lo
                
print "Execute OK!,run cpuinfo,%d" % (i)
1cu B5RrTn0                cpuinfo_th.run()
%EQw^ n0G2m0~6t0                time.sleep(
0.001)
P!E*F8^3n0                
print "Execute OK!,run memoryinfo,%d" % (i)
I#M`,tp0                memoryinfo_th.run()
2z}0dj.k,j+F0                time.sleep(
0.001)
/t%Y/p/{6F0                
print "Execute OK!,run deciveinfo,%d" % (i)
X#^$l Qa0                deciveinfo_th.run()51Testing软件测试网hVj.T.Zd*tL*q
                time.sleep(
0.001)51Testing软件测试网7m6Iia] r!Iz
                
print "Execute OK!,run totalinfo,%d" % (i)51Testing软件测试网(ToO'vA-x(jM2W
                totalinfo_th.run()51Testing软件测试网h^]IJ
                time.sleep(
0.001)51Testing软件测试网9v'R2RHm.H9R
                
print "Total Execute %d......" % (i)
'lhk6nGX0   
kwU!c9E }0
if __name__ == "__main__":
cl+`R j0    51Testing软件测试网T[X#y ^AW
    control 
= Control()
|G T Lp0Jn0    control.console()
8f\-O7a^~0        51Testing软件测试网 Z1s+Nz!M^x
        
)IS4C.v b#W0

}[4o i C?p0 参数配置:

s6s'A7['d&t?0

{o Su#b#|'N yA0[Config]
(F6N/?A_!Df@0work_path=/home/data51Testing软件测试网+\!c['p4O?'f
command_path=/usr/local/bin51Testing软件测试网o|C;m"\NB
loop_time_second=1051Testing软件测试网qk@+ty
loop_day_hour=224
&s/HP$HukMT0loop_week_day=751Testing软件测试网8L J4y i%j4R

[Cpu]51Testing软件测试网,W3{%i4_e3O
%usr:CPU处在用户模式下的时间百分比。 
!Kim/U7eU0%sys:CPU处在系统模式下的时间百分比。  51Testing软件测试网C6E(E'?QGl
%wio:CPU等待输入输出完成时间的百分比。
c K i6]|Z#s"k?+A0%idle:CPU空闲时间百分比。51Testing软件测试网0f1i3eRR
在所有的显示中,我们应主要注意%wio和%idle,%wio的值过高,表示硬盘存在I/O瓶颈, 51Testing软件测试网7}'E1Du;MxM
%idle值高,表示CPU较空闲,如果%idle值高但系统响应慢时,有可能是CPU等待分配内存, 51Testing软件测试网O y*d }*H[4LR%q
此时应加大内存容量。%idle值如果持续低于10,那么系统的CPU处理能力相对较低,表 
N+Wd)l:s7w0明系统中最需要解决的资源是CPU.
M(WZe5[ c-E0
ch%{w;c#HAQD0
[Decive]51Testing软件测试网"{%l9J,fy |Bb7X$_
bread/s: 每秒从硬盘读入系统缓冲区buffer的物理块数。 
8H HTE[ ](~"K:A0lread/s: 平均每秒从系统buffer读出的逻辑块数。 51Testing软件测试网il}w,e
%rcache: 在buffer cache中进行逻辑读的百分比。 
9Q [ U:esB0p0bwrit/s: 平均每秒从系统buffer向磁盘所写的物理块数。 
.LG-h"xV.Fi|0lwrit/s: 平均每秒写到系统buffer逻辑块数。 51Testing软件测试网JE]8I&}|F
%wcache: 在buffer cache中进行逻辑读的百分比。 
m/t!o'Z7L0pread/s: 平均每秒请求物理读的次数。 
!G{q9E?+z$X B}._0pwrit/s: 平均每秒请求物理写的次数。51Testing软件测试网 i q:V isi
在显示的内容中,最重要的是%cache和%wcache两列,它们的值体现着buffer的使用效 
Lz+a/B5o3B;tTy0率,%rcache的值小于90或者%wcache的值低于65,应适当增加系统buffer的数量,buffer 
of7d,Q3q V\x/v0数量由核心参数NBUF控制,使%rcache达到90左右,%wcache达到80左右。但buffer参数 51Testing软件测试网5E["H ~"rC0u}2l&V X't^
值的多少影响I/O效率,增加buffer,应在较大内存的情况下,否则系统效率反而得不到 51Testing软件测试网|+XL)y0E4`eU
提高。51Testing软件测试网(JUTD| q(pg9J
51Testing软件测试网;T z8G:}^5r#Udx}T
[Memory]
h9|1tR"`e-_Wg0procs: 51Testing软件测试网W1{g _ v5lXo'x
r-->
;在运行队列中等待的进程数 51Testing软件测试网i4P8O;u?*~a
b-->;在等待io的进程数 51Testing软件测试网N'L1] tsq
w-->;可以进入运行队列但被替换的进程 
(z0}!S"ZT2X@@0
memoy 51Testing软件测试网f L,P?v`z
swap-->
;现时可用的交换内存(k表示) 51Testing软件测试网(e'Br$qG0HHxfi
free-->;空闲的内存(k表示) 51Testing软件测试网l? C`C7J
pages 
^ QKLff0re--》回收的页面 
*G-^ bf.L4F6xf0mf--》非严重错误的页面 
Aj0XM#r ? wc z0pi--》进入页面数(k表示) 51Testing软件测试网 wP q$qO.]%y
po--》出页面数(k表示) 
L)HA] c:l |;S0fr--》空余的页面数(k表示) 
2XWg%bX t%q0de--》提前读入的页面中的未命中数 51Testing软件测试网$Uh#H7c7MR;B
sr--》通过时钟算法扫描的页面 51Testing软件测试网 ~ jQ#i!H]"?4} Z-v
disk 显示每秒的磁盘操作。 s表示scsi盘,0表示盘号 51Testing软件测试网VvgOi
fault 显示每秒的中断数 
:o.Y*M5J-y!]M%Fv0in--》设备中断 51Testing软件测试网/c4Ug/U/wB4[Vr!t
sy--》系统中断 51Testing软件测试网^4W+rOfq2z{
cy--》cpu交换 51Testing软件测试网(_} t6]xRR.rU
cpu 表示cpu的使用状态 51Testing软件测试网dp TLam$rR
cs--》用户进程使用的时间 51Testing软件测试网0I XFD3?8UL)C)h.AO
sy--》系统进程使用的时间 
5Dh&i([%zm*|Dd0id--》cpu空闲的时间 51Testing软件测试网y!fl'Md~
 51Testing软件测试网"T3x%@2H ?K
如果 r经常大于 
4 ,且id经常少于40,表示cpu的负荷很重。 51Testing软件测试网 j1WUV~
如果pi,po 长期不等于0,表示内存不足。 
!]']2b:lMr8|X0cJJ ~0如果disk 经常不等于0, 且在 b中的队列 大于3, 表示 io性能不好。 51Testing软件测试网"yu/l-vG A1^6pv

TAG:

 

评分:0

我来说两句

Open Toolbar