Linux主机和MySQL实时监控工具-orzdba

代码SVN地址:
http://code.taobao.org/p/orzdba/src/trunk/
说明:
Perl脚本,用于对Linux主机和MySQL相关指标进行实时监控。
工具主要有如下参数:

下面分别说明一下:
1、查看Linux主机指标
-l,–load           Print Load Info.

-c,–cpu            Print Cpu  Info.

-s,–swap           Print Swap Info.

-d,–disk           Print Disk Info.

-n,–net            Print Net  Info.

-sys                Print SysInfo   (include -t,-l,-c,-s)
这些指标的数据都来自/proc目录下的相关系统元数据:
LOAD : /proc/loadavg
CPU  : /proc/stat
SWAP : /proc/vmstat
DISK : /proc/diskstats
NET  : /proc/net/dev
其中,查看DISK(-d)和NET(-n)需要带具体的设备名(具体可以查看/proc/diskstats和/proc/net/dev中的设备或者可以取自iostat和sar -n DEV)。

2、查看MySQL指标
通过show variables列出经常关注的核心变量。
通过show global status列出相关MYSQL status信息。
-com
Print MySQL Status(Com_select,Com_insert,Com_update,Com_delete).

-hit
Print Innodb Hit%.

Hit% : (Innodb_buffer_pool_read_requests – Innodb_buffer_pool_reads) / Innodb_buffer_pool_read_requests * 100%


-innodb_rows
Print Innodb Rows Status(Innodb_rows_inserted/updated/deleted/read).

-innodb_pages
Print Innodb Buffer Pool Pages Status(Innodb_buffer_pool_pages_data/free/dirty/flushed)

-innodb_data
Print Innodb Data Status(Innodb_data_reads/writes/read/written)

-innodb_log
Print Innodb Log  Status(Innodb_os_log_fsyncs/written)


-innodb_status
Print Innodb Status from Command: ‘Show Engine Innodb Status‘ (history list/ log unflushed/uncheckpointed bytes/ read views/ queries inside/queued)

另外,-innodb_status的信息来自如下:

其中:
log unflushed = Log sequence number – Log flushed up to
uncheckpointed bytes = Log sequence number – Last checkpoint at
-T,–threads
Print Threads Status(Threads_running,Threads_connected,Threads_created,Threads_cached).

-B,–bytes
Print Bytes received from/send to MySQL(Bytes_received,Bytes_sent).

-mysql
Print MySQLInfo (include -t,-com,-hit,-T,-B).

-innodb
Print InnodbInfo(include -t,-innodb_pages,-innodb_data,-innodb_log,-innodb_status)

3、查看MySQL的响应时间
-rt                 Print MySQL DB RT(us).
通过调用tcprstat来监控MySQL的响应时间。
-rt中列的具体意义参考http://www.percona.com/docs/wiki/tcprstat:start 中的解释。

-rt参数依赖:
(1)需要安装tcprstat
由于安装后运行tcprstat需要root用户,或者sudo进行,可以通过如下命令来避免:
$ sudo wget http://github.com/downloads/Lowercases/tcprstat/tcprstat-static.v0.3.1.x86_64
$ sudo cp tcprstat-static.v0.3.1.x86_64 tcprstat

$ sudo chown root:root /usr/local/bin/tcprstat
$ sudo chmod u+s /usr/bin/tcprstat ; sudo cp tcprstat /usr/local/bin/
$ ll /usr/local/bin/tcprstat
-rwsr-xr-x 1 root root 1183465 May 28 15:38 /usr/local/bin/tcprstat


$ sudo tcprstat -p 1588 -t 1 -n 0 (针对Bonding网口,无法识别)
pcap: SIOCGIFFLAGS: bonding_masters: No such device
 
指定确定ip地址可以避免上面的错误
$ sudo tcprstat -p 1588 -t 1 -n 0 -l 192.168.0.200
timestamp       count   max     min     avg     med     stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1357885445      256     73120   67      746     245     4607    995     349     285     3107    399     405
1357885446      256     2610    84      365     255     317     846     330     266     906     351     281
1357885446    36      968     127     370     278     287     900     336     259     908     353     272
 
还可以通过如下的方式,不过是统计分析机器的所有ip地址
$ sudo tcprstat -p 1588 -t 1 -n 0 -l `/sbin/ifconfig | grep 'addr:[^ ]\+' -o | cut -f 2 -d : | xargs echo | sed -e 's/ /,/g'`
 
如下是一台生产数据库的响应时间
$ sudo tcprstat -p 1588 -t 1 -n 0 -l `/sbin/ifconfig | grep 'addr:[^ ]\+' -o | cut -f 2 -d : | xargs echo | sed -e 's/ /,/g'`
timestamp       count   max     min     avg     med     stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1357886048      5840    26133   54      240     163     500     664     184     101     1411    214     183
1357886049      6003    3405    57      227     164     242     660     182     96      1296    211     173
1357886050      6376    27322   29      269     168     689     724     194     117     1643    226     196
1357886051      6524    20489   58      225     167     330     613     182     92      1168    208     160
1357886052      6123    33313   52      231     165     497     627     181     94      1213    209     164
1357886053      6991    66977   55      221     167     822     525     176     80      1120    199     140
1357886054      5876    11483   57      234     162     427     610     177     89      1195    204     160
1357886055      6166    189134  30      526     187     3085    1265    245     202     6366    342     561
1357886056      5678    5913    52      210     161     218     553     172     81      1100    196     142


默认工具读取tcprstat的代码如下:
$grep -n ‘my $TCPRSTAT’ orzdba

166:my $TCPRSTAT = “/usr/bin/tcprstat –no-header -t 1 -n 0 -p $port”;
不同的路径可以自行修改。
(2)需要安装Perl的File::Lockfile模块
File::Lockfile模块同时要依赖Module-Build/version/Class-Data-Inheritable这3个模块,可以通过下面方式进行安装:
安装version模块:
$wget http://search.cpan.org/CPAN/authors/id/J/JP/JPEACOCK/version-0.99.tar.gz
$tar -zxvf version-0.99.tar.gz
$cd version-0.99
$perl Makefile.PL
$make
$make test
$sudo make install


安装Class-Data-Inheritable模块:
$wget http://search.cpan.org/CPAN/authors/id/T/TM/TMTM/Class-Data-Inheritable-0.08.tar.gz
$tar -zxvf Class-Data-Inheritable-0.08.tar.gz
$cd Class-Data-Inheritable-0.08
$perl Makefile.PL
$make
$make test
$sudo make install


安装Module-Build模块:
$wget http://search.cpan.org/CPAN/authors/id/K/KW/KWILLIAMS/Module-Build-0.31.tar.gz
$tar -zxvf Module-Build-0.31.tar.gz
$cd Module-Build-0.31
$perl Build.PL
$./Build
$./Build test
$sudo ./Build install


安装安装File::Lockfile模块:
$wget http://search.cpan.org/CPAN/authors/id/G/GL/GLORYBOX/File-Lockfile-v1.0.5.tar.gz
$tar -zxvf File-Lockfile-v1.0.5.tar.gz
$cd File-Lockfile-v1.0.5
$perl Build.PL
$perl ./Build
$perl ./Build test
$sudo perl ./Build install


可以通过如下脚本,检查安装了哪些perl模块的脚本:
$cat check_module.pl
#!/usr/bin/perl
use ExtUtils::Installed;
my $inst = ExtUtils::Installed->new();
print join “\n”,$inst->modules();
print “\n”;


4、其他
(1)MySQL相关参数配置
-P,–port           Port number to use for mysql connection(default 3306).

-S,–socket         Socket file to use for mysql connection.
用于指定端口或者socket。


如果需要MYSQL的其他参数要添加,直接改代码:
$grep -n -A1 ‘my $MYSQL’ orzdba
166:my $MYSQL    = qq{mysql -s –skip-column-names -uroot -P$port };
167-$MYSQL      .= qq{-S$socket } if defined $socket;


(2)控制输出间隔和次数,以及是否输出颜色。
-h,–help           Print Help Info.
-i,–interval       Time(second) Interval.
-C,–count          Times.
-t,–time           Print The Current Time.
-nocolor            Print NO Color.


(3)日志输出
-L,–logfile        Print to Logfile.
-logfile_by_day     One day a logfile,the suffix of logfile is ‘yyyy-mm-dd’;  and is valid with -L.
用于将数据输出到日志文件-L后面带输出的日志文件,另外如果加上-logfile_by_day参数的话,将按天输出日志。

原文地址:http://www.taobaodba.com/html/937_orzdba.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值