线上是用Nagios监控的,版本是最新版4.0.8
在nagios服务器上面下载redis插件
下载地址页面
https://exchange.nagios.org/directory/Plugins/Databases/check_redis-2Epl/details
下载check_redis.pl文件
安装perl redis环境
[[email protected] ~]# yum install -y perl-CPAN perl-Time-HiRes perl-YAML
[[email protected] ~]# perl -MCPAN -e shell
CPAN> install Redis
之后遇到[yes]的位置,一路回车,需要安装很多组件。
我花了2~3个小时,不停的回车,终于安装好了。
将check_redis.pl文件放到/usr/local/nagios/libexec/ 目录下
设置权限
[[email protected] ~]#chmod 755 check_redis.pl
[[email protected] ~]#chown nagios:nagios check_redis.pl
测试插件
[[email protected] ~]#cd /usr/local/nagios/libexec/
[[email protected] ~]#./check_redis.pl -H 10.168.13.230 -p 6379
OK: REDIS 2.8.19 on 10.168.13.230:6380 has 1 databases (db0) with 16 keys, up 98 days 7 hours
测试连接到redis的时间
./check_redis.pl -H 10.168.13.230 -p 6379 -T 0.5,1
测试CPU
./check_redis.pl -H 10.168.13.230 -p 6379 -a ‘used_cpu_sys,used_cpu_user,used_cpu_user_children,used_cpu_sys_children‘ -w ~,~,~,~ -c ~,~,~,~
测试内存
./check_redis.pl -H 10.168.13.230 -p 6379 -a ‘used_memory_human,used_memory_peak_human‘ -w ~,~ -c ~,~
测试连接数
./check_redis.pl -H 10.168.13.230 -p 6379 -a ‘connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf‘ -w 100,5,~,~ -c 500,10,~,~
开始正式用Nagios监控
编辑文件
vi /usr/local/nagios/etc/objects/commands.cfg
最后一行添加以下内容
# check redis
define command {
command_name check_redis
command_line $USER1$/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -f
}
# check redis
define command {
command_name check_redis_conn_time
command_line $USER1$/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -T $ARG2$
}
编辑主机文件
在最后添加以下内容
define service{
use generic-service
host_name redis_1
service_description redis_6379_CPU
check_command check_redis!6379!‘used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children‘!~,~,~,~!~,~,~,~
}
define service{
use generic-service
host_name redis_1
service_description redis_6379_Memory
check_command check_redis!6379!‘used_memory_human,used_memory_peak_human‘!~,~!~,~
}
define service{
use generic-service
host_name redis_1
service_description redis_6379_Memory
check_command
check_redis!6379!‘connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf‘!100,5,~,~!500,10,~,~
}
define service{
use generic-service
host_name redis_1
service_description redis_6379_conn_number
check_command check_redis!6379!‘connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf‘!100,5,~,~!500,10,~,~
}
define service{
use generic-service
host_name redis_1
service_description redis_6379_conn_time
check_command check_redis_conn_time!6379!0.5,1
}
重启Nagios
/etc/init.d/nagios restart