Tcprstat测试mysql响应时间

Tcprstat测试mysql响应时间

一、tcprstat工具安装与使用

tcprstat 是一个基于 pcap 提取 TCP 应答时间信息的工具,通过监控网络传输来统计分析请求的响应时间。

  • 使用方法:
    tcprstat是安装在server端,统计分析本地网卡地址请求的响应时间,可以用于临时分析,也可定时任务做信息收集

1、 下载安装tcprstat

  • x86_64位操作系统可以直接下载二进制文件使用。
步骤如下:
1、下载文件 http://github.com/downloads/Lowercases/tcprstat/tcprstat-static.v0.3.1.x86_64
2、把下载的文件移动到 /usr/bin
3、把文件名修改为 tcprstat
4、修改文件权限,增加执行权限 chmod +x /usr/bin/tcprstat
  • i686操作系统只能自己编译。

源码下载

2、tcprestat 使用

[root@sql ~]#  tcprstat -p 3306 -t 1 -n 5 -I em1
tcprstat: invalid option -- 'I'
Usage: tcprstat [--port <port>] [--format=<format>] [--interval=<sec>]
             [--header[=<header>] | --no-header] [--iterations=<it>]
             [--read=<file>]
       tcprstat --version | --help

    --read <file>, -r    Capture from pcap file <file>, not live.
    --local <addresses>, -l
                         <addresses> is a comma-separated list of ip
                         addresses, which are used as the local list of
                         addresses instead of pcap getting the list.
                         This is useful when working with a pcap file got
                         from another host with different addresses.
    --port <port>, -p    Capture traffic only for tcp/<port>.
    --format <format>, -f
                         Output format. Argument is a string detailing
                         how the information is presented. Accepted codes:
                             %n - Response time count
                             %a - Response time media in microseconds
                             %s - Response time sum
                             %x - Response time squares sum
                             %m - Minimum value
                             %M - Maximum value
                             %h - Median value
                             %S - Standard deviation
                             %v - Variance (square stddev)
                             %I - Iteration number
                             %t - Timestamp since iteration zero
                             %T - Unix timestamp
                             %% - A literal %
                         Default is:
    "%T\t%n\t%M\t%m\t%a\t%h\t%S\t%95M\t%95a\t%95S\t%99M\t%99a\t%99S\n".
                         Statistics may contain a percentile between
                         the percentage sign and the code: %99n, %95a.
    --header[=<header>], --no-header
                         Whether to output a header. If not supplied, a
                         header is created out of the format. By default,
                         the header is shown.
    --interval <seconds>, -t
                         Output interval. Default is 10.
    --iterations <n>, -n
                         Output iterations. Default is 1, 0 is infinity

    --help               Shows program information and usage.
    --version            Shows version information.
  • 参数说明
命令行参数    简短形式   类型      描述                    默认值
--format       -f     字符串    输出格式化字符串  ”%T\t%n\t%M\t%m\t%a\t%h\t%S\t%95M\t%95a\t%95S\t%99M\t%99a\t%99S\n” 
--help                          显示帮助信息
--interval    -t      数字      监控多少秒输出一次统计     10
--iterations  -n      数字      迭代执行的次数             0 意味着无限循环
--local       -l      字符串    本级ip地址列表
--port        -p      数字      端口
--read        -r      字符串    pcap文件路径
--no-header           字符串    输出不显示头信息
--header              字符串    指定输出的头信息
--version                       显示版本信息

3、执行tcprtat

  • 运行 tcpstat 需要 root 权限。
[root@sqlmaster ~]# ifconfig -a
bond0: flags=5122<BROADCAST,MASTER,MULTICAST>  mtu 1500
        ether c6:81:ba:27:41:22  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

bond2: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.106.156  netmask 255.255.255.0  broadcast 192.168.106.255
        inet6 fe80::266e:96ff:fe7a:2530  prefixlen 64  scopeid 0x20<link>
        ether 24:6e:96:7a:25:30  txqueuelen 1000  (Ethernet)
        RX packets 841045952  bytes 140694028836 (131.0 GiB)
        RX errors 0  dropped 9  overruns 0  frame 0
        TX packets 879251828  bytes 315328775843 (293.6 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 24:6e:96:7a:25:30  txqueuelen 1000  (Ethernet)
        RX packets 229601719  bytes 41718497150 (38.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 216881448  bytes 77518470229 (72.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 24:6e:96:7a:25:30  txqueuelen 1000  (Ethernet)
        RX packets 233564715  bytes 33185099691 (30.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 284092875  bytes 114906661329 (107.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.48.156  netmask 255.255.255.0  broadcast 192.168.48.255
        inet6 fe80::266e:96ff:fe7a:2534  prefixlen 64  scopeid 0x20<link>
        ether 24:6e:96:7a:25:34  txqueuelen 1000  (Ethernet)
        RX packets 24855939  bytes 2219201978 (2.0 GiB)
        RX errors 0  dropped 161  overruns 0  frame 0
        TX packets 27211500  bytes 30274496459 (28.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x91a80000-91afffff  

em4: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 24:6e:96:7a:25:35  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x91a00000-91a7ffff  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 74096282  bytes 26484813440 (24.6 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74096282  bytes 26484813440 (24.6 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


[root@sqlmaster ~]# 
[root@sqlmaster ~]#  tcprstat -p 3306 -t 1 -n 5 
pcap: SIOCGIFFLAGS: bonding_masters: No such device --那说明没自动获取服务器ip。需要使用-l参数手动指定IP。

[root@sqlmaster ~]# tcprstat -p 3306 -t 1 -n 5 -l 192.168.106.156    --指定ip、指定端口
timestamp   count   max min avg med stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1541410855  9   412 35  121 86  108 132 84  38  132 84  38
1541410856  11  432 24  136 84  135 332 107 102 332 107 102
1541410857  3   506 173 360 401 139 401 287 114 401 287 114
1541410858  7   516 73  270 234 140 360 229 105 360 229 105
1541410859  8   177 23  77  78  50  107 63  34  107 63  34
  • 通过如下的方式,不过是统计分析机器的所有ip地址

Centos6 统计分析机器的所有ip地址

[root@master(36.100) ~]# tcprstat -p 3306 -t 1 -n 0 -l `/sbin/ifconfig | grep 'addr:[^ ]\+' -o | cut -f 2 -d : | xargs echo | sed -e 's/ /,/g'`
timestamp   count   max min avg med stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1541412023  186 69239   26  922 450 5152    675 423 171 10490   489 760
1541412024  122 59761   65  2050    481 7520    2758    526 247 34144   1288    4441
1541412025  134 72180   126 1343    562 6337    838 527 123 10543   733 1289
1541412026  151 49829   39  1088    543 4340    792 513 122 10413   647 1016
1541412027  130 62064   83  1150    573 5513    741 527 128 5134    571 427
1541412028  130 34246   363 814 450 2989    691 480 92  3045    514 256
1541412029  125 55868   52  1287    593 5430    782 552 108 12540   659 1082
1541412030  129 49267   117 837 434 4281    653 446 79  737 456 93
1541412031  131 83227   57  1171    580 7197    683 529 123 755 537 123
1541412032  135 58226   55  1019    599 4947    813 559 123 1667    577 162
1541412033  149 46590   386 977 609 3820    712 600 69  912 609 79
1541412034  67  56254   55  1656    614 6976    701 575 119 15967   829 1886
  • Centos7 统计分析机器的所有ip地址
[root@sqlmaster ~]# tcprstat -p 3306 -t 1 -n 0 -l `/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
timestamp   count   max min avg med stddev  95_max  95_avg  95_std  99_max  99_avg  99_std
1541412404  0   0   0   0   0   0   0   0   0   0   0   0
1541412405  0   0   0   0   0   0   0   0   0   0   0   0
1541412406  17  754 26  134 73  178 395 95  91  395 95  91
1541412407  98  467 22  62  57  59  97  52  23  402 58  42
1541412408  10  1020    72  234 130 286 479 147 120 479 147 120
1541412409  8   126 26  61  64  34  90  52  25  90  52  25
1541412410  2   515 490 502 515 25  490 490 0   490 490 0
1541412411  1   380 380 380 380 0   0   0   0   0   0   0
1541412412  49  436 19  101 67  105 360 80  67  435 94  95
1541412413  1   435 435 435 435 0   0   0   0   0   0   0
1541412414  0   0   0   0   0   0   0   0   0   0   0   0
1541412415  9   444 26  112 54  124 175 70  44  175 70  44
1541412416  29  446 21  148 77  134 399 127 111 435 138 123
1541412417  58  403 18  91  60  96  332 74  66  398 85  88
1541412418  10  306 23  98  76  78  159 75  37  159 75  37
1541412419  0   0   0   0   0   0   0   0   0   0   0   0
[root@sqlmaster ~]# 

猜你喜欢

转载自www.cnblogs.com/gczheng/p/9910675.html