设为首页 加入收藏

TOP

MySQL瑞士军刀(三)
2015-11-21 02:05:53 来源: 作者: 【 】 浏览:1
Tags:MySQL 瑞士军刀
支持即时刷新, 譬如输入dstat 3, 即每三秒收集一次, 但最新的数据都会每秒刷新显示. 和sysstat相同的是, dstat也可以收集指定的性能资源, 譬如 dstat-c 即显示CPU的使用情况.

?

运行dstat,如下所示

 [root@data01 ifstat-1.1]# dstat 3
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw 
  0   0  99   0   0   0|  24k 9603B|   0     0 | 254B 4410B|  38    48 
  0   0 100   0   0   0|   0  5461B|  80B  525B|   0     0 |  50    53 
  0   0 100   0   0   0|   0     0 |  70B  359B|   0     0 |  33    44 
  0   0 100   0   0   0|   0    21k| 146B  341B|   0     0 |  61    63 
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  31    44 ^C
[root@data01 ifstat-1.1]#

?

下面对显示出来的部分信息作一些说明:

1. cpu:hiq,siq分别为硬中断和软中断次数。

2. system:int,csw分别为系统的中断次数(interrupt)和上下文切换(context switch)

其他的都很好理解。

通过dstat --help可以看到常用参数选项

PS:这个软件和vmstat很像, 不过和vmstat相比好像少了io部份的显示, dstat只能显示磁盘的吞吐量而不是显示负载情况, dstat和几乎所有监控软件一样, 只能对整个系统进行监控而不能对某一个进程或某一个程序进行深入分析. 我常使用的参数是dstat -cdlmnpsy, 做个别名链接alias dstat='dstat -cdlmnpsy'

7,tcprstat工具

检查mysql偶发事件以及性能异常的工具,抓住当时的现场细节状况。

7.1 Bzr方式安装下载

bzr branch lp:tcprstat

tar czvf tcprstat.tar.gz ./tcprstat

cd tcprstat/

chmod +x bootstrap

安装 automake 和 autoconf

yum list|grep automake

yum list|grep autoconf

yum -y install automake

安装成功后,再重新执行bootstrap

./bootstrap

然后编译

./configure

make

7.2 集成方式下载

# 下载地址,wget下载失败,可以在windows下网页下载,然后secure上传到mysql服务器上面

7.3 实例

./tcprstat -p 3306 -t 1 -n 5

-p监控的端口号,-t 间隔时间,-n运行次数

 [root@wgq_idc_dbm_3_61 ~]# chmod a+x tcprstat 
[root@wgq_idc_dbm_3_61 ~]# ./tcprstat -p 3306 -t 1 -n 5
timestamp count     max       min       avg       med       stddev    95_max    95_avg    95_std    99_max    99_avg          99_std
1428142214          41        548646    28        79647     145       173376    418497    44645     125122    521857          67922     158663
1428142215          25        422953    22        54943     120       118359    201027    25393     65142     366568          39609     93352
1428142216          5         409520    193       155644    223       190817    368069    92175     159287    368069          92175     159287
1428142217          24        881981    45        52977     130       188839    1968      377       556       381189          16934     77661
1428142218          15        356049    49        24126     133       88711     1989      417       549       1989          417       549
[root@wgq_idc_dbm_3_61 ~]#

?

7.4,实际使用案例

如果用户觉得我们的mysql数据库响应时间很慢,查询也突然变慢,我们怎么办,方法肯定有许多种,这里可以选择用tcprstat,我们可以将./tcprstat -l 192.168.52.129 -p 3306 -t 1 -n 0 发给用户,让他在他的应用服务器上做一次啊tcprstat检测看下其中的响应时间是怎么样的,我们就可以知道具体原因是什么了。

8,tcpdump

抓包工具,可以截取到客户端对mysql数据库服务器的所有请求操作。

8.1简介

系统自带的工具包,如果没有的话,就使用yum安装(yum install –y tcpdump)用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具。 tcpdump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤,并提供and、or、not等逻辑语句来帮助你去掉无用的信息。

?

通过tcpdump查看参数信息:

[root@data02 ~]# tcpdump --help

tcpdump version 4.1-PRE-CVS_2010_08_20

libpcap version 1.0.0

Usage: tcpdump [-aAdDefIKlLnNOpqRStuUvxX] [-B size ] [ -c count ]

[-C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]

[-i interface ] [ -M secret ] [ -r file ]

[-s snaplen ] [ -T type ] [ -w file ] [ -W filecount ]

[-y datalinktype ] [ -z command ] [ -Z user ]

[expression ]

[root@data02 ~]#

tcpdump -s 0 -l -w - dst xxx.xxx.xxx.xxxand port 3306 |strings

?

8.2 使用

通过如下命令来监控192.168.52.129服务器mysql当前所执行的一切操作

tcpdump -i eth1 -s 0 -l -w - dst192.168.52.129 and port 3306 |strings,如下所示:

 [root@data01 ~]# tcpdump -i eth1 -s 0 -l -w - dst 192.168.52.129 and port 3306 |strings
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
V68@
select * from user_db.UC_USER
469@
5.6.12-log
9?o3MiL}
UmH^~"(APNw-
mysql_native_password
#28000Access denied for user 'repl'@'192.168.52.129' (using password: YES)
J6:@
SELECT DATABASE()
46;@
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇mysql远程导入导出数据库 下一篇mysqlin的两种用法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: