MySQL响应时间监测

 大家习惯于以响应时间来衡量性能表现,实际响应时间指的正是从接收请求开始到发送响应之间的时间跨度。我们通常的做法是在代码里加入日志计算时间,这个是不准确的,该方式只是单单计算应用程序内部经过的时间,没有计算网卡到应用程序,应用程序到网卡的时间。这个会由于系统的负载发生很大的变化!wireshark  和 tcpdump  这种抓包的方式,极需要耐心关键它不是持续的。

      今天说的是Percona公司开源的工具:Tcprstat。

      简介:Tcprstat  免费,开源的 TCP分析工具,它会检测网络的传输,并且计算请求和响应之间的delay 它的输出格式 就像是linux里面的vmstat iostat 的格式一样进行输出。这个工具能够检测到某个端口的流量情况。所以呢它可以监听像mysqld httpd memcached 单个守护进程的请求和响应时间,或者其他的processer。(PS:这个工具不只是应用于MySQL哦)

     优点:

     1、轻量级,开销小,不用写入大量日志,不用分析大量的日志

     2 、 请求和响应的时间 精确到微妙级。

     3、输出的信息很容易导入到表格,或通过脚本格式化,或使用gnuplot的图形,等等

     4、这个与协议无关, works well for a large variety of client-server protocols that have a simple request-response model

     5、Tcprstat 关注于response的时间计算,并不是网卡流量的计算

     Response times 的计算方式:从最后的入站数据包的第一出站数据包锁经过的时间。。仅包含tcp控制信息的某些类型的数据包将被忽略。

     百分比计算方式:对响应时间进行排序再取出N%的结果。

     安装部分:

     下载地址:statically linked 64-bit binary (version 0.3.1)

     该文件是一个二进制文件,需要 重命名、加上可执行权限。

     执行:

     ./tcprstat -p 3306 -t 2 -n 2
     timestamp count max  min avg med stddev 95_max 95_avg 95_std 99_max  99_avg  99_std
     1343190264      72      2380    108     289     209     285     547     237     95      909     259     143

输出格式定义为:   

             Format Code     

    Header

  Default?   

 Meaning

  %n

count

y

Count of requests that completed during this iteration

  %a

avg

y

Average response time

  %s

sum

y

Sum of response times

  %x

sqs

 

Sum of squares of response times

  %m

min

y

Minimum response time

  %M

max

y

Maximum response time

  %h

med

y

Median response time

  %S

stddev

y

Standard deviation of response times

  %v

var

 

Variance of response times

 %I

iter#

 

Iteration number

 %t

elapsed

 

Seconds elapsed since the first iteration

 %T

timestamp

y

Unix timestamp

 %%

 

 

A literal %

\ t

 

 

A tab character

\n

 

 

A newline character

95,99

Adds a prefix

y

A percentile indicator; see later in this section for more

例如: tcprstat -f '%n\n' -p 3306 -t 1 -n 0

 

 语法为:

Option NameShort NameTypeDefault ValueMeaning
--format-fstring A format string; see above.
--[no]header stringEnabledIf no argument is given, tcprstat auto-generates the header based on --format. If an argument is given,tcprstat uses that as the header instead. If --no-header is used,tcprstat will not print a header.
--help   Shows program information and usage.
--interval-tinteger10The number of seconds tcprstatwaits between each successive line of output.
--iterations-ninteger1How many iterationstcprstat should execute before exiting; 0 means infinity.
--local-lstring Accepts a comma-separated list of IP addresses to consider as local IP addresses, instead of getting a list from the operating system.
--port-pinteger Capture traffic only for the specified TCP port; if none, capture all traffic.
--read-rstring Read the specified pcap file instead of capturing traffic from the network.
--version   

Shows version information.

tcprstat 还可以分析一个 TCPDUMP 抓包文件。

如果想将结果生成图像,可以利用gnuplot的图形,

具体参考:http://www.ibm.com/developerworks/cn/linux/l-gnuplot/?ca=dwcn-newsletter-linux

本文参考:http://www.percona.com/docs/wiki/tcprstat:start






本文转自 位鹏飞 51CTO博客,原文链接:http://blog.51cto.com/weipengfei/941918,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值