#!/bin/bash
fork_usec_alarm=400
delayed_fsync_alarm=2
repl_offset_alarm=5
printSeparator() {
printtimes=50
if [[ $1 ]]; then
printtimes=$1
fi
mid=`expr $printtimes / 2`
echo " "
while [[ $printtimes -gt 0 ]]; do
echo -n "="
if [[ $2 ]] && [[ $printtimes == $mid ]]; then
echo -n $2
fi
let "printtimes--"
done
echo " "
echo " "
}
data=$(redis-cli info stats | grep fork | awk -F":" '{print $2}')
echo "latest_fork_usec: $data"
if [ $data -gt $fork_usec_alarm ]; then
echo "fork_usec_alarm!!!please check the data memory used"
else
echo "latest_fork_usec normal"
fi
printSeparator 50 "latest_fork_usec_check_end"
config=$(redis-cli config get appendfsync | sed 's/^.*fsync//g' | awk '{printf "%s",$1}')
echo "appendfsync: $config"
if [[ $config == 'everysec' ]]; then
if [[ $(redis-cli info persistence | grep delayed_fsync | awk -F ":" '{print $2}') -gt $delayed_fsync_alarm ]]; then
echo "delayed_fsync_alarm!!!please check the disk IO"
else
echo "aof_delayed_fsync normal"
fi
fi
printSeparator 50 "aof_delayed_fsync_check_end"
count=0
echo -n "" > /tmp/log1
master_repl_offset=$(redis-cli info replication | grep master_repl_offset | sed 's/master_repl_offset://g' | awk '{printf "%s",$1}')
for line in $(redis-cli info replication | grep slave | sed '/connected_/d'); do
line=$(echo $line | sed 's/,port=/ /g' | awk -F ":" '{print $2}')
ip=$(echo $line | awk -F "," '{print $1}' | sed 's/ip=//g')
state=$(echo $line | awk -F "," '{print $2}' | sed 's/state=//g')
offset=$(echo $line | awk -F "," '{print $3}' | sed 's/offset=//g')
minus_offset=`expr $master_repl_offset - $offset`
if [[ $state != "online" ]] || [[ $minus_offset -gt $repl_offset_alarm ]]; then
echo "machine ${ip} state:${state} minus offset: ${minus_offset}"
echo "machine ${ip} state:${state} minus offset: ${minus_offset}" >> /tmp/log1
fi
let "count++"
done
if [[ -s /tmp/log1 ]]; then
echo "repl_offset_alarm!!! please check slave machine "
else
echo "replication normal"
fi
printSeparator 50 "repl_offset_alarm_check_end"