• zabbix监控redis


    1)agent端配置

    • 安装redis
    yum install epel-release -y 
    yum install redis -y 
    
    • 配置认证密码
    #vim /etc/redis.conf
    requirepass redhat 
    #systemctl restart redis
    
    • 获取redis的item值shell脚本
    #vim /etc/zabbix/zabbix_agentd.d/redis_status.sh
    #/bin/bash 
    R_COMMAND="$1"
    R_PORT="6379"
    R_SERVER="127.0.0.1"
    PASSWD="redhat"
    redis_status(){
       (echo -en "AUTH $PASSWD
    INFO
    ";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT" > /tmp/redis_"$R_PORT".tmp
          REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
           echo "$REDIS_STAT_VALUE"
    }
    case $R_COMMAND in
        used_cpu_user_children)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        used_cpu_sys)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        total_commands_processed)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        role)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        lru_clock)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        latest_fork_usec)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        keyspace_misses)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        keyspace_hits)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        keys)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        expires)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        expired_keys)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        evicted_keys)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        connected_clients)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        changes_since_last_save)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        blocked_clients)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        bgsave_in_progress)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        bgrewriteaof_in_progress)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        used_memory_peak)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        used_memory)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        used_cpu_user)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        used_cpu_sys_children)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
        total_connections_received)
    	redis_status "$R_PORT" "$R_COMMAND"
    	;;
    	*)
    	echo $"USAGE:$0 {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}"
    	esac
    
    • 授权
    chmod +x /etc/zabbix/zabbix_agentd.d/redis_status.sh
    
    • 修改agent配置文件
    #vim /etc/zabbix/zabbix_agentd.d/userparameter_redis.conf
    UserParameter=redis.status[*],/etc/zabbix/zabbix_agentd.d/redis_status.sh $1
    
    • 重启agent服务
    systemctl restart zabbix-agent
    

    2)server端配置

    • server端获取key值
    # zabbix_get -s 192.168.1.33 -k redis.status
    USAGE:/etc/zabbix/zabbix_agentd.d/redis_status.sh {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}
    # zabbix_get -s 192.168.1.33 -k redis.status[used_cpu_sys]
    0.11
    
    • 键值
    redis.status[used_cpu_user_children]
    redis.status[used_cpu_sys]
    redis.status[total_commands_processed]
    redis.status[role]
    redis.status[lru_clock]
    redis.status[latest_fork_usec]
    redis.status[keyspace_misses]
    redis.status[keyspace_hits]
    redis.status[keys]
    redis.status[expires]
    redis.status[expired_keys]
    redis.status[connected_clients]
    redis.status[changes_since_last_save]
    redis.status[blocked_clients]
    redis.status[bgrewriteaof_in_progress]
    redis.status[used_memory_peak]
    redis.status[used_memory]
    redis.status[used_cpu_user]
    redis.status[used_cpu_sys_children]
    redis.status[total_connections_received]
    
    • 创建模板
    • 创建监控项
    • 其它省略,验证图形
  • 相关阅读:
    IDE IntelliJ IDEA ToolsTable 窗口找回
    Equals方法与“==”区别
    JAVA虚拟机内存分配与回收机制(转)
    java集合框架总结三--Set接口及其子类
    2014年4月5日 java集合框架总结2--List接口及其子类
    java集合框架总结一
    sql 操作数据库
    EF框架用中使用mysql数据库需要安装mysql-for-visualstudio
    mysql 服务启动不了;无法启动MYSQL服务”1067 进程意外终止”解决办法
    mysql 修改密码
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9016248.html
Copyright © 2020-2023  润新知