#!/bin/bash STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 socket=$1 info=$(redis-cli -s $socket info replication) lag=$(echo "$info" | grep master_last_io_seconds_ago | cut -d":" -f2 | sed -e "s/\s//g") slave_offset=$(echo "$info" | grep slave_repl_offset | cut -d":" -f2 | sed -e "s/\s//g") master_offset=$(echo "$info" | grep master_repl_offset | cut -d":" -f2 | sed -e "s/\s//g") offset=$(($master_offset - $slave_offset)) exit_code=$? if [[ $exit_code -ne 0 ]]; then echo "UNKNOWN - Impossible to run redis command" exit $STATE_UNKNOWN elif [[ -z "$lag" ]]; then echo "UNKNOWN - No replication found" exit $STATE_UNKNOWN else output="Replication lag for redis is ${lag}s and offset is ${offset}" LC_ALL=C lag=$(printf "%.*f" 0 $lag) if [[ $lag -lt 5 && $offset -lt 5 ]]; then echo "OK - $output" exit $STATE_OK elif [[ $lag -lt 10 && $offset -lt 10 ]]; then echo "WARNING - $output" exit $STATE_WARNING else echo "CRITICAL - $output" exit $STATE_CRITICAL fi fi