Nagios 監控Redis 應用配置:
監控環境介紹:
1>被監控redis服務器:
IP:192.168.254.102
Hostname:server1
Redis版本:REDIS 2.8.7
2>Nagios 監控服務器:
IP:192.168.254.101
Hostname:Nagios
一.下載 perl版本Redis 監控程序包
下載參考:
1> https://exchange.nagios.org/directory/Plugins/Databases/check_redis-2Epl/details
2> https://github.com/willixix/WL-NagiosPlugins
下載後將check_redis.pl文件拷貝到被監控服務器目錄: /usr/local/nagios/libexec/
並給用戶可執行的權限與用戶組:
chown nagios.nagios check_redis.pl (如果監控默認執行就是Root用戶與組,則不需要修改)
chmod 755 check_redis.pl (修改文件可以執行權限)
二.被監控服務器安裝perl redis環境依賴包
[root@localhost ~]# yum install -y perl-CPAN perl-Time-HiRes perl-YAML
[root@localhost ~]# perl -MCPAN -e shell
CPAN> install Redis
.....
CPAN> quit (退出)
一路回車確認即可.(大概需要20分鐘,具體以個人網速決定)
安裝完後,使用監控程序包進行連接測試能否獲取到監控數據:
/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6379 -x "passwd" -a
OK: REDIS 2.8.7 on 127.0.0.1:6379 has 1 databases (db0) with 18 keys, up 3 days 23 hours
返回以上結果,說明依賴包安裝成功;否則請重新執行一次安裝: install Redis 安裝.
相關參數說明:
H: 主機名(IP) -p :redis 端口 -x: redis 訪問密碼(如果沒有,可以省略) -a: 後面可能添加一些具體的監控參數.
/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6379 -x "redis_passwd" -a 'connected_clients,blocked_clients' -w ~,~ -c ~,~ -m -M 4G -A -R -T
OK: REDIS 2.8.7 on 127.0.0.1:6379 has 1 databases (db0) with 14 keys, up 4 days 18 hours - response in 0.003s, hitrate is 100.00%,
查看更多命令幫助:
/usr/local/nagios/libexec/check_redis.pl --help
Redis Check for Nagios version 0.73
by William Leibzon - william(at)leibzon.org
This is redis monitoring plugin to check its stats variables, replication, response time
hitrate, memory utilization and other info. The plugin can also query and test key data
against specified thresholds. All data is available as performance output for graphing.
...................
三.客戶機的配置(被監控服務器)
#vi /usr/local/nagios/etc/nrpe.cfg
增加以下配置:
command[check_redis]=/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6379 -x "passwd" -a
如服務器運行2個redis 實例:
redis實例2 增加以下配置:
command[check_redis_6380]=/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6380 -a
如果還要對其它指標進行監控,可按照 redis實例2的方法進行增加即可:
監控內存:
command[check_redis_memory]=/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6380 -a 'used_memory_human,used_memory_peak_human'!~,~!~,~
監控基本信息:
command[check_redis]=/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6380 -a 'connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf'!100,5,~,~!500,10,~,~
監控CPU:
command[check_redis_cpu]=/usr/local/nagios/libexec/check_redis.pl -H 127.0.0.1 -p 6380 -a 'used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children'!15,20,~,~!25,30,~,~ ;
配置完成後,重啓被監控服務器監控程序:
關閉: /etc/init.d/nrpe stop
重啓: /etc/init.d/nrpe start
四.Nagios 服務器端配置
1> 添加被監控主機:
#vi /usr/local/nagios/etc/objects/hosts.cfg
增加以下配置(如果該已經存在,則不要再添加)
define host{
use generic-host
host_name DB4
alias DB4
address 192.168.254.102
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 120
notification_period 24x7
notification_options d,r
contact_groups admins
}
2>增加被監控機的應用服務
/usr/local/nagios/etc/objects]# vi services.cfg
增加以下配置:
define service{
use generic-service
service_description Redis_Servers
hostgroup_name Redis_Servers ;監控用戶組
notifications_enabled 1
check_period 24x7
max_check_attempts 2
retry_check_interval 2
contact_groups admins
notification_interval 180
notification_period 24x7
notification_options w,u,c
check_command check_nrpe!check_redis ;監控程序
}
Redis實例2 增加以下配置:
define service{
use generic-service
service_description redis_6380
hostgroup_name redis_6380 ;監控用戶組
notifications_enabled 1
check_period 24x7
max_check_attempts 2
retry_check_interval 2
contact_groups admins
notification_interval 180
notification_period 24x7
notification_options w,u,c
check_command check_nrpe!check_redis_6380 ;監控程序
}
3>增加redis 被監控組:
#/usr/local/nagios/etc/objects]# vi hostgroups.cfg
增加以下配置:
define hostgroup {
hostgroup_name Redis_Servers
alias Redis_Servers
members server1,server2
}
redis實例2 增加以下配置:
define hostgroup {
hostgroup_name redis_6380
alias redis_6380
members server1
}
五.驗證服務器端配置,並重啓Nagios 應用.
檢查Nagios 監控服務器是否存在異常(如果配置有異常,重啓將會失敗)
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.3.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 07-25-2011
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/services.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/hosts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/hostgroups.cfg'...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
#:/usr/local/nagios/etc/objects]# /etc/init.d/nagios stop
Nagios stop successful.
#:/usr/local/nagios/etc/objects]# /etc/init.d/nagios start
Nagios started successful.
#:/usr/local/nagios/etc/objects]#
前端監控顯示效果:
至此Redis 監控就配置完了.
值得注意的是Redis 依賴環境包安裝.如果安裝失敗,則無法正常獲取Redis監控數據.