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. L229 词汇题

    The incidence of lung cancer is particularly high among long-term heavy smokers,especially chain smo ...

  2. java读取大容量excel之一

    最近在用poi读取大容量excel,发现只要是excel文件大于2M左右,便会出现OOM(out of memory),经过查询得知,原来poi读取excel的原理是如下: org.apache.po ...

  3. 查看Linux下系统资源占用常用命令

    一 top命令 1.作用top命令用来显示执行中的程序进程,使用权限是所有用户. 2.格式top [-] [d delay] [q] [c] [S] [s] [i] [n] 3.主要参数d:指定更新的 ...

  4. IOS沙盒机制

    一,ios应用程序只能在为该程序创建的文件系统中读取文件,不可以去其他地方访问,此区域被称为沙盒 1,每个应用程序都有自己的存储空间 2,应用程序不能翻过自己的围墙去访问别的存储空间的内容. 3,应用 ...

  5. Global.asax 详解

    在网上找了N多相关的东西总说的不够细,现在终于找到了.可以了解web.cofig和Global.asax之间的关系以及执行的顺序. 在Global.asax.cs文件中 protected void ...

  6. David Silver 强化学习原理 (中文版 链接)

    教程的在线视频链接: http://www.bilibili.com/video/av9831889/ 全部视频链接: https://space.bilibili.com/74997410/vide ...

  7. 获奖感言和C语言的学习心得

    获奖感言和C语言的学习心得 自我介绍: 大家好,我的名字叫袁忠,我来自湖南,今年快19岁了,现在是大学一年级,我平时喜欢跑步.打羽毛球,我也喜欢学算法与数学,以及喜欢看一些与计算机有关的书籍,每次我学 ...

  8. jquey学习2之jquery动态添加页面片段

    第一个方法:append()方法 [1]$(selector).append(content)//向匹配的所有标签中的内容末尾处添加Html代码,会编译成页面显示. <html> < ...

  9. Oracle集合类型

    Oracle集合类型介绍   集合类型   1. 使用条件:    a. 单行单列的数据,使用标量变量 .     b. 单行多列数据,使用记录    c. 单列多行数据,使用集合        *集 ...

  10. smarty学习——编程知识

    smarty 提供了丰富的api 接口可以方便我们进行操作: 1.clear_all_assign清除所有赋值 2.clear_all_cache清除所有缓存 3.clear_assign清除赋值 4 ...