]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - flakes/private/monitoring/plugins/check_redis_replication
Squash changes containing private information
[perso/Immae/Config/Nix.git] / flakes / private / monitoring / plugins / check_redis_replication
diff --git a/flakes/private/monitoring/plugins/check_redis_replication b/flakes/private/monitoring/plugins/check_redis_replication
new file mode 100755 (executable)
index 0000000..6dbe4c4
--- /dev/null
@@ -0,0 +1,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 | time=${lag}s;5;10;0; offset=${offset};5;10;0;"
+    exit $STATE_OK
+  elif [[ $lag -lt 10 && $offset -lt 10 ]]; then
+    echo "WARNING - $output | time=${lag}s;5;10;0; offset=${offset};5;10;0;"
+    exit $STATE_WARNING
+  else
+    echo "CRITICAL - $output | time=${lag}s;5;10;0; offset=${offset};5;10;0;"
+    exit $STATE_CRITICAL
+  fi
+fi