配置zabbix-agent配置文件
Zabbix-agent监控配置文件/etc/zabbix/zabbix_agentd.conf(标准安装位置,如果手动编译安装可能在其他位置):
增加如下内容:
UserParameter=Redis.Info[*],/home/zkml/redismonitor.sh $1 $2 通过脚本监控信息
UserParameter=Redis.Status,(/home/zkml/redis-3.2.9/src/redis-cli -h 192.168.42.128 -p 7000 -a 密码 ping)2>/dev/null |grep -c PONG
通过命令检查redis状态,使用错误重定向(2>/dev/null)是防止报错导致监控项失效无法告警
增加时候需要特别注意: redismonitor.sh 放置的位置zabbix需要有权限执行. chmod +x redismonitor.sh 另外放置的文件夹也要有权限,否则是无监控信息的如果redis需要密码验证还需要设置 -a 密码
Zabbix-server端验证使用zabbix-get:
/usr/local/zabbix-3.0.3/bin/zabbix_get -s 192.168.42.128 -p10041 –k Redis.Status(ip是客户端的,端口zabbix-agent)
编写脚本
#!/bin/bash
redis_client_path=/usr/local/bin/redis-cli
redis_ip=192.168.42.128
redis_port=7000
##redis client 信息
redis_monitor_client="${redis_client_path} -h ${redis_ip} -p ${redis_port} -a 123456 info Clients"
## 查看当前连接到redis的客户端的个数
connected_clients(){
${redis_monitor_client}|awk "NR==2"|cut -d ":" -f 2
}
## 查看被阻塞客户端的个数
blocked_clients(){
${redis_monitor_client}|awk "NR==5"|cut -d ":" -f 2
}
## 判断redis服务器的运行情况,统计是1的话说明redis 是正常的
redis_monitor="${redis_client_path} -h ${redis_ip} -p ${redis_port} -a 123456"
redis_status(){
${redis_monitor} ping |grep -c PONG
}
#######CPU#####
##redis服务器消耗的系统cpu
used_cpu_sys(){
${redis_monitor} info CPU|awk "NR==2"|cut -d ":" -f 2
}
##redis服务器消耗的用户cpu
used_cpu_user(){
${redis_monitor} info CPU|awk 'NR==3'|cut -d ":" -f 2
}
## 后台进程消耗的系统cpu
used_cpu_sys_children(){
${redis_monitor} info CPU|awk 'NR==4'|cut -d ":" -f 2
}
##后台进程消耗的用户cpu
used_cpu_user_children(){
${redis_monitor} info CPU|awk 'NR==5'|cut -d ":" -f 2
}
########Memory########
used_memory(){
used=$(${redis_monitor} info Memory|awk 'NR==2'|cut -d ":" -f 2)
awk 'BEGIN {printf "%.2f\n",$used/1000000}'
}
used_memory_peak(){
used_peak=`${redis_monitor} info Memory|awk 'NR==6'|cut -d ":" -f 2`
awk 'BEGIN{printf "%.2f\n","$used_peak"/1000000}'
}
$1