MySQL監控利器-Innotop

Innotop是一款十分強大的MySQL監控工具,用perl所寫,經過文本模式展現MysQL服務器和Innodb的運行情況。mysql

 

安裝innotopgit

下載地址:https://github.com/innotop/innotopgithub

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

注意:網上提供的下載地址是http://code.google.com/p/innotop/,但這個是原先的維護地址,該項目現已遷移到Github上,並且,innotop-1.9.0.tar.gz這個版本也測試了下(google code上面的最新版本是1.9.1),不少功能都沒法使用,可能與MySQL的版本有關,建議仍是直接從Github上下載。vim

# unzip innotop-master.zipcentos

# 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包。socket

# 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 <options> <innodb-status-file>

  --[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服務器

有兩種方式:

1、直接在innotop交互式界面中添加,步驟以下:

# innotop

進入到交互式界面後,點擊@鍵,會進入到鏈接配置界面

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

說明以下:

Choose connections for this mode:選擇鏈接,若是鏈接不存在,則手動建立。因此下面會有提示「There is no connection called 'master26',create it?:」。

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

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

對於該種方法,簡單,在監控機器較少的狀況下,比較適用,但該方法的弊端在於一旦退出innotop,全部的配置信息都會丟失,從新進入,需從新配置。

因此,推薦的方法以下。

2、利用配置文件

# 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

顧名思義,就是講服務器進行分組,這種信息展現的粒度就不在是服務器,而是整個組了。

一樣有兩種方式添加:

1、直接在innotop交互式界面中添加

使用「#」鍵,首先建立組的名字,而後添加服務器,以下所示:

2、編輯配置文件

[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功能仍是及其強大的,你們慢慢琢磨吧~

相關文章
相關標籤/搜索