]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/check_mysql_replication
Adjust sql parameters
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_mysql_replication
1 #!/bin/bash
2
3 STATE_OK=0
4 STATE_WARNING=1
5 STATE_CRITICAL=2
6 STATE_UNKNOWN=3
7
8 socket=$1
9 config_file=$2
10 info=$(mysql --defaults-file=${config_file} -S $socket -e "show slave status" --vertical)
11 exit_code=$?
12
13 lag=$(echo "$info" | grep "\bSeconds_Behind_Master\b" | cut -d':' -f2 | sed -e "s/\s//g")
14
15 IO_running=$(echo "$info" | grep "\bSlave_IO_Running\b" | cut -d':' -f2 | sed -e "s/\s//g")
16 SQL_running=$(echo "$info" | grep "\bSlave_SQL_Running\b" | cut -d':' -f2 | sed -e "s/\s//g")
17
18 if [[ $exit_code -ne 0 ]]; then
19 echo "UNKNOWN - Impossible to run mysql command"
20 exit $STATE_UNKNOWN
21 elif [[ -z "$lag" ]]; then
22 echo "UNKNOWN - No replication found for mysql"
23 exit $STATE_UNKNOWN
24 elif [[ "$IO_running" != "Yes" || "$SQL_running" != "Yes" ]]; then
25 echo "UNKNOWN - Replication is not running"
26 exit $STATE_UNKNOWN
27 else
28 output="Replication lag for mysql is ${lag}s"
29 LC_ALL=C lag=$(printf "%.*f" 0 $lag)
30
31 if [[ $lag -lt 5 ]]; then
32 echo "OK - $output | time=${lag}s;5;10;;"
33 exit $STATE_OK
34 elif [[ $lag -lt 10 ]]; then
35 echo "WARNING - $output | time=${lag}s;5;10;;"
36 exit $STATE_WARNING
37 else
38 echo "CRITICAL - $output | time=${lag}s;5;10;;"
39 exit $STATE_CRITICAL
40 fi
41 fi