使用pt-query-digest进行日志分析
Posted 认真生活、快乐工作 - 马云
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用pt-query-digest进行日志分析相关的知识,希望对你有一定的参考价值。
使用pt-query-digest
sudo apt install percona-toolkit
也可以到官网
https://www.percona.com/downloads/percona-toolkit/LATEST/
下载安装
sudo dpkg -i /home/jiqing/下载/percona-toolkit_3.0.10-1.xenial_amd64.deb
查看帮助
[email protected]:/usr/bin$ pt-query-digest -h
Option h requires an argument
Usage: pt-query-digest [OPTIONS] [FILES] [DSN]
Errors in command-line arguments:
* Error parsing options
pt-query-digest analyzes mysql queries from slow, general, and binary log files.
It can also analyze queries from C<SHOW PROCESSLIST> and MySQL protocol data
from tcpdump. By default, queries are grouped by fingerprint and reported in
descending order of query time (i.e. the slowest queries first). If no C<FILES>
are given, the tool reads C<STDIN>. The optional C<DSN> is used for certain
options like L<"--since"> and L<"--until">. For more details, please use the
--help option, or try 'perldoc /usr/bin/pt-query-digest' for complete
documentation.
使用
sudo pt-query-digest /tmp/mysql-slow.log |less
# 220ms user time, 0 system time, 36.90M rss, 110.99M vsz
# Current date: Thu May 31 01:19:54 2018
# Hostname: jiqing-pad
# Files: /tmp/mysql-slow.log
# Overall: 127 total, 39 unique, 0.09 QPS, 0.00x concurrency _____________
# Time range: 2018-05-31 00:48:17 to 01:12:31
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 999ms 81us 334ms 8ms 38ms 33ms 247us
# Lock time 59ms 0 44ms 461us 445us 4ms 57us
# Rows sent 537 0 219 4.23 6.98 19.08 0.99
# Rows examine 52.59k 0 15.67k 424 592.07 1.97k 46.83
# Query size 16.53k 21 1.28k 133.31 346.17 131.28 130.47
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============= ===== ====== ===== ===============
# 1 0xDBD84EBCA96FD1B3 0.3335 33.4% 1 0.3335 0.00 SELECT information_schema.TABLES
# 2 0x4EBEE0C93679AA3A 0.1654 16.6% 15 0.0110 0.14 SELECT INFORMATION_SCHEMA.SCHEMATA
# 3 0xA1E689B034771CD3 0.0820 8.2% 6 0.0137 0.06 SELECT INFORMATION_SCHEMA.TABLES
# 4 0x31DE4C0DBC50DA30 0.0492 4.9% 1 0.0492 0.00 SELECT sakila.film_actor
# 5 0x6587F7103124EF13 0.0477 4.8% 4 0.0119 0.03 SELECT INFORMATION_SCHEMA.ROUTINES
# 6 0x1130DFE666B5F2AA 0.0434 4.3% 1 0.0434 0.00 SELECT sakila.rental
# 7 0x18B275D7FFB41810 0.0428 4.3% 1 0.0428 0.00 SELECT
# 8 0xA46100310F18DEB9 0.0396 4.0% 4 0.0099 0.02 SELECT INFORMATION_SCHEMA.SCHEMATA
# 9 0xACB921BD6A67D19F 0.0383 3.8% 1 0.0383 0.00 SELECT sakila.film_text
# 10 0xF2E9C9BDE150321B 0.0322 3.2% 1 0.0322 0.00 SET
# 11 0xE2F7D83651089289 0.0308 3.1% 1 0.0308 0.00 SELECT
# 12 0x6498E5CBE1B003AB 0.0291 2.9% 1 0.0291 0.00 SET
# 13 0x26D1F8747AD5C7A2 0.0148 1.5% 1 0.0148 0.00 SELECT sakila.payment
# 14 0xB53625A7FA91320B 0.0114 1.1% 1 0.0114 0.00 SELECT sakila.inventory
# MISC 0xMISC 0.0391 3.9% 88 0.0004 0.0 <25 ITEMS>
...
会发现有很多统计信息提供!非常方便。
如果通过日志发现问题?
查询次数多,查询时间长的sql
IO大的sql,查询数量多于输出数量的sql
未命中索引的sql
以上是关于使用pt-query-digest进行日志分析的主要内容,如果未能解决你的问题,请参考以下文章