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

代码SVN地址:

说明:

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

工具主要有如下参数:

orzdba_1_help.png

下面分别说明一下:

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

orzdba_2_host.png

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

orzdba_5_innodb_status.png

其中:

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)

orzdba_3_mysql.png

orzdba_4_innodb.png

3、查看MySQL的响应时间

-rt Print MySQL DB RT(us).

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

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

orzdba_6_rt.png

-rt参数依赖:

由于安装后运行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)需要安装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参数的话,将按天输出日志。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值