diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-12-07 15:40:15 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-12-07 15:40:15 +0100 |
commit | 6015a3b52c3b155ac444aeb39950c38a5e653101 (patch) | |
tree | 47ab7a69ddeaedab40a20b0c5cb8a7cc98b0f1f1 /modules/private/monitoring/plugins/check_mysql_replication | |
parent | dded66995529a0419cc56778f4ebb4247c2ab765 (diff) | |
download | Nix-6015a3b52c3b155ac444aeb39950c38a5e653101.tar.gz Nix-6015a3b52c3b155ac444aeb39950c38a5e653101.tar.zst Nix-6015a3b52c3b155ac444aeb39950c38a5e653101.zip |
Add mysql and redis monitoring
Diffstat (limited to 'modules/private/monitoring/plugins/check_mysql_replication')
-rwxr-xr-x | modules/private/monitoring/plugins/check_mysql_replication | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_mysql_replication b/modules/private/monitoring/plugins/check_mysql_replication new file mode 100755 index 0000000..8923928 --- /dev/null +++ b/modules/private/monitoring/plugins/check_mysql_replication | |||
@@ -0,0 +1,35 @@ | |||
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 Seconds_Behind_Master | cut -d':' -f2 | sed -e "s/\s//g") | ||
14 | |||
15 | if [[ $exit_code -ne 0 ]]; then | ||
16 | echo "UNKNOWN - Impossible to run mysql command" | ||
17 | exit $STATE_UNKNOWN | ||
18 | elif [[ -z "$lag" ]]; then | ||
19 | echo "UNKNOWN - No replication found for mysql" | ||
20 | exit $STATE_UNKNOWN | ||
21 | else | ||
22 | output="Replication lag for mysql is ${lag}s" | ||
23 | LC_ALL=C lag=$(printf "%.*f" 0 $lag) | ||
24 | |||
25 | if [[ $lag -lt 5 ]]; then | ||
26 | echo "OK - $output" | ||
27 | exit $STATE_OK | ||
28 | elif [[ $lag -lt 10 ]]; then | ||
29 | echo "WARNING - $output" | ||
30 | exit $STATE_WARNING | ||
31 | else | ||
32 | echo "CRITICAL - $output" | ||
33 | exit $STATE_CRITICAL | ||
34 | fi | ||
35 | fi | ||