您的位置:首页 > 数据库 > SQL

mysql监控和性能分析工具

2015-01-29 09:59 609 查看
mysql监控和性能分析工具

Mysql作为广泛应用的数据库系统,平时运维工作中对她的监控必不可少,现在把我对Mysql数据库的监控体会写成下文,欢迎拍砖。

无论是DBA或是SA,监控的目标都很明确,无外乎 

1.快速的得到Mysql过去一段时间或者当前运行的状态

2.因硬件升级或者系统配置的改变而诊断对Mysql数据库性能影响

3.在Mysql数据库系统出现故障要能够及时收到告警

4.为日后编写运维报告提供各项数据指标供分析

5.……

想到了再做补充。而所有以上这些目的,通过各种方法和手段都可以做到。

   自从Mysql数据库系统启动并且提供服务,Mysql内部自身的一套“计数器”就开始工作,可以通过

Show Global Status , Show global variables ,Show full processlist

得到Mysql数据库系统当前各种系统变量和状态 ,并且后文介绍个各种监控工具几乎都是对这三个指令的输出

进行数据的计算和统计分析。

这里要提到的是mysqladmin这个Mysql自带的工具,除了用来做各种管理工作,还 可以用来做监控

例如:每个10秒输出一次mysql的状态信息

#./mysqladmin -i 10 extended status

下面进入文章正题

一。GUI 类监控工具

1.MySQL administrator

Mysql公司发布管理工具,安装和使用都很方便

可以对Mysql 的状态,变量和进程监控,并且有简单图形绘制输出。

2.Cacti

用它来做系统监控的同仁相信很多,目前各种插件数量也很多,足以满足绝大多数公司监控要求。

这里要说的是Mysql监控插件teMySQL_cacti,能够对mysql做比较全面的监 控,

但是我发现这个插件很长时间没有更新了。

3.Mysql-cacti-templates

Google cacti : http://code.google.com/p/mysql-cacti-templates/

这个应该说是teMySQL_cacti的升级和改进版本,项目发起人是主编《High Performance MySQL, Second Edition.》的作者

他的主页 http://www.xaprb.com/blog/

本人推荐使用,功能强大丰富。

4.Nagios

这个天天使用,没啥好说的,可以自己写监控脚本来监控,和cacti结合使用是不错的搭配!

5.Munin

Munin是一款和cacti类似的系统监控工具,有兴趣的可以去研究研究

http://munin.projects.linpro.no/ ,这里不多说

6.Zenoss

测试过一次,用的不多,不做什么评价

7.MySQL Enterprise Monitor

Mysql 旗舰付费产品,功能丰富

详细信息 http://www.mysql.com/products/enterprise/monitor.html

能够监控,报警,绘图,并提供性能优化和建议,集众多监控指标于一身,好是好,可以要花钱的 哦

有兴趣的可以去download 30天的试用版本体验。

二。文字模式的监控工具

我了解并使用过的有

1.mytop

类似linux下top命令的输入

http://jeremy.zawodny.com/mysql/mytop/

2.mtstat-mysql

http://pypi.python.org/pypi/mtstat-mysql/0.7.3.3

3.mysqlreport

http://hackmysql.com/mysqlreport

看我写的这篇文章

用mysqlreport监控并输出mysql状态值  http://www.askwan.com/read.php?44

4.innotop

这个针对innodb存储引擎数据库的监控,功能丰富

http://www.xaprb.com/blog/2006/07/02/innotop-mysql-innodb-monitor/

三。自己写脚本监控

参看我以前写过一篇文章

http://www.askwan.com/read.php?96

方法和原理一样,可以定制需求

以上各种工具和方法各有自己特色,如何选择,可以根据需求和自己的情况定,目的只有一个,效 益最大化!

--------------------END-------------------- 相关日志

地址:http://www.askwan.com/read.php?140

 

==================用mysqlreport监控并输出mysql状态值====================

      mysqlreport 以非 常友好的方式显示MySQL状态变量值。和SHOW STATUS不同,mysqlreport以一种非常格式化的方式输出状态值,具有非常好的可读性。

官 方站点是:http://hackmysql.com

安 装mysqlreport非常简单

Quotation#cd /usr/local/sbin

#wget hackmysql.com/scripts/mysqlreport

#chmod 755 mysqlreport

常 用选项

Quotation#mysqlreport --help        

mysqlreport v3.5 Apr 16 2008

mysqlreport makes an easy-to-read report of important MySQL status values.

Command line options (abbreviations work):

--user USER       Connect to MySQL as USER

--password PASS   Use PASS or prompt for MySQL user's password

--host ADDRESS    Connect to MySQL at ADDRESS

--port PORT       Connect to MySQL at PORT

--socket SOCKET   Connect to MySQL at SOCKET

--no-mycnf        Don't read ~/.my.cnf

--infile FILE     Read status values from FILE instead of MySQL

--outfile FILE    Write report to FILE

--email ADDRESS   Email report to ADDRESS (doesn't work on Windows)

--flush-status    Issue FLUSH STATUS; after getting current values

--relative X      Generate relative reports. If X is an integer,

reports are live from the MySQL server X seconds apart.

If X is a list of infiles (file1 file2 etc.),

reports are generated from the infiles in the order

that they are given.

--report-count N  Collect N number of live relative reports (default 1)

--detach          Fork and detach from terminal (run in background)

--help            Prints this

--debug           Print debugging information

Visit http://hackmysql.com/mysqlreport for more information.

#mysqlreport  --user USER  --password PASS

QuotationMySQL 5.0.37-log         uptime 0 0:21:32       Tue Apr 29 23:55:28 2008

__ Key _________________________________________________________________

Buffer used    12.16M of 512.00M  %Used:   2.38

Current      71.12M            %Usage:  13.89

Write hit       7.14%

Read hit       99.99%

__ Questions ___________________________________________________________

Total         126.66k    98.0/s

QC Hits      94.01k    72.8/s  %Total:  74.22

DMS          24.29k    18.8/s           19.18

Com_          6.27k     4.9/s            4.95

COM_QUIT      2.09k     1.6/s            1.65

-Unknown          2     0.0/s            0.00

Slow 5 s            0       0/s            0.00  %DMS:   0.00  Log:  ON

DMS            24.29k    18.8/s           19.18

SELECT       24.16k    18.7/s           19.08         99.47

UPDATE          121     0.1/s            0.10          0.50

REPLACE           6     0.0/s            0.00          0.02

INSERT            2     0.0/s            0.00          0.01

DELETE            0       0/s            0.00          0.00

Com_            6.27k     4.9/s            4.95

set_option    4.18k     3.2/s            3.30

change_db     2.09k     1.6/s            1.65

show_variab       3     0.0/s            0.00

__ SELECT and Sort _____________________________________________________

Scan            2.52k     2.0/s %SELECT:  10.44

Range           2.46k     1.9/s           10.17

Full join         881     0.7/s            3.65

Range check         0       0/s            0.00

Full rng join       0       0/s            0.00

Sort scan       3.83k     3.0/s

Sort range        527     0.4/s

Sort mrg pass       6     0.0/s

__ Query Cache _________________________________________________________

Memory usage    6.39M of  32.00M  %Used:  19.98

Block Fragmnt  16.20%

Hits           94.01k    72.8/s

Inserts        23.61k    18.3/s

Insrt:Prune  23.61k:1    18.3/s

Hit:Insert     3.98:1

__ Table Locks _________________________________________________________

Waited             15     0.0/s  %Total:   0.04

Immediate      35.38k    27.4/s

__ Tables ______________________________________________________________

Open               98 of  512    %Cache:  19.14

Opened            104     0.1/s

__ Connections _________________________________________________________

Max used           11 of 1000      %Max:   0.11

Total           2.09k     1.6/s

__ Created Temp ________________________________________________________

Disk table        153     0.1/s

Table           3.83k     3.0/s    Size:   2.0G

File               17     0.0/s

__ Threads _____________________________________________________________

Running             2 of    3

Cached              5 of    8      %Hit:  99.47

Created            11     0.0/s

Slow                0       0/s

__ Aborted _____________________________________________________________

Clients             0       0/s

Connects            0       0/s

__ Bytes _______________________________________________________________

Sent          140.73M  108.9k/s

Received       12.88M   10.0k/s

__ InnoDB Buffer Pool __________________________________________________

Usage         304.00k of   8.00M  %Used:   3.71

Read hit       84.42%

Pages

Free            493            %Total:  96.29

Data             19                      3.71 %Drty:   0.00

Misc              0                      0.00

Latched           0                      0.00

Reads              77     0.1/s

From file        12     0.0/s           15.58

Ahead Rnd         1     0.0/s

Ahead Sql         0       0/s

Writes              0       0/s

Flushes             0       0/s

Wait Free           0       0/s

__ InnoDB Lock _________________________________________________________

Waits               0       0/s

Current             0

Time acquiring

Total             0 ms

Average           0 ms

Max               0 ms

__ InnoDB Data, Pages, Rows ____________________________________________

Data

Reads            25     0.0/s

Writes            3     0.0/s

fsync             3     0.0/s

Pending

Reads           0

Writes          0

fsync           0

Pages

Created           0       0/s

Read             19     0.0/s

Written           0       0/s

Rows

Deleted           0       0/s

Inserted          0       0/s

Read              0       0/s

Updated           0       0/s

通过这个报表可以快速 知道mysql的运行状态,需要做什么调整等

更多信息和相关用法可以参考The Guide To Understanding mysqlreport

报表说明参考:http://bbs.chinaunix.net/thread-1323591-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: