aboutsummaryrefslogtreecommitdiff
path: root/modules/private/monitoring/plugins/check_redis_replication
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-12-07 15:40:15 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-12-07 15:40:15 +0100
commit6015a3b52c3b155ac444aeb39950c38a5e653101 (patch)
tree47ab7a69ddeaedab40a20b0c5cb8a7cc98b0f1f1 /modules/private/monitoring/plugins/check_redis_replication
parentdded66995529a0419cc56778f4ebb4247c2ab765 (diff)
downloadNix-6015a3b52c3b155ac444aeb39950c38a5e653101.tar.gz
Nix-6015a3b52c3b155ac444aeb39950c38a5e653101.tar.zst
Nix-6015a3b52c3b155ac444aeb39950c38a5e653101.zip
Add mysql and redis monitoring
Diffstat (limited to 'modules/private/monitoring/plugins/check_redis_replication')
-rwxr-xr-xmodules/private/monitoring/plugins/check_redis_replication38
1 files changed, 38 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_redis_replication b/modules/private/monitoring/plugins/check_redis_replication
new file mode 100755
index 0000000..7a884e1
--- /dev/null
+++ b/modules/private/monitoring/plugins/check_redis_replication
@@ -0,0 +1,38 @@
1#!/bin/bash
2
3STATE_OK=0
4STATE_WARNING=1
5STATE_CRITICAL=2
6STATE_UNKNOWN=3
7
8socket=$1
9
10info=$(redis-cli -s $socket info replication)
11lag=$(echo "$info" | grep master_last_io_seconds_ago | cut -d":" -f2 | sed -e "s/\s//g")
12slave_offset=$(echo "$info" | grep slave_repl_offset | cut -d":" -f2 | sed -e "s/\s//g")
13master_offset=$(echo "$info" | grep master_repl_offset | cut -d":" -f2 | sed -e "s/\s//g")
14offset=$(($master_offset - $slave_offset))
15
16exit_code=$?
17
18if [[ $exit_code -ne 0 ]]; then
19 echo "UNKNOWN - Impossible to run redis command"
20 exit $STATE_UNKNOWN
21elif [[ -z "$lag" ]]; then
22 echo "UNKNOWN - No replication found"
23 exit $STATE_UNKNOWN
24else
25 output="Replication lag for redis is ${lag}s and offset is ${offset}"
26 LC_ALL=C lag=$(printf "%.*f" 0 $lag)
27
28 if [[ $lag -lt 5 && $offset -lt 5 ]]; then
29 echo "OK - $output"
30 exit $STATE_OK
31 elif [[ $lag -lt 10 && $offset -lt 10 ]]; then
32 echo "WARNING - $output"
33 exit $STATE_WARNING
34 else
35 echo "CRITICAL - $output"
36 exit $STATE_CRITICAL
37 fi
38fi