Home Database Mysql Tutorial pt-query-digest使用介绍

pt-query-digest使用介绍

Jun 07, 2016 pm 04:42 PM
introduce use

一、pt-query-digest参数介绍. pt-query-digest --user=anemometer --password=anemometerpass --review h=192.168.11.28,D=slow_query_log,t=global_query_review \ --history h=192.168.11.28,D=slow_query_log,t=global_query_review_history \ --no-repo

一、pt-query-digest参数介绍.

 pt-query-digest --user=anemometer --password=anemometerpass     --review h=192.168.11.28,D=slow_query_log,t=global_query_review  \
 --history h=192.168.11.28,D=slow_query_log,t=global_query_review_history  \
 --no-report --limit=0%  --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" \
 /usr/local/mariamysql/data/localhost-slow.log
 
Copy after login

–filter 对输入的慢查询按指定的字符串进行匹配过滤后再进行分析
–limit限制输出结果百分比或数量,默认值是20,即将最慢的20条语句输出,如果是50%则按总响应时间占比从大到小排序,输出到总和达到50%位置截止。
–host mysql服务器地址
–user mysql用户名
–password mysql用户密码
–history 将分析结果保存到表中,分析结果比较详细,下次再使用–history时,如果存在相同的语句,且查询所在的时间区间和历史表中的不同,则会记录到数据表中,可以通过查询同一CHECKSUM来比较某类型查询的历史变化。
–review 将分析结果保存到表中,这个分析只是对查询条件进行参数化,一个类型的查询一条记录,比较简单。当下次使用–review时,如果存在相同的语句分析,就不会记录到数据表中。
–output 分析结果输出类型,值可以是report(标准分析报告)、slowlog(Mysql slow log)、json、json-anon,一般使用report,以便于阅读。
–since 从什么时间开始分析,值为字符串,可以是指定的某个”yyyy-mm-dd [hh:mm:ss]”格式的时间点,也可以是简单的一个时间值:s(秒)、h(小时)、m(分钟)、d(天),如12h就表示从12小时前开始统计。
–until 截止时间,配合—since可以分析一段时间内的慢查询。

二、分析结果分析:

#pt-query-digest mysql-slow.log
--分析mysql-slow.log这个慢查询日志文件
Copy after login
# A software update is available:
#   * The current version for Percona::Toolkit is 2.2.9.
<strong>开始总的摘要信息</strong>
# 170ms user time, 10ms system time, 26.00M rss, 213.39M vsz
--此工具执行日志分析时的所用时间、内存资源(rss物理内存占用大小,vsz虚拟内存占用大小)
# Current date: Mon Jul 28 09:55:34 2014
--分析时的系统时间
# Hostname: lump.group.com
--进行分析的主机名,非记录日志的数据库服务器
# Files: mysql-slow.log
--分析的日志文件名称
# Overall: 5 total, 4 unique, 0.02 QPS, 0.04x concurrency ________________
--文件中总共的语句数量,唯一的语句数量(对语句进行了格式化),QPS,并发数
# Time range: 2014-07-28 09:50:30 to 09:54:50
--记录日志的时间范围
Copy after login
# Attribute          total     min     max     avg     95%  stddev  median
--total总计,min最小,max最大,avg平均,95%把所有值从小到大排列,位于95%的那个数
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec time            10s      1s      3s      2s      3s   753ms      1s
# Lock time          196us       0    79us    39us    76us    33us    42us
# Rows sent          1.40k       0     716     287  685.39  335.14    3.89
# Rows examine      15.32k       0  11.13k   3.06k  10.80k   4.02k   2.06k
# Rows affecte           0       0       0       0       0       0       0
# Bytes sent        72.42k      11  38.85k  14.48k  38.40k  17.57k  234.30
# Query size           807       6     342  161.40  329.68  146.53  112.70
Copy after login

–Exec time:语句执行时间
–Lock time:锁占有时间
–Rows sent:发送到客户端的行数
–Row examine:扫描的行数(SELECT语句)
–Row affecte:发送改变的行数(UPDATE, DELETE, INSERT语句)
–Bytes sent:发送多少bytes的查询结果集
–Query size:查询语句的字符数

查询分组统计结果

# Profile
# Rank Query ID           Response time Calls R/Call V/M   Item
# ==== ================== ============= ===== ====== ===== ===============
#    1 0x4A9CF4735A0490F2  3.1898 31.9%     1 3.1898  0.00 SELECT history_uint
#    2 0x2B0044BDE0960A2F  2.6991 27.0%     1 2.6991  0.00 SELECT history
#    3 0x813031B8BBC3B329  2.5755 25.7%     2 1.2877  0.00 COMMIT
#    4 0x469563A79E581DDB  1.5380 15.4%     1 1.5380  0.00 SELECT sessions
Copy after login

–Rank:分析的所有查询语句的排名,默认按查询时间降序排序,可以通过–order-by指定排序方式
–Query ID:查询语句的指纹,去掉了多余空格、和文本字符
–Response time:响应时间,占所有响应时间的百分比
–Calls:查询执行的次数
–R/Call:每次执行的平均响应时间
–V/M:响应时间Variance-to-mean的比率,参考:http://en.wikipedia.org/wiki/Index_of_dispersion
–Item:查询语句
–最后一行没有包括在报告中的查询合计统计信息,如使用了选项–limit和–outliers

每个独立查询语句的分析

# Query 1: 0 QPS, 0x concurrency, ID 0x4A9CF4735A0490F2 at byte 591 ______
--QPS:每秒查询数(queries per second)
--concurrency:该查询的近似并发值
--ID:16进制,查询语句的指纹,去掉了多余空格、和文本字符、转换成小写,使用--filter可以用来进行过滤(如:pt-query-digest mysql-slow.201407250000 --filter '$event->{fingerprint} && make_checksum($event->{fingerprint}) eq "0793E2F7F5EBE1B1"' > slow2.txt),必须移除0x
--at byte 289141:查询语句在日志文件中的偏移量(byte offset),不一定精确,根据偏移量在日志文件中查找语句(如tail -c +289141 mysql-slow.201407250000 |head)
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: all events occurred at 2014-07-28 09:51:02
# Attribute    pct   total     min     max     avg     95%  stddev  median
--95%:95th percentile,stddev:standard deviation
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         20       1
--pct在整个日志文件中,执行语句占用百分比(20%),总计执行了1次
# Exec time     31      3s      3s      3s      3s      3s       0      3s
# Lock time     40    79us    79us    79us    79us    79us       0    79us
# Rows sent     49     715     715     715     715     715       0     715
# Rows examine  13   2.09k   2.09k   2.09k   2.09k   2.09k       0   2.09k
# Rows affecte   0       0       0       0       0       0       0       0
# Bytes sent    45  33.31k  33.31k  33.31k  33.31k  33.31k       0  33.31k
# Query size    42     342     342     342     342     342       0     342
# String:
# Databases    zabbix
--数据库名
# Hosts
# Last errno   0
# Users        zabbix
--执行语句的用户名
# Query_time distribution
--查询的执行时间分布情况图,可以使用选项--report-histogram进行定义
#   1us
#  10us
# 100us
#   1ms
#  10ms
# 100ms
#    1s  ################################################################
#  10s+
# Tables
#    SHOW TABLE STATUS FROM `zabbix` LIKE 'history_uint'\G
--可以使用该语句查询表的统计信息,如大小
#    SHOW CREATE TABLE `zabbix`.`history_uint`\G
--可以使用该语句查看表的结构信息
# EXPLAIN /*!50100 PARTITIONS*/
SELECT itemid,round(1401* MOD(CAST(clock AS UNSIGNED)+79742,86400)/(86400),0) AS i,COUNT(*) AS count,AVG(value) AS avg,MIN(value) AS min,MAX(value) AS max,MAX(clock) AS clock FROM history_uint  WHERE itemid='30376' AND clock>='1406425858' AND clock
<p>参考:<br>
1、"pt-query-digest":http://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.html</p>
    <p class="copyright">
        本文出自:http://isadba.com, 原文地址:http://isadba.com/?p=651, 感谢原作者分享。
    </p>
    
    


Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use mdf and mds files How to use mdf and mds files Feb 19, 2024 pm 05:36 PM

How to use mdf files and mds files With the continuous advancement of computer technology, we can store and share data in a variety of ways. In the field of digital media, we often encounter some special file formats. In this article, we will discuss a common file format - mdf and mds files, and introduce how to use them. First, we need to understand the meaning of mdf files and mds files. mdf is the extension of the CD/DVD image file, and the mds file is the metadata file of the mdf file.

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone Feb 22, 2024 pm 05:19 PM

After long pressing the play button of the speaker, connect to wifi in the software and you can use it. Tutorial Applicable Model: Xiaomi 12 System: EMUI11.0 Version: Xiaoai Classmate 2.4.21 Analysis 1 First find the play button of the speaker, and press and hold to enter the network distribution mode. 2 Log in to your Xiaomi account in the Xiaoai Speaker software on your phone and click to add a new Xiaoai Speaker. 3. After entering the name and password of the wifi, you can call Xiao Ai to use it. Supplement: What functions does Xiaoai Speaker have? 1 Xiaoai Speaker has system functions, social functions, entertainment functions, knowledge functions, life functions, smart home, and training plans. Summary/Notes: The Xiao Ai App must be installed on your mobile phone in advance for easy connection and use.

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Mar 10, 2024 pm 04:34 PM

Apple rolled out the iOS 17.4 update on Tuesday, bringing a slew of new features and fixes to iPhones. The update includes new emojis, and EU users will also be able to download them from other app stores. In addition, the update also strengthens the control of iPhone security and introduces more "Stolen Device Protection" setting options to provide users with more choices and protection. "iOS17.3 introduces the "Stolen Device Protection" function for the first time, adding extra security to users' sensitive information. When the user is away from home and other familiar places, this function requires the user to enter biometric information for the first time, and after one hour You must enter information again to access and change certain data, such as changing your Apple ID password or turning off stolen device protection.

See all articles