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 ~]#

Tcprstat测试mysql响应时间的更多相关文章

  1. mysql响应时间超时排查

    背景: 数据库运营环境,zabbix mysql响应时间告警,响应时间超时 zabbix监控 tcprstart 直接抓包响应时间看到每5秒钟就一次,与zabbix监控一致 [root@slave1( ...

  2. ubuntu下安装与测试mysql

    1.在决定安装mysql之前,要先确定系统是否已经安装mysql. 输入: 1 mysql 结果:说明尚未安装mysql The program 'mysql' is currently notins ...

  3. 测试MySQL事务管理

    1.MySQL 版本 mysql> select version(); +------------+ | version() | +------------+ -log | +--------- ...

  4. php测试mysql数据库连通性并且在浏览器每一秒输出一次结果

    有时候网络环境不稳定,需要测试mysql数据库的连接是否畅通,我们可以通过php脚本实现,具体代码如下,在360浏览器测试通过: <?php /* 循环打印出mysql连接测试 */ heade ...

  5. 测试mysql

    sysbench 测试mysql TODO emacs

  6. 5.JMeter测试mysql数据库

    1.使用jmeter测试mysql数据库时,需要导入jar包,jar包网盘地址为:链接: https://pan.baidu.com/s/1-5-s7HccudT4GirpmBVn6Q 密码: bea ...

  7. python测试mysql写入性能完整实例

    这篇文章主要介绍了python测试mysql写入性能完整实例,具有一定借鉴价值,需要的朋友可以参考下 本文主要研究的是python测试mysql写入性能,分享了一则完整代码,具体介绍如下. 测试环境: ...

  8. 【MySQL】测试MySQL表中安全删除重复数据只保留一条的相关方法

    第二篇文章测试说明 开发测试中,难免会存在一些重复行数据,因此常常会造成一些测试异常. 下面简单测试mysql表删除重复数据行的相关操作. 主要通过一下三个大标题来测试说明: 02.尝试删除dept_ ...

  9. SQL注入之DVWA平台测试mysql注入

    今天主要针对mysql常用注入语句进行测试. 测试环境与工具: 测试平台:DVWA,下载地址:http://down.51cto.com/data/875088,也可下载metaspolit-tabl ...

随机推荐

  1. mysql-5.6.17-win32安装

    下载免安装压缩文件http://dev.mysql.com/downloads/mysql/ 解压到自定义目录,我这里演示的是D:\wamp\mysql\   复制根目录下的my-default.in ...

  2. jQuery单选组美化特效

    需求:根据数据动态生成单选组 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  3. python3:jsonpath-rw处理Json对象

    前提:接口自动化测试中,存在依赖情况:test_02的某个请求参数的值,需要依赖test_01返回结果中某个字段的数据,所以就先需要拿到返回数据中特定字段的值.这里使用到python中jsonpath ...

  4. sql,用 ISNULL(), NVL(), IFNULL() and COALESCE() 函数替换空值

    在数据库操作中,往往要对一些查询出来的空值进行替换,如函数SUM(),这个函数如果没有值会返回NULL,这是我们不希望看到的, 在MySQL中我们可以这样来写: ) ... 在SQLSERVER中我们 ...

  5. Excel 设置标题栏

    1. 选中列表标题行, 可以设置字体居中显示,并放大字体以表示这是标题栏. 2. 选中列表第一数据行,即列表标题行下一行,选择View > Freeze Panes.

  6. PyTorch 数据集类 和 数据加载类 的一些尝试

    最近在学习PyTorch,  但是对里面的数据类和数据加载类比较迷糊,可能是封装的太好大部分情况下是不需要有什么自己的操作的,不过偶然遇到一些自己导入的数据时就会遇到一些问题,因此自己对此做了一些小实 ...

  7. VC++ 6.0 C8051F340 USB PC侧通信 Demo

    // HelloWorld.cpp : Defines the entry point for the console application. // /*********************** ...

  8. PR使用技巧

    1.要经常使用快捷键,这样能进步效率. 常用的快捷键是:+(放大),-(缩小),v(移动),c(切刀),x(变速),L(快放),ctrl+K(载切),ctrl+M(输出视频),ctrl+alt+M(输 ...

  9. 习题3.5 求链表的倒数第m个元素(20 分)浙大版《数据结构(第2版)》题目集

    请设计时间和空间上都尽可能高效的算法,在不改变链表的前提下,求链式存储的线性表的倒数第m(>0)个元素. 函数接口定义: ElementType Find( List L, int m ); 其 ...

  10. hdu1355

    题意:有一片矩形花生田在路的一侧,田上的整数坐标位置有0个或多个花生,现规定从路上走到田地最边上的某个格点位置.从田边上走回路上.从一个格点移动到另一个格点.采摘格点上的花生,这四种动作都要花费一单位 ...