• redis的session清理


    (1)统计redis连接信息

    echo 'client list' | /apps/svr/redis/bin/redis-cli -h 127.0.0.1 -p 6379 |awk '{print $1}' | awk -F '[=,:]' '{print $2}' | sort -n | uniq -c |sort -nr
    

    (2)当redis连接满了,client list都没法执行,那么是用netsta命令查看。

    netstat  -na| grep 6379  | awk '{print $5}' | awk -F":" '{print $1}' |  sort  | uniq -c
    

    (3)当redis实例cpu较高的时间,捕获redis正在执行的命令

    #!/user/bin/env bash
    
    port=$1
    
    rpid=`ps aux | grep redis-server| grep -v grep | grep $port | awk '{print $2}'`
    
    for((;;))
    do
            mon=`top -c -b -n 1 -p $rpid | tail -2|grep -Ev "^$"|awk '{if($9 > 15) print 1;else print 0}'`
    
            if [ $mon = 1 ]
            then     
                    /apps/svr/redis/bin/redis-cli -h 127.0.0.1 -p $port monitor > /tmp/$port.txt & 
    
                    echo 'client list'|/apps/svr/redis/bin/redis-cli -h 127.0.0.1 -p $port > /tmp/$port'_client'.txt 
    
                    sleep 1
                    ps aux | grep redis | grep -v 'grep' |grep 'redis-cli' | grep 'monitor' | grep $port | awk '{print $2}' | xargs kill  -s 9
                    exit 
            fi
    
            sleep 0.5
    done
    

    改进:

    #!/usr/bin/env bash
    
    port=$1
    # get the pid of redis-server of specified port
    rpid=`ps aux | grep redis-server| grep -v grep | grep $port | awk '{print $2}'`
    
    #when cpu usage is greater than 50%,begin to catch the redis query log by using the redis MONITOR command
    mon=`top -c -b -n 1 -p $rpid | tail -2|grep -Ev "^$"|awk '{if($9 > 50) print 1;else print 0}'`
    
    if [ $mon = 1 ]
    then
            /apps/svr/redis/bin/redis-cli -h 127.0.0.1 -p $port monitor > /tmp/$port.txt &;
    
            mpid=$!
            sleep 3
            # killing  the subprocess and exit
            kill $mpid
            exit
    fi
    

     

  • 相关阅读:
    在ASP.NET GridView 中使用e.CommandArgument传递参数
    循环处理之while and do while
    MzTreeView(梅花雪)完全攻略
    FreeTextBox使用详解
    委托、线程的用法
    Master Theorem
    python jsonpath 语法总结
    python + zmail 邮件发送
    python的yaml语法
    unittest单元测试框架总结
  • 原文地址:https://www.cnblogs.com/5sdba-notes/p/13944546.html
Copyright © 2020-2023  润新知