zoukankan      html  css  js  c++  java
  • (十二)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
    sys

    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]
    • 创建模板
    • 创建监控项
    • 其它省略,验证图形
  • 相关阅读:
    Java并发包concurrent——ConcurrentHashMap
    Eclipse中给SVN添加项目
    Maven在导入其他项目时报错:Plugin execution not covered by lifecycle configuration
    新导入的项目目录结构不对(main目录)
    java.lang.reflect.Method.getAnnotation()方法示例
    彻底理解ThreadLocal
    Oracle查询前几条数据的方法
    PLSQL Developer新手使用教程(图文教程)
    PLSQL连接本地oracle或远程oracle数据库,实现随意切换
    Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
  • 原文地址:https://www.cnblogs.com/shaonli/p/12089956.html
Copyright © 2011-2022 走看看