diff options
Diffstat (limited to 'modules/private/monitoring/plugins')
-rwxr-xr-x | modules/private/monitoring/plugins/check_mysql_replication | 35 | ||||
-rwxr-xr-x | modules/private/monitoring/plugins/check_redis_replication | 38 |
2 files changed, 73 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 | ||
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 | |||
3 | STATE_OK=0 | ||
4 | STATE_WARNING=1 | ||
5 | STATE_CRITICAL=2 | ||
6 | STATE_UNKNOWN=3 | ||
7 | |||
8 | socket=$1 | ||
9 | |||
10 | info=$(redis-cli -s $socket info replication) | ||
11 | lag=$(echo "$info" | grep master_last_io_seconds_ago | cut -d":" -f2 | sed -e "s/\s//g") | ||
12 | slave_offset=$(echo "$info" | grep slave_repl_offset | cut -d":" -f2 | sed -e "s/\s//g") | ||
13 | master_offset=$(echo "$info" | grep master_repl_offset | cut -d":" -f2 | sed -e "s/\s//g") | ||
14 | offset=$(($master_offset - $slave_offset)) | ||
15 | |||
16 | exit_code=$? | ||
17 | |||
18 | if [[ $exit_code -ne 0 ]]; then | ||
19 | echo "UNKNOWN - Impossible to run redis command" | ||
20 | exit $STATE_UNKNOWN | ||
21 | elif [[ -z "$lag" ]]; then | ||
22 | echo "UNKNOWN - No replication found" | ||
23 | exit $STATE_UNKNOWN | ||
24 | else | ||
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 | ||
38 | fi | ||