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

摘要

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

代码SVN地址:

http://code.taobao.org/p/orzdba/src/trunk/

说明:

Perl脚本,用于对Linux主机和MySQL相关指标进行实时监控。

工具主要有如下参数:

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

下面分别说明一下:

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)。

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

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的信息来自如下:

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

其中:

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)

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

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

3、查看MySQL的响应时间

-rt                 Print MySQL DB RT(us).

通过调用tcprstat来监控MySQL的响应时间。

-rt中列的具体意义参考http://www.percona.com/docs/wiki/tcprstat:start 中的解释。

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

-rt参数依赖:

(1)需要安装tcprstat

由于安装后运行tcprstat需要root用户,或者sudo进行,可以通过如下命令来避免:

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

默认工具读取tcprstat的代码如下:

$grep -n ‘my $TCPRSTAT’ orzdba  166:my $TCPRSTAT = “/usr/bin/tcprstat –no-header -t 1 -n 0 -p $port”;

不同的路径可以自行修改。

2)需要安装PerlFile::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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: