分享一个监控redis的脚本
#!/bin/bash
redis_client_path=/usr/local/redis-4.0.11/src/redis-cli
redis_ip=192.168.5.149
redis_port=6379
#redis client情况
redis_monitor_client="$redis_client_path -h $redis_ip -p $redis_port info Clients"
#当前连接的客户端的个数
connected_clinets () {
$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"
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}'
#百分数表示
#awk 'BEGIN{printf "%.2f%\n",(’$num1‘/’$num2‘)*100}'
}
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
51cto博客链接:
http://blog.51cto.com/12217124/2158476
文章转载自一直爱流浪的猫,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




