tcprstat

tcprstat 

http://www.percona.com/docs/wiki/tcprstat:start

监控网络流量情况,计算请求的响应时间(the delay between request and response)

只能针对特定端口,对于统计类似mysqld、httpd、memcached等后台进程的响应时间比较实用。

tcprstat优点

1、轻量级,不会产生日志类文件

  • It is lightweight and unobtrusive. No bulky log files need be written and analyzed

2、request和response的时间可以精确到微秒级别microsecond 

  • Requests and responses are timed with microsecond resolution.

3、输出结果比较方便于表格统计或者图形化(gnuplot)

  • The output is easy to import into spreadsheets, manipulate with command-line scripts, graph with gnuplot, and so on.

4、协议未知(protocol-agnostic)层,对于简单的request-response模型都适用

  • It is protocol-agnostic, and works well for a large variety of client-server protocols that have a simple request-response model.

Response Time

Here “response time” means, for a given TCP connection, the time elapsed from the last inbound packet until the first outbound packet. For many simple protocols such as HTTP and MySQL, this is the moral equivalent of a query’s response time.

这里的响应时间是对于一个TCP连接来说,最后一个接收到的包和第一个发送的包之间时间间隔。对于类似HTTP、MySQL这些简单的协议来说,Respone time和Query的响应时间是对等的。

用法以及输出

[root@localhost ~]# ./tcprstat -p 5308 -t 1 -n 5
timestamp       count   max     min     avg     med     stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1383894304      46      4576    98      408     212     782     300     218     39      3199    315     480
1383894305      46      4258    102     326     208     606     314     206     48      954     239     158
1383894306      42      9767    102     988     232     2166    5576    492     1178    6906    774     1698
1383894307      42      9767    177     1192    232     2330    5575    680     1426    6907    983     1930
1383894308      38      9805    199     1811    234     3117    8441    1400    2652    8600    1595    2865

单位是微秒,包含两个百分比,95%以及99%

安装

参数以及结果分析

默认用法:

[root@typhoeus79 dstat-0.7.2]# tcprstat 
timestamp       count   max     min     avg     med     stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1383894884      471     24975   20      1866    1291    2472    4724    1499    1407    10987   1687    1693

基本参数:

  1. 端口:-p <port> selects a port
  2. 时间间隔:-i <secs> sets the measurement interval, in seconds
  3. 循环次数:0是无限制-n <iter> specifies the number of iterations to run; 0 means to run forever

定制化输出:

例子1:获取端口5308请求的次数

[root@localhost ~]# ./tcprstat -f '%n
' -p 5308 -t 1 -n 0    
count
46
43
41
38
44
42
41

例子2:获取最大响应时间、95%以及99%的最大响应时间

[root@kvasir88 guosong]# ./tcprstat -f '%M	%95M	%99M
' -p 3875 -t 1 -n 0  
max     95_max  99_max
282187  45414   100645
296978  42948   105187
458925  24736   101847
1681948 46504   146443
289493  39500   108248
1172935 28625   121042
1120742 35687   121058
480594  82955   211894

分析抓包文件

tcprstat不仅可以分析线上实时的访问情况,也可以分析抓取的文件,例如tcpdump

参数

原文地址:https://www.cnblogs.com/gsblog/p/3414374.html