blob: 7a884e1100631f1d741859aa241b56df0c023c88 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/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
|