summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg2021-08-31 12:26:04 +0200
committerGeorg2021-08-31 12:26:04 +0200
commit174458d8c7436e82f16742c710706c9f22cfadd6 (patch)
treeb0625304d94bdfe3fa81b505b4bf005f86ed4496
parent5f1c378aa6b120d036b37fa07ee86c3005376b9e (diff)
downloadsystem-174458d8c7436e82f16742c710706c9f22cfadd6.tar.gz
system-174458d8c7436e82f16742c710706c9f22cfadd6.tar.bz2
system-174458d8c7436e82f16742c710706c9f22cfadd6.zip
Adding mysql-status.sh
Signed-off-by: Georg <georg@lysergic.dev>
-rw-r--r--cron/cron.daily/mysql-status.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/cron/cron.daily/mysql-status.sh b/cron/cron.daily/mysql-status.sh
new file mode 100644
index 0000000..67d02ce
--- /dev/null
+++ b/cron/cron.daily/mysql-status.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+OUTPUT="nc -N 127.0.0.2 2424"
+maximumSecondsBehind=20
+/opt/mysql/bin/mysql -u repl-status -p'$dbmonpass' -e 'SHOW REPLICA STATUS \G' > /tmp/replicationstatus.txt
+
+slaveRunning="$(cat /tmp/replicationstatus.txt | grep "Replica_IO_Running: Yes" | wc -l)"
+slaveSQLRunning="$(cat /tmp/replicationstatus.txt | grep "Replica_SQL_Running: Yes" | wc -l)"
+secondsBehind="$(cat /tmp/replicationstatus.txt | grep "Seconds_Behind_Source" | tr -dc '0-9')"
+
+echo $slaveRunning | $OUTPUT
+echo $slaveSQLRunning | $OUTPUT
+echo $secondsBehind | $OUTPUT
+
+if [[ $slaveRunning != 1 || $slaveSQLRunning != 1 || $secondsBehind -gt $maximumSecondsBehind ]]; then
+ echo
+ echo "Replikacja wydaje się być popieprzona. Sending logs via email. @cranberry" | $OUTPUT
+ /usr/bin/mail -s "[MySQL Replication Monitor] Issue on $(hostname) at $(date)" system@lysergic.dev < /tmp/replicationstatus.txt
+else
+ echo
+ echo "Replikacja wydaje się być zdrowa." | $OUTPUT
+fi