zabbix监控redis的状态

1、在zabbix的agentd端配置文件添加如下:

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=htczabbix01
ServerActive=htczabbix01
Hostname=htcap02
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UserParameter=Redis.status,/usr/local/redis/bin/redis-cli -h 192.168.1.12 -p 6379 ping | grep -c PONG &&echo $status
UserParameter=Redis.Info[*],/etc/zabbix/script/redismonitor.sh $1 $2


3、编写redismonitor.sh脚本 /etc/zabbix/scripts/redismonitor.sh
#! /bin/bash
#Name: redismontior.sh
#From: [email protected] <2016/08/06>
#Action: Zabbix monitoring redis plug-in

REDISCLI="/usr/local/redis/bin/redis-cli"
HOST="192.168.1.12"
PORT=6379

if [[ $# == 1 ]];then
    case $1 in
        version)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "redis_version" | awk -F':' '{print $2}'`
            echo $result
        ;;
        uptime)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "uptime_in_seconds" | awk -F':' '{print $2}'`
            echo $result
        ;;
        connected_clients)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "connected_clients" | awk -F':' '{print $2}'`
            echo $result
        ;;
        blocked_clients)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "blocked_clients" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_memory)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_memory_rss)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_rss" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_memory_peak)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_peak" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_memory_lua)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_lua" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_cpu_sys)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_sys" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_cpu_user)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_user" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_cpu_sys_children)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}'`
            echo $result
        ;;
        used_cpu_user_children)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_user_children" | awk -F':' '{print $2}'`
            echo $result
        ;;
        rdb_last_bgsave_status)
            result=`$REDISCLI -h $HOST -p $PORT info  | grep -w "rdb_last_bgsave_status" | awk -F':' '{print $2}' | grep -c ok`
            echo $result
        ;;
        aof_last_bgrewrite_status)
            result=`$REDISCLI -h $HOST -p $PORT info  | grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | grep -c ok`
            echo $result
        ;;
        aof_last_write_status)
            result=`$REDISCLI -h $HOST -p $PORT info  | grep -w "aof_last_write_status" | awk -F':' '{print $2}' | grep -c ok`
            echo $result
        ;;
        *)
            echo -e "\033[33mUsage: $0 {connected_clients|blocked_clients|used_memory|used_memory_rss|used_memory_peak|used_memory_lua|used_cpu_sys|
used_cpu_user|used_cpu_sys_children|used_cpu_user_children|rdb_last_bgsave_status|aof_last_bgrewrite_status|aof_last_write_status}\033[0m"         ;;
    esac
elif [[ $# == 2 ]];then
    case $2 in
        keys)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $2}'`
            echo $result
        ;;
        expires)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $4}'`
            echo $result
        ;;
        avg_ttl)
            result=`$REDISCLI -h $HOST -p $PORT info | grep -w "$1" | grep -w "avg_ttl" | awk -F'=|,' '{print $6}'`
            echo $result
        ;;
        *)
            echo -e "\033[33mUsage: $0 {db0 keys|db0 expires|db0 avg_ttl}\033[0m" 
        ;;
    esac
fi


3.在web界面添加redis的监控项模板redis.xml



    3.2
    2017-09-21T10:10:29Z
    
        
            Templates
        
    
    
        
    
    
        
            {RedisMontior:Redis.Status.last(0)}=0
            0
            
            Redis is down
            0
            
            
            0
            5
            
            0
            0
            
            
        
    
    
        
            Redis Client
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    0
                    C80000
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[blocked_clients]
                    
                
                
                    1
                    0
                    00C800
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[connected_clients]
                    
                
            
        
        
            Redis CPU
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    2
                    C80000
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_cpu_sys]
                    
                
                
                    1
                    2
                    00C800
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_cpu_user]
                    
                
                
                    2
                    2
                    0000C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_cpu_sys_children]
                    
                
                
                    3
                    2
                    C800C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_cpu_user_children]
                    
                
            
        
        
            Redis DbKeys
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    2
                    C80000
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[db0,avg_ttl]
                    
                
                
                    1
                    2
                    00C800
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[db0,expires]
                    
                
                
                    2
                    2
                    0000C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[db0,keys]
                    
                
            
        
        
            Redis Memory
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    2
                    C80000
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_memory]
                    
                
                
                    1
                    2
                    00C800
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_memory_lua]
                    
                
                
                    2
                    2
                    0000C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_memory_peak]
                    
                
                
                    3
                    2
                    C800C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[used_memory_rss]
                    
                
            
        
        
            Redis WriteStatus
            900
            200
            0.0000
            100.0000
            1
            1
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    2
                    C80000
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[aof_last_bgrewrite_status]
                    
                
                
                    1
                    2
                    0000C8
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[rdb_last_bgsave_status]
                    
                
                
                    2
                    2
                    00C800
                    0
                    2
                    0
                    
                        RedisMontior
                        Redis.Info[aof_last_write_status]
                    
                
            
        
    






你可能感兴趣的:(zabbix)