MySQL監控利器-Innotop

luashin發表於2016-01-06

Innotop是一款十分強大的MySQL監控工具,用perl所寫,透過文字模式展示MysQL伺服器和Innodb的執行狀況。

安裝innotop

下載地址:

Github上提供兩種版本,一種是開發版(innotop-master),一種是穩定版(innotop-gtid)。在這裡,我們使用的是開發版。

注意: 網上提供的下載地址是 ,但這個是原先的維護地址,該專案現已遷移到Github上,而且,innotop-1.9.0.tar.gz這個版本也測試了下(google code上面的最新版本是1.9.1),很多功能都無法使用,可能與MySQL的版本有關,建議還是直接從Github上下載。

# unzip innotop-master.zip

# cd innotop-master

# perl Makefile.PL

Checking if your kit is complete...
Looks good
Warning: prerequisite Term::ReadKey 2.1 not found.
Writing Makefile for innotop

報以上錯誤,缺少ReadKey包。

# yum search ReadKey   --注意:基本上缺失的Perl Module都可以通常yum獲取

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
================================================= N/S matched: ReadKey ==================================================
perl-TermReadKey.x86_64 : A perl module for simple terminal control

  Name and summary matches only, use "search all" for everything.

# yum install -y perl-TermReadKey

# perl Makefile.PL

Writing Makefile for innotop

# make install

cp innotop blib/script/innotop
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/innotop
Manifying blib/man1/innotop.1 Installing /usr/local/share/man/man1/innotop.1 Installing /usr/local/bin/innotop
Appending installation info to /usr/lib64/perl5/perllocal.pod

如何使用Innotop

首先我們透過innotop --help檢視其常見的啟動引數

# innotop --help Usage: innotop  

  --[no]color   -C   Use terminal coloring (default)
  --config      -c   Config file to read --count            Number of updates before exiting
  --delay       -d   Delay between updates in seconds
  --help             Show this help message
  --host        -h   Connect to host
  --[no]inc     -i   Measure incremental differences
  --mode        -m Operating mode to start in
  --nonint      -n   Non-interactive, output tab-separated fields
  --password    -p   Password to use for connection
  --port        -P   Port number to use for connection
  --skipcentral -s Skip reading the central configuration file
  --socket -S   MySQL socket to use for connection
  --spark            Length of status sparkline (default 10)
  --timestamp   -t   Print timestamp in -n mode (1: per iter; 2: per line)
  --user        -u   User for login if not current user
  --version          Output version information and exit --write -w   Write running configuration into home directory if no config files were loaded

其中:

-d:多久時間更新一次

-h:連線的主機名

-p:連線的埠

-S:socket的位置

-u:連線的使用者

熟悉MysQL的童鞋不難理解。

登入進來後,預設是Dashboard。Innotop支援多種模式,Dashboard只是其中一種模式。透過“?”鍵我們可以檢視所有模式

透過上述字母可切換到不同的狀態下。

如何檢視innotop的文件

1. # man innotop

2. # perldoc innotop

如何監控多個MySQL伺服器

有兩種方式:

一、直接在innotop互動式介面中新增,步驟如下:

# innotop

進入到互動式介面後,點選@鍵,會進入到連線配置介面

下面開始填寫,主要有以下幾項:

說明如下:

Choose connections for this mode:選擇連線,如果連線不存在,則手動建立。所以下面會有提示“There is no connection called 'master26',create it?:”。

填寫y,然後回車,會提示填寫DSN string,按格式來即可。

其中在Enter password這一項需要注意,你輸入密碼的時候游標沒有動,但實際上它是有輸入,輸入完畢,直接回車即可。

對於該種方法,簡單,在監控機器較少的情況下,比較適用,但該方法的弊端在於一旦退出innotop,所有的配置資訊都會丟失,重新進入,需重新配置。

所以,推薦的方法如下。

二、利用配置檔案

# innotop --write,進入互動式介面後退出。會在當前目錄下生成一個.innotop/innotop.conf

# ls .innotop/ innotop.conf  plugins

# vim .innotop/innotop.conf

該配置檔案中有關連線的配置資訊,預設有一個localhost。

[connections] localhost=user= have_user= have_pass= dsn=DBI:mysql:;host=localhost;mysql_read_default_group=client savepass= dl_table=test.innotop_dl [/connections] 

當然,這個對我們編輯自己的配置資訊沒有多大用處,可以刪除掉。

在此,可根據第一種方式新增一個connection資訊,然後根據該資訊進行相應的編輯。

以第一種方式中的master26為例,新增後,innotop.conf中的資訊如下:

[connections] localhost=user= have_user= have_pass= dsn=DBI:mysql:;host=localhost;mysql_read_default_group=client savepass= dl_table=test.innotop_dl master26=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.26;port=3306 savepass=1 [/connections] 

根據實際生產的需求,編輯innotop.conf檔案。

[connections] master26=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.26;port=3306 savepass=1 slave25=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.25;port=3306 savepass=1 slave22=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.22;port=3306 savepass=1 [/connections] 

啟動innotop,預設監控的是master26的資訊。

可透過“n”或“@”選擇相應的伺服器。

好雖好,但不夠直觀,我們希望本例中三個伺服器的資訊能顯示在一個螢幕裡,這樣就不需要進行來回的切換,更直觀。這裡,就需要用到SERVER GROUPS的功能。

SERVER GROUPS

顧名思義,就是講伺服器進行分組,這種資訊展示的粒度就不在是伺服器,而是整個組了。

同樣有兩種方式新增:

一、直接在innotop互動式介面中新增

使用“#”鍵,首先建立組的名字,然後新增伺服器,如下所示:

二、編輯配置檔案

[server_groups] master-slave=master26 slave22 slave25 [/server_groups] 

下面,我們來看看叢集顯示的效果

對於監控主從叢集的狀況,完全夠用。

注意: 在innotop互動式介面中配置完畢後,需退出innotop,再進入,不然就不會顯示CXN列。

總結:

1. 可能有人有疑慮,將密碼儲存到配置檔案中,是否不安全,尤其是在生產環境下。其實,密碼也可以不儲存在配置檔案中,配置如下:

[connections] server144=user=root have_user=1 have_pass=1 dsn=DBI:mysql:;host=192.168.244.144;port=3306 savepass= dl_table= [/connections] 

如果是在innotop互動式介面中新增,則最後一步Save password in plain text in the config file?: 寫“n”即可。

2. 除了上述功能,innotop還是蠻強大的。譬如在M模式,即Replication Status下,可透過“o”鍵給伺服器傳送命令。如下所示:

Anyway,Innotop功能還是及其強大的,大家慢慢琢磨吧~

參考:

https://www.percona.com/blog/2013/10/14/innotop-real-time-advanced-investigation-tool-mysql/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9034054/viewspace-1972884/,如需轉載,請註明出處,否則將追究法律責任。

相關文章