1. 程式人生 > >Percona Toolkit使用之pt-mysql-summary

Percona Toolkit使用之pt-mysql-summary

     pt-mysql-summary的功能是以優雅的形式彙總MySQL伺服器資訊。

     用法如下:

pt-mysql-summary [OPTIONS]

     pt-mysql-summary方便地彙總出MySQL資料庫伺服器的狀態和配置,使你可以一目瞭然地獲得這些資訊。這不是一個調優或者診斷的工具。它會生成一個報告,可以很容易地diff或者不丟失格式地複製到Email裡。它應該可以很好地運行於任何現代Unix系統。

     pt-mysql-summary通過連線到MySQL資料庫伺服器然後執行狀態和配置資訊查詢的方式執行。它將這些零碎資訊儲存到臨時目錄的檔案中,然後藉助awk和其他指令碼語言來整齊格式化。

     要使用它,只需要執行即可。作為可選可以加雙“ - ”後接你用來連線MySQL時相同的命令列選項,如下示例:

pt-mysql-summary --user=root

     該工具與執行它的伺服器進行最低限度地呼叫。它假定你執行它的伺服器和要進行檢查的伺服器是同一個,因此,它假定可以找到配置檔案,例如my.cnf。然而如果不是這種情況,它可能優雅地折損。請注意,它的輸出並沒有指出哪些資訊來自於MySQL資料庫;哪些資訊來自於作業系統主機。所以如果你在一臺伺服器上執行該工具,然後連線訪問另一臺伺服器上的MySQL,就有可能產生混亂的輸出。

     該工具的很多輸出值都故意作了近似舍入處理以展示它們的量級而不是精確的細節。這稱為“ fuzzy-rounding ”。該設計認為一臺伺服器是918QPS還是921QPS並不打緊,如此小的差異微不足道,而只會使得輸出同其他伺服器作比較變得困難。隨著輸入的增大,fuzzy-rounding也以更大的量級近似舍入。剛開始它舍入到最近的5,然後是最近的10,最近的25,然後以一個10倍大的因數重複(50,100,250),以此類推,隨著輸入的增大。以下是該工具產生的報告的一個示例。

     前兩部分展示該報告生成自哪臺伺服器以及有哪些MySQL例項執行在該伺服器上。這取自ps的輸出。雖然並不是總能檢查到所有的例項和引數,但往往執行效果還是不錯的。

# Percona Toolkit MySQL Summary Report #######################
              System time | 2012-03-30 18:46:05 UTC
                            (local TZ: EDT -0400)
# Instances ##################################################
  Port  Data Directory             Nice OOM Socket
  ===== ========================== ==== === ======
  12345 /tmp/12345/data            0    0   /tmp/12345.sock
  12346 /tmp/12346/data            0    0   /tmp/12346.sock
  12347 /tmp/12347/data            0    0   /tmp/12347.sock

     往下是單個MySQL例項的報告。該部分是MySQL例項的快速彙總。“ Time ”值生成自MySQL伺服器,不同於之前部分列印的系統日期和時間,可以以此判斷資料庫時間和作業系統時間是否匹配。

# Report On Port 12345 #######################################
                     User | [email protected]%
                     Time | 2012-03-30 14:46:05 (EDT)
                 Hostname | localhost.localdomain
                  Version | 5.5.20-log MySQL Community Server (GPL)
                 Built On | linux2.6 i686
                  Started | 2012-03-28 23:33 (up 1+15:12:09)
                Databases | 4
                  Datadir | /tmp/12345/data/
                Processes | 2 connected, 2 running
              Replication | Is not a slave, has 1 slaves connected
                  Pidfile | /tmp/12345/data/12345.pid (exists)

     接下來部分是“ SHOW PROCESSLIST ”輸出的彙總。

# Processlist ################################################

  Command                        COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  Binlog Dump                           1       1    150000    150000
  Query                                 1       1         0         0

  User                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  msandbox                              2       2    150000    150000

  Host                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  localhost                             2       2    150000    150000

  db                             COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  NULL                                  2       2    150000    150000

  State                          COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  Master has sent all binlog to         1       1    150000    150000
  NULL                                  1       1         0         0

     大約間隔10秒的兩份“ SHOW GLOBAL STATUS ”快照計算而來的select計數。

# Status Counters (Wait 10 Seconds) ##########################
Variable                            Per day  Per second     10 secs
Binlog_cache_disk_use                     4
Binlog_cache_use                         80
Bytes_received                     15000000         175         200
Bytes_sent                         15000000         175        2000
Com_admin_commands                        1
...................(many lines omitted)............................
Threads_created                          40                       1
Uptime                                90000           1           1

     表快取大小。

# Table cache ################################################
                     Size | 400
                    Usage | 15%

     Percona Server特性彙總部分。標準版本MySQL因為沒有啟用,會顯示為不支援。

# Key Percona Server features ################################
      Table & Index Stats | Not Supported
     Multiple I/O Threads | Enabled
     Corruption Resilient | Not Supported
      Durable Replication | Not Supported
     Import InnoDB Tables | Not Supported
     Fast Server Restarts | Not Supported
         Enhanced Logging | Not Supported
     Replica Perf Logging | Not Supported
      Response Time Hist. | Not Supported
          Smooth Flushing | Not Supported
      HandlerSocket NoSQL | Not Supported
           Fast Hash UDFs | Unknown

     外掛彙總部分。

# Plugins ####################################################
       InnoDB compression | ACTIVE

     查詢緩衝部分。

# Query cache ################################################
         query_cache_type | ON
                     Size | 0.0
                    Usage | 0%
         HitToInsertRatio | 0%

     schema部分。生成自“ mysqldump --no-data ”而不是查詢“ INFORMATION_SCHEMA ”以避免對繁忙的伺服器造成影響。

# Schema #####################################################

  Database           Tables Views SPs Trigs Funcs   FKs Partn
  mysql                  24
  performance_schema     17
  sakila                 16     7   3     6     3    22

  Database           MyISAM CSV PERFORMANCE_SCHEMA InnoDB
  mysql                  22   2
  performance_schema                            17
  sakila                  8                            15

  Database           BTREE FULLTEXT
  mysql                 31
  performance_schema
  sakila                63        1

                       c   t   s   e   l   d   i   t   m   v   s
                       h   i   e   n   o   a   n   i   e   a   m
                       a   m   t   u   n   t   t   n   d   r   a
                       r   e       m   g   e       y   i   c   l
                           s           b   t       i   u   h   l
                           t           l   i       n   m   a   i
                           a           o   m       t   t   r   n
                           m           b   e           e       t
                           p                           x
                                                       t
  Database           === === === === === === === === === === ===
  mysql               61  10   6  78   5   4  26   3   4   5   3
  performance_schema               5          16          33
  sakila               1  15   1   3       4   3  19      42  26

     特定技術使用情況部分。

# Noteworthy Technologies ####################################
       Full Text Indexing | Yes
         Geospatial Types | No
             Foreign Keys | Yes
             Partitioning | No
       InnoDB Compression | Yes
                      SSL | No
     Explicit LOCK TABLES | No
           Delayed Insert | No
          XA Transactions | No
              NDB Cluster | No
      Prepared Statements | No
 Prepared statement count | 0

     InnoDB儲存引擎重要配置引數部分。

# InnoDB #####################################################
                  Version | 1.1.8
         Buffer Pool Size | 16.0M
         Buffer Pool Fill | 100%
        Buffer Pool Dirty | 0%
           File Per Table | OFF
                Page Size | 16k
            Log File Size | 2 * 5.0M = 10.0M
          Log Buffer Size | 8M
             Flush Method |
      Flush Log At Commit | 1
               XA Support | ON
                Checksums | ON
              Doublewrite | ON
          R/W I/O Threads | 4 4
             I/O Capacity | 200
       Thread Concurrency | 0
      Concurrency Tickets | 500
       Commit Concurrency | 0
      Txn Isolation Level | REPEATABLE-READ
        Adaptive Flushing | ON
      Adaptive Checkpoint |
           Checkpoint Age | 0
             InnoDB Queue | 0 queries inside InnoDB, 0 queries in queue
       Oldest Transaction | 0 Seconds
         History List Len | 209
               Read Views | 1
         Undo Log Entries | 1 transactions, 1 total undo, 1 max undo
        Pending I/O Reads | 0 buf pool reads, 0 normal AIO,
                            0 ibuf AIO, 0 preads
       Pending I/O Writes | 0 buf pool (0 LRU, 0 flush list, 0 page);
                            0 AIO, 0 sync, 0 log IO (0 log, 0 chkp);
                            0 pwrites
      Pending I/O Flushes | 0 buf pool, 0 log
       Transaction States | 1xnot started

     MyISAM儲存引擎key cache使用情況部分。

# MyISAM #####################################################
                Key Cache | 16.0M
                 Pct Used | 10%
                Unflushed | 0%

     連線使用者部分。生成自“ mysql ”系統庫。

# Security ###################################################
                    Users | 2 users, 0 anon, 0 w/o pw, 0 old pw
            Old Passwords | OFF

     二進位制日誌部分。

# Binary Logging #############################################
                  Binlogs | 1
               Zero-Sized | 0
               Total Size | 21.8M
            binlog_format | STATEMENT
         expire_logs_days | 0
              sync_binlog | 0
                server_id | 12345
             binlog_do_db |
         binlog_ignore_db |

     伺服器配置引數部分。

# Noteworthy Variables #######################################
     Auto-Inc Incr/Offset | 1/1
   default_storage_engine | InnoDB
               flush_time | 0
             init_connect |
                init_file |
                 sql_mode |
         join_buffer_size | 128k
         sort_buffer_size | 2M
         read_buffer_size | 128k
     read_rnd_buffer_size | 256k
       bulk_insert_buffer | 0.00
      max_heap_table_size | 16M
           tmp_table_size | 16M
       max_allowed_packet | 1M
             thread_stack | 192k
                      log | OFF
                log_error | /tmp/12345/data/mysqld.log
             log_warnings | 1
         log_slow_queries | ON
log_queries_not_using_indexes | OFF
        log_slave_updates | ON

     美化版的my.cnf配置檔案部分。

# Configuration File #########################################
              Config File | /tmp/12345/my.sandbox.cnf
[client]
user                                = msandbox
password                            = msandbox
port                                = 12345
socket                              = /tmp/12345/mysql_sandbox12345.sock
[mysqld]
port                                = 12345
socket                              = /tmp/12345/mysql_sandbox12345.sock
pid-file                            = /tmp/12345/data/mysql_sandbox12345.pid
basedir                             = /home/baron/5.5.20
datadir                             = /tmp/12345/data
key_buffer_size                     = 16M
innodb_buffer_pool_size             = 16M
innodb_data_home_dir                = /tmp/12345/data
innodb_log_group_home_dir           = /tmp/12345/data
innodb_data_file_path               = ibdata1:10M:autoextend
innodb_log_file_size                = 5M
log-bin                             = mysql-bin
relay_log                           = mysql-relay-bin
log_slave_updates
server-id                           = 12345
report-host                         = 127.0.0.1
report-port                         = 12345
log-error                           = mysqld.log
innodb_lock_wait_timeout            = 3
# The End ####################################################

     以下為個人本地環境的測試資料。

[email protected]:~# pt-mysql-summary --host=192.168.112.129 --port=3306 --user=root --password=123456 --all-databases
mysql: [Warning] Using a password on the command line interface can be insecure.
# Percona Toolkit MySQL Summary Report #######################
              System time | 2018-04-07 19:26:17 UTC (local TZ: CST +0800)
# Instances ##################################################
  Port  Data Directory             Nice OOM Socket
  ===== ========================== ==== === ======
        /usr/local/mysql/data      0    0   /tmp/mysql.sock
# MySQL Executable ###########################################
       Path to executable | /usr/local/mysql/bin/mysqld
              Has symbols | Yes
# Slave Hosts ################################################
*************************** 1. row ***************************
 Server_id: 1025
      Host: 192.168.136.128
      User: root
  Password: 123456
      Port: 3306
 Master_id: 1024
Slave_UUID: b5fe6950-6c2a-11e7-a60a-000c29c6454d
# Report On Port 3306 ########################################
                     User | [email protected]%
                     Time | 2018-04-08 03:26:16 (CST)
                 Hostname | ubuntu
                  Version | 5.7.18-log Source distribution
                 Built On | Linux x86_64
                  Started | 2018-04-07 20:30 (up 0+06:56:11)
                Databases | 5
                  Datadir | /usr/local/mysql/data/
                Processes | 2 connected, 2 running
              Replication | Is not a slave, has 1 slaves connected
                  Pidfile | /usr/local/mysql/data/ubuntu.pid (exists)
# Processlist ################################################

  Command                        COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  Binlog Dump GTID                      1       1        50        50
  Query                                 1       1         0         0

  User                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  root                                  2       2        50        50

  Host                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  192.168.112.128                       1       1        50        50
  192.168.112.129                       1       1         0         0

  db                             COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  NULL                                  2       2        50        50

  State                          COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- ---------
  Master has sent all binlog to         1       1        50        50
  starting                              1       1         0         0

# Status Counters (Wait 10 Seconds) ##########################
Variable                                Per day  Per second     11 secs
Bytes_received                           100000           1        2000
Bytes_sent                              1250000          15       20000
...................(many lines omitted)............................
Table_open_cache_misses                     500                       3
Threads_created                               6                        
Uptime                                    90000           1           1
# Table cache ################################################
                     Size | 2000
                    Usage | 7%
# Key Percona Server features ################################
      Table & Index Stats | Not Supported
     Multiple I/O Threads | Enabled
     Corruption Resilient | Not Supported
      Durable Replication | Not Supported
     Import InnoDB Tables | Not Supported
     Fast Server Restarts | Not Supported
         Enhanced Logging | Not Supported
     Replica Perf Logging | Disabled
      Response Time Hist. | Not Supported
          Smooth Flushing | Not Supported
      HandlerSocket NoSQL | Not Supported
           Fast Hash UDFs | Unknown
# Percona XtraDB Cluster #####################################
# Plugins ####################################################
       InnoDB compression | ACTIVE
# Query cache ################################################
         query_cache_type | OFF
                     Size | 1.0M
                    Usage | 1%
         HitToInsertRatio | 0%
# Schema #####################################################

  Database Tables Views SPs Trigs Funcs   FKs Partn
  mysql        31                                  
  player        5                           1      

  Database MyISAM InnoDB CSV
  mysql        10     19   2
  player               5    

  Database BTREE
  mysql       38
  player      12

             c   t   s   e   v   i   f   l   d   t   b   s   t   b   m   m   t
             h   i   e   n   a   n   l   o   a   i   i   m   e   l   e   e   i
             a   m   t   u   r   t   o   n   t   n   g   a   x   o   d   d   m
             r   e       m   c       a   g   e   y   i   l   t   b   i   i   e
                 s           h       t   b   t   i   n   l           u   u    
                 t           a           l   i   n   t   i           m   m    
                 a           r           o   m   t       n           t   b    
                 m                       b   e           t           e   l    
                 p                                                   x   o    
                                                                     t   b    
  Database === === === === === === === === === === === === === === === === ===
  mysql     61  15   6  62  18  42   3   5   4   6  23   4  26   5   2   2   2
  player                    16   6           3      11                        

# Noteworthy Technologies ####################################
       Full Text Indexing | No
         Geospatial Types | No
             Foreign Keys | Yes
             Partitioning | No
       InnoDB Compression | Yes
                      SSL | No
     Explicit LOCK TABLES | No
           Delayed Insert | No
          XA Transactions | No
              NDB Cluster | No
      Prepared Statements | No
 Prepared statement count | 0
# InnoDB #####################################################
                  Version | 5.7.18
         Buffer Pool Size | 128.0M
         Buffer Pool Fill | 4%
        Buffer Pool Dirty | 0%
           File Per Table | ON
                Page Size | 16k
            Log File Size | 2 * 48.0M = 96.0M
          Log Buffer Size | 16M
             Flush Method | 
      Flush Log At Commit | 1
               XA Support | ON
                Checksums | ON
              Doublewrite | ON
          R/W I/O Threads | 4 4
             I/O Capacity | 200
       Thread Concurrency | 0
      Concurrency Tickets | 5000
       Commit Concurrency | 0
      Txn Isolation Level | REPEATABLE-READ
        Adaptive Flushing | ON
      Adaptive Checkpoint | 
           Checkpoint Age | 9
             InnoDB Queue | 0 queries inside InnoDB, 0 queries in queue
       Oldest Transaction | 0 Seconds
         History List Len | 0
               Read Views | 0
         Undo Log Entries | 0 transactions, 0 total undo, 0 max undo
        Pending I/O Reads | 0 buf pool reads, 0 normal AIO, 0 ibuf AIO, 0 preads
       Pending I/O Writes | 0 buf pool (0 LRU, 0 flush list, 0 page); 0 AIO, 0 sync, 0 log IO (0 log, 0 chkp); 0 pwrites
      Pending I/O Flushes | 0 buf pool, 0 log
       Transaction States | 1xnot started
# MyISAM #####################################################
                Key Cache | 8.0M
                 Pct Used | 20%
                Unflushed | 0%
# Security ###################################################
                    Users | 2 users, 0 anon, 0 w/o pw, 0 old pw
            Old Passwords | 0
# Binary Logging #############################################
                  Binlogs | 28
               Zero-Sized | 0
               Total Size | 168.8k
            binlog_format | ROW
         expire_logs_days | 0
              sync_binlog | 1
                server_id | 1024
             binlog_do_db | 
         binlog_ignore_db | 
# Noteworthy Variables #######################################
     Auto-Inc Incr/Offset | 1/1
   default_storage_engine | InnoDB
               flush_time | 0
             init_connect | 
                init_file | 
                 sql_mode | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_S
UBSTITUTION         join_buffer_size | 256k
         sort_buffer_size | 256k
         read_buffer_size | 128k
     read_rnd_buffer_size | 256k
       bulk_insert_buffer | 0.00
      max_heap_table_size | 16M
           tmp_table_size | 16M
       max_allowed_packet | 4M
             thread_stack | 256k
                      log | 
                log_error | /usr/local/mysql/data/ubuntu.err
             log_warnings | 2
         log_slow_queries | 
log_queries_not_using_indexes | OFF
        log_slave_updates | ON
# Configuration File #########################################
              Config File | /etc/my.cnf

[client]
user                                = root
password                            = 123456
port                                = 3306
socket                              = /tmp/mysql.sock

[mysqld]
socket                              = /tmp/mysql.sock
basedir                             = /usr/local/mysql
datadir                             = /usr/local/mysql/data
sql_mode                            = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,N
O_ENGINE_SUBSTITUTIONinnodb_buffer_pool_instances        = 1 
slow_query_log                      = ON
long_query_time                     = 10
log_throttle_queries_not_using_indexes = 1
log_output                          = FILE
show-slave-auth-info
server-id                           = 1024
log-bin                             = master-bin
log-bin-index                       = master-bin.index
binlog_format                       = row 
binlog_rows_query_log_events        = ON
sync_binlog                         = 1 
innodb_support_xa                   = ON
innodb_flush_log_at_trx_commit      = 1
skip-slave-start
log_slave_updates                   = ON
relay_log_recovery                  = ON
gtid_mode                           = ON
enforce_gtid_consistency            = 1
# Memory management library ##################################
jemalloc is not enabled in MySQL config for process with ID 1846
# The End ####################################################

參考: