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监控数据.