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

Percona Toolkit使用之pt-summary

     pt-summary的功能是優雅地彙總系統資訊。

     用法如下:

pt-summary

     pt-summary方便地彙總伺服器的狀態和配置。它並不是一個調優工具或者診斷工具。它生成一個易於diff以及可以不丟失格式貼上進Email的報告。該工具在很多型別的Unix系統上執行良好。

     pt-summary執行大量命令去檢查系統狀態和配置,儲存輸出到臨時目錄檔案,然後在這些結果上執行Unix命令來優雅地格式化。以特權使用者執行時它工作得最好,當然也可以在沒有特權時執行,不過非root使用者可能無法生成某些輸出。

     該工具的很多輸出都刻意舍入來展示其量級大小而不是具體細節。這稱為“fuzzy-rounding”。該設計思想為一個特定的計數是918還是921並沒有關係;如此小的差異是微不足道的,只會讓輸出結果難於同其他伺服器作比較。fuzzy-rounding隨著輸入的增長會舍入更大的增量。它剛開始舍入到最近的5,然後是最近的10,最近的25,然後以10倍大小的因數重複(50,100,250),隨著輸入的增長,以此類推。

     以下是一個生成自CentOS虛擬機器的簡單報告,以註釋分割成段落。在終端作為手冊頁查閱該文件時,為了明晰,一些長行被重新格式化。

     該段展示當前日期和時間,以及伺服器和作業系統的概覽。

# Percona Toolkit System Summary Report ######################
        Date | 2012-03-30 00:58:07 UTC (local TZ: EDT -0400)
    Hostname | localhost.localdomain
      Uptime | 20:58:06 up 1 day, 20 min, 1 user,
               load average: 0.14, 0.18, 0.18
      System | innotek GmbH; VirtualBox; v1.2 ()
 Service Tag | 0
    Platform | Linux
     Release | CentOS release 5.5 (Final)
      Kernel | 2.6.18-194.el5
Architecture | CPU = 32-bit, OS = 32-bit
   Threading | NPTL 2.5
    Compiler | GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-48).
     SELinux | Enforcing
 Virtualized | VirtualBox

     該段提取自/proc/cpuinfo

# Processor ##################################################
  Processors | physical = 1, cores = 0, virtual = 1, hyperthreading = no
      Speeds | 1x2510.626
      Models | 1xIntel(R) Core(TM) i5-2400S CPU @ 2.50GHz
      Caches | 1x6144 KB

     記憶體資訊。生成自free、ps、sysctl以及dmidecode。

# Memory #####################################################
       Total | 503.2M
        Free | 29.0M
        Used | physical = 474.2M, swap allocated = 1.0M,
               swap used = 16.0k, virtual = 474.3M
     Buffers | 33.9M
      Caches | 262.6M
       Dirty | 396 kB
     UsedRSS | 201.9M
  Swappiness | 60
 DirtyPolicy | 40, 10
 Locator  Size  Speed    Form Factor  Type    Type Detail
 =======  ====  =====    ===========  ====    ===========

     掛載檔案系統。生成自mount和df。

# Mounted Filesystems ########################################
  Filesystem                       Size Used Type  Opts Mountpoint
  /dev/mapper/VolGroup00-LogVol00   15G  17% ext3  rw   /
  /dev/sda1                         99M  13% ext3  rw   /boot
  tmpfs                            252M   0% tmpfs rw   /dev/shm

     磁碟排程資訊。提取自/sys。

# Disk Schedulers And Queue Size #############################
        dm-0 | UNREADABLE
        dm-1 | UNREADABLE
         hdc | [cfq] 128
         md0 | UNREADABLE
         sda | [cfq] 128

     磁碟分割槽資訊。生成自fdisk -l。

# Disk Partioning ############################################
Device       Type      Start        End               Size
============ ==== ========== ========== ==================
/dev/sda     Disk                              17179869184
/dev/sda1    Part          1         13           98703360
/dev/sda2    Part         14       2088        17059230720

     核心索引節點資訊。分別提取自/proc/sys/fs目錄下同名檔案。

# LVM Volumes ################################################
LV       VG         Attr   LSize   Origin Snap% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao 269.00G
LogVol01 VolGroup00 -wi-ao   9.75G

     RAID控制器。生成自lvs。

# RAID Controller ############################################
  Controller | No RAID controller detected

     網路配置。生成自lspci和sysctl。

# Network Config #############################################
  Controller | Intel Corporation 82540EM Gigabit Ethernet Controller
 FIN Timeout | 60
  Port Range | 61000

     網路介面統計。生成自ip -s link。

# Interface Statistics #######################################
interface rx_bytes rx_packets rx_errors tx_bytes tx_packets tx_errors
========= ======== ========== ========= ======== ========== =========
lo        60000000      12500         0 60000000      12500         0
eth0      15000000      80000         0  1500000      10000         0
sit0             0          0         0        0          0         0

     網路連線彙總。生成自netstat。

# Network Connections ########################################
  Connections from remote IP addresses
    127.0.0.1           2
  Connections to local IP addresses
    127.0.0.1           2
  Connections to top 10 local ports
    38346               1
    60875               1
  States of connections
    ESTABLISHED         5
    LISTEN              8

     top前幾行。

# Top Processes ##############################################
  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root  15   0  2072  628  540 S  0.0  0.1   0:02.55 init
    2 root  RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0
    3 root  34  19     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/0
    4 root  RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    5 root  10  -5     0    0    0 S  0.0  0.0   0:00.97 events/0
    6 root  10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper
    7 root  10  -5     0    0    0 S  0.0  0.0   0:00.00 kthread
   10 root  10  -5     0    0    0 S  0.0  0.0   0:00.13 kblockd/0
   11 root  20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid
# Notable Processes ##########################################
  PID    OOM    COMMAND
 2028    +0    sshd

     裁剪後的vmstat 1 5。

# Simplified and fuzzy rounded vmstat (wait please) ##########
  procs  ---swap-- -----io---- ---system---- --------cpu--------
   r  b    si   so    bi    bo     ir     cs  us  sy  il  wa  st
   2  0     0    0     3    15     30    125   0   0  99   0   0
   0  0     0    0     0     0   1250    800   6  10  84   0   0
   0  0     0    0     0     0   1000    125   0   0 100   0   0
   0  0     0    0     0     0   1000    125   0   0 100   0   0
   0  0     0    0     0   450   1000    125   0   1  88  11   0
# The End ####################################################

     以下為個人本地環境(Ubuntu virtual machine)的測試資料。出於簡潔省略了一些輸出。

[email protected]:~# pt-summary
# Percona Toolkit System Summary Report ######################
        Date | 2018-05-04 11:55:10 UTC (local TZ: CST +0800)
    Hostname | ubuntu
      Uptime |  2:08,  3 users,  load average: 0.30, 0.32, 0.28
      System | VMware, Inc.; VMware Virtual Platform; vNone (Other)
 Service Tag | VMware-56 4d 7d 7a cd bc ab bd-5d cc e8 c9 6c b5 aa 8c
    Platform | Linux
     Release | Ubuntu 16.04.4 LTS (xenial)
      Kernel | 4.4.0-119-generic
Architecture | CPU = 64-bit, OS = 64-bit
   Threading | NPTL 2.23
     SELinux | No SELinux detected
 Virtualized | VMWare
# Processor ##################################################
  Processors | physical = 2, cores = 2, virtual = 2, hyperthreading = no
      Speeds | 2x2494.280
      Models | 2xIntel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
      Caches | 2x6144 KB
# Memory #####################################################
       Total | 1.9G
        Free | 71.5M
        Used | physical = 1.2G, swap allocated = 4.0G, swap used = 126.1M, virtual = 1.3G
      Shared | 30.6M
     Buffers | 687.3M
      Caches | 524.8M
       Dirty | 428 kB
     UsedRSS | 1.8G
  Swappiness | 60
 DirtyPolicy | 20, 10
 DirtyStatus | 0, 0
  Locator   Size     Speed             Form Factor   Type          Type Detail
  ========= ======== ================= ============= ============= ===========
  RAM slot #0 2048 MB  Unknown           DIMM          DRAM          EDO     
  NVD #0    {EMPTY}  Unknown           DIMM          Other         Unknown 
  
    ……………………………………………………………………………………omitted……………………………………………………………………………………
  
  RAM slot #11 {EMPTY}  Unknown           DIMM          DRAM          Unknown 

    ……………………………………………………………………………………omitted……………………………………………………………………………………
  
# Mounted Filesystems ########################################
  Filesystem  Size Used Type     Opts                                                             Mountpoint
  /dev/sda1    21G  82% ext4     rw,relatime,errors=remount-ro,data=ordered                       /
  tmpfs       199M   0% tmpfs    rw,nosuid,nodev                                                  /run/user/0
  tmpfs       199M   0% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /run/user/0
  tmpfs       199M   0% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /run/user/0
  tmpfs       199M   0% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /run/user/0
  tmpfs       199M   0% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /run/user/0
  tmpfs       199M   0% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /run/user/0
  tmpfs       199M   4% tmpfs    rw,nosuid,nodev                                                  /run
  tmpfs       199M   4% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /run
  tmpfs       199M   4% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /run
  tmpfs       199M   4% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /run
  tmpfs       199M   4% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /run
  tmpfs       199M   4% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /run
  tmpfs       199M   1% tmpfs    rw,nosuid,nodev                                                  /run/user/1000
  tmpfs       199M   1% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /run/user/1000
  tmpfs       199M   1% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /run/user/1000
  tmpfs       199M   1% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /run/user/1000
  tmpfs       199M   1% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /run/user/1000
  tmpfs       199M   1% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /run/user/1000
  tmpfs       5.0M   1% tmpfs    rw,nosuid,nodev                                                  /run/lock
  tmpfs       5.0M   1% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /run/lock
  tmpfs       5.0M   1% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /run/lock
  tmpfs       5.0M   1% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /run/lock
  tmpfs       5.0M   1% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /run/lock
  tmpfs       5.0M   1% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /run/lock
  tmpfs       992M   0% tmpfs    rw,nosuid,nodev                                                  /sys/fs/cgroup
  tmpfs       992M   0% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /sys/fs/cgroup
  tmpfs       992M   0% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /sys/fs/cgroup
  tmpfs       992M   0% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /sys/fs/cgroup
  tmpfs       992M   0% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /sys/fs/cgroup
  tmpfs       992M   0% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /sys/fs/cgroup
  tmpfs       992M   2% tmpfs    rw,nosuid,nodev                                                  /dev/shm
  tmpfs       992M   2% tmpfs    rw,nosuid,nodev,noexec,relatime,size=5120k                       /dev/shm
  tmpfs       992M   2% tmpfs    rw,nosuid,noexec,relatime,size=202988k,mode=755                  /dev/shm
  tmpfs       992M   2% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700                   /dev/shm
  tmpfs       992M   2% tmpfs    rw,nosuid,nodev,relatime,size=202988k,mode=700,uid=1000,gid=1000 /dev/shm
  tmpfs       992M   2% tmpfs    ro,nosuid,nodev,noexec,mode=755                                  /dev/shm
  udev        971M   0% devtmpfs rw,nosuid,relatime,size=993960k,nr_inodes=248490,mode=755        /dev
# Disk Schedulers And Queue Size #############################
         sda | [deadline] 128
         sr0 | [deadline] 128
# Disk Partioning ############################################
Device       Type      Start        End               Size
============ ==== ========== ========== ==================
/dev/sda     Disk                              26843545600
/dev/sda1    Part       2048   44040191                  0
/dev/sda2    Part   44042238   52426751                  0
/dev/sda5    Part   44042240   52426751                  0
# Kernel Inode State #########################################
dentry-state | 27242	12085	45	0	0	0
     file-nr | 8640	0	197654
    inode-nr | 39867	13627
# LVM Volumes ################################################
Unable to collect information
# LVM Volume Groups ##########################################
Unable to collect information
# RAID Controller ############################################
  Controller | No RAID controller detected
# Network Config #############################################
  Controller | Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
 FIN Timeout | 60
  Port Range | 60999
# Interface Statistics #######################################
  interface  rx_bytes rx_packets  rx_errors   tx_bytes tx_packets  tx_errors
  ========= ========= ========== ========== ========== ========== ==========
  lo           100000       1000          0     100000       1000          0
  ens33     700000000     500000          0   12500000     150000          0
# Network Devices ############################################
  Device    Speed     Duplex
  ========= ========= =========
  ens33      1000Mb/s   Full      
# Network Connections ########################################
  Connections from remote IP addresses

    ……………………………………………………………………………………omitted……………………………………………………………………………………
  
  Connections to local IP addresses
  
    ……………………………………………………………………………………omitted……………………………………………………………………………………
	
  Connections to top 10 local ports
    22                  2
    40952               1
    43808               1
    45808               1
    46468               1
    53362               1
    57576               1
  States of connections
    CLOSE_WAIT          4
    ESTABLISHED         4
    LISTEN             10
# Top Processes ##############################################
   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  3292 root      20   0 2601232 164840  61636 S  12.5  8.1  20:16.60 netease-c+
     1 root      20   0  119836   4736   3260 S   0.0  0.2   0:02.42 systemd
     2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd
     3 root      20   0       0      0      0 S   0.0  0.0   0:00.24 ksoftirqd+
     5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0+
     7 root      20   0       0      0      0 S   0.0  0.0   0:06.58 rcu_sched
     8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh
     9 root      rt   0       0      0      0 S   0.0  0.0   0:00.03 migration+
    10 root      rt   0       0      0      0 S   0.0  0.0   0:00.04 watchdog/0
# Notable Processes ##########################################
  PID    OOM    COMMAND
 1008    -17    sshd
# Simplified and fuzzy rounded vmstat (wait please) ##########
  procs  ---swap-- -----io---- ---system---- --------cpu--------
   r  b    si   so    bi    bo     ir     cs  us  sy  il  wa  st
   1  0     0    9   150   100    500   1000   4   5  91   0   0
   3  0     0    0   100     0   1500   4000   5  12  84   0   0
   0  0     0    0   125     0    800   1750   5   4  91   0   0
   0  0     0    0     0     0    800   1750   5   4  92   0   0
   0  0     0    0     0   175    800   1750   2   6  91   0   0
# Memory mamagement ##########################################
Transparent huge pages are enabled.
# The End ####################################################
[email protected]:~# 

     參考: