percona_template_for_cacti監控映像增加對redis多執行個體監控的支援
percona的cacti模板還是挺帥氣的,但是對於redis、memercache等多執行個體而言,只能監控預設6379,或者一個其他連接埠(總之不能監控所有執行個體),這還是很可惜的,要實現監控一切可以監控的對象,就必須自訂模板,經過了半天的摸索,終於實現了,先來看一下帥氣的:
步驟:
1、下載percona模板,解壓,因之前用的時1.0.1版本的,所以還是在原版本的基礎上修改
wget http://www.percona.com/redir/downloads/percona-monitoring-plugins/1.0.1/percona-monitoring-plugins-1.0.1.tar.gz
2、在redis的預設範本設定檔的基礎上增加選項port2,使用者在建立redis監控映像時要求填寫redis連接埠號碼,不填的話就是預設的6379,ss_get_by_ssh.php指令碼通過port2選項串連指定連接埠的redis執行個體:
cd percona-monitoring-plugins-1.0.1/cacti/bin
? bin ./pmp-cacti-template \
> --script ../scripts/ss_get_by_ssh.php ../definitions/redis.def \
> --mpds port2 >../templates/cacti_host_template_percona_redis_server_ht_for_multi_instance.xml
建立模板指令碼的使用說明
? bin ./pmp-cacti-template --help
pmp-cacti-template generates a Cacti template from a definition file. For more
details, please use the --help option, or try 'perldoc pmp-cacti-template' for
complete documentation.
Usage: pmp-cacti-template <options> FILE
Options:
--cactiver Create templates for this Cacti version
--graph_height Height of generated graphs (default 120)
--graph_width Width of generated graphs (default 500)
--help Show this help message
--lint_check Complain about unused data found in the script
--mpds Comma-separated list of input method options to make
per-data-source
--name_prefix Template name prefix (default Percona)
--poll_interval Polling interval (default 300)
--script Command-line script to use (required)
--smallint Create templates for 32-bit MySQL
--version Output version information and exit
Options and values after processing arguments:
--cactiver (No value)
--graph_height 120
--graph_width 500
--help TRUE
--lint_check FALSE
--mpds
--name_prefix Percona
--poll_interval 300
--script (No value)
--smallint FALSE
--version FALSE
? bin
3、在cacti的web管理頁面匯入新建立的redis模板cacti_host_template_percona_redis_server_ht_for_multi_instance.xml
console->Import/Export->Import Templates->choose file->import
4、修改redis模板中映像的title,以便區分映像屬於那個執行個體,本例使用使用者在建立映像時輸入的連接埠號碼區分,在cacti中變數使用||引用
console->Templates->Graph Templates->search 'redis' and select a redis template->in Graph Template title->|host_description| - Redis Commands - |input_port2|->save
5、建立redis的監控映像,記得填寫連接埠號碼
6、如果在匯入新模板之前已經有對redis 6379的監控,這時映像顯示名字會不正常,如192.168.0.19_Redis19 - Redis Unsaved Changes - |input_port2|,而非192.168.0.19_Redis19 - Redis Unsaved Changes - 6382
需要修改之前的datasource
console->Create->Data Sources->search 'redis' and select a data source->in the Custom Data,let port2=6379->save
7、指令碼重新整理映像顯示名字
在cacti伺服器的指令碼目錄下:
[root@admin200 cli]# pwd
/var/www/cacti/cacti/cli
[root@admin200 cli]# php -q poller_graphs_reapply_names.php -id=All -d -s=Redis
WARNING: Do not interrupt this script. Interrupting during rename can cause issues
DEBUG: There are '142' Graphs to rename
DEBUG: Graph Name '192.168.0.19_Redis19 - Redis Commands - 6379' starting
DEBUG: Graph Rename Done for Graph '192.168.0.19_Redis19 - Redis Commands - 6379'
DEBUG: Graph Name '192.168.0.19_Redis19 - Redis Connections - 6379' starting
DEBUG: Graph Rename Done for Graph '192.168.0.19_Redis19 - Redis Connections - 6379'
DEBUG: Graph Name '192.168.0.19_Redis19 - Redis Memory - 6379' starting
DEBUG: Graph Rename Done for Graph '192.168.0.19_Redis19 - Redis Memory - 6379'
8、ok,重新整理web映像就顯示正常,見本文開頭。