推荐一个实时统计MySQL read-write ratio的script

对于MySQL的读写比率统计,我们一般的做法是通过统计"show global status like 'com_%' "来得到相关数值。这里有一个不错的script。用来实时查看MySQL读写比率是个不错的选择。它的项目主页是http://code.google.com/p/rw-ratio/

安装与使用都很简单:

用perl写的嘛,DBI、DBD之类的依赖包肯定是少不了的。这个脚本使用到三个包分别是:

  a.perl-DBI

  b.perl-Term-ReadKey

  c.perl-DBD-MySQL

前面a、b两个包找一下匹配OS版本的rpm包装一下,至于最后的c包安装时会遇到找不到“libmysqlclient.so.1*”的问题。网上的解决方法很多,大多使用软链接的方式,不过如果遇到提供的是libmysqlclient.so.16而要的是libmysqlclient.so.15的情况下,这种方法很有可能是不行的。所以最好的方法是安装完a、b两个包后,使用tar包安装。

# tar -zxvf DBD-mysql-4.013.tar.gz

# cd DBD-mysql-4.013 

# perl Makefile.PL  --testhost=127.0.0.1         #这里要说明一下,最好要指定--testuser和--testpassword,这个用户最起码要对test.*拥有所有all privileges

# make  && make test

# make install

好了,环境完成后,直接运行这个统计r/w ratio的脚本即可。当然必要的参数还是要加的,比如'--user':

# ./rw-ratio  --host=localhost --user=lrngsql --port=3306 --sleep=10

 Enter password:
Time: xxxx        Interval: 10    R: xxx   dR: xxx  W: xxx  dW: xxx dR/dW: xxx     R/W: xxx

对于它的输出项,它的脚本里有详细的说明,这里粘一些:

=item B<Time>

The timestamp, expressed as a UNIX epoch, of the sample.

=item B<Interval>

The number of seconds between the previous sample and the current sample.

=item B<R>

The total number of database reads.

=item B<dR>

The delta of reads between the previous sample and the current sample.

=item B<W>

The total number of database writes.

=item B<dW>

The delta of writes between the previous sample and the current sample.

=item B<dR/dW>

The ratio of reads to writes, calculated using the current deltas

=item B<R/W>

The ratio of reads to writes, calculated using the totals 

 

posted @ 2010-03-10 18:46  番茄侠  阅读(1016)  评论(3编辑  收藏  举报