1. 程式人生 > >Tcprstat測試mysql響應時間

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 使用

[[email protected] ~]#  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 許可權。
[[email protected] ~]# 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


[[email protected] ~]# 
[[email protected] ~]#  tcprstat -p 3306 -t 1 -n 5 
pcap: SIOCGIFFLAGS: bonding_masters: No such device --那說明沒自動獲取伺服器ip。需要使用-l引數手動指定IP。

[[email protected] ~]# 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地址

[[email protected](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地址
[[email protected] ~]# 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
[[email protected] ~]#