diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-12-01 18:25:16 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-12-01 18:25:16 +0100 |
commit | 9f2025235d888eb4a7822024a5fad2e288388814 (patch) | |
tree | cd9ed388375e5843b373a5975b1e902b61ecaded /modules/private/monitoring/plugins | |
parent | 0012da0ff3d45df9f68412b90be4f7c24d46a777 (diff) | |
download | Nix-9f2025235d888eb4a7822024a5fad2e288388814.tar.gz Nix-9f2025235d888eb4a7822024a5fad2e288388814.tar.zst Nix-9f2025235d888eb4a7822024a5fad2e288388814.zip |
Add monitoring for backup-2
Diffstat (limited to 'modules/private/monitoring/plugins')
-rwxr-xr-x | modules/private/monitoring/plugins/check_last_file_date | 26 | ||||
-rwxr-xr-x | modules/private/monitoring/plugins/check_postgres_replication | 35 |
2 files changed, 61 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_last_file_date b/modules/private/monitoring/plugins/check_last_file_date new file mode 100755 index 0000000..df45bbc --- /dev/null +++ b/modules/private/monitoring/plugins/check_last_file_date | |||
@@ -0,0 +1,26 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | STATE_OK=0 | ||
4 | STATE_WARNING=1 | ||
5 | STATE_CRITICAL=2 | ||
6 | STATE_UNKNOWN=3 | ||
7 | |||
8 | base_path=$1 | ||
9 | hours=$2 | ||
10 | |||
11 | last_date=$(find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1) | ||
12 | |||
13 | if [ -z "$last_date" ]; then | ||
14 | echo "UNKNOWN: Could not read folder" | ||
15 | exit $STATE_UNKNOWN | ||
16 | else | ||
17 | LC_ALL=C last_date=$(printf "%.*f" 0 $last_date) | ||
18 | min_date=$(date -d "$hours hours ago" "+%s") | ||
19 | if [ "$min_date" -lt "$last_date" ]; then | ||
20 | echo "OK: Last file $(date -d @$last_date)" | ||
21 | exit $STATE_OK | ||
22 | else | ||
23 | echo "CRITICAL: Last file $(date -d @$last_date)" | ||
24 | exit $STATE_CRITICAL | ||
25 | fi | ||
26 | fi | ||
diff --git a/modules/private/monitoring/plugins/check_postgres_replication b/modules/private/monitoring/plugins/check_postgres_replication new file mode 100755 index 0000000..009b4d5 --- /dev/null +++ b/modules/private/monitoring/plugins/check_postgres_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 | user=$1 | ||
9 | host=$2 | ||
10 | port=$3 | ||
11 | |||
12 | lag=$(psql -h $host -p $port -A -t -c "SELECT COALESCE(EXTRACT(EPOCH FROM replay_lag),0) FROM pg_stat_replication WHERE usename='$user'" 2>/dev/null) | ||
13 | exit_code=$? | ||
14 | |||
15 | if [[ $exit_code -ne 0 ]]; then | ||
16 | echo "UNKNOWN - Impossible to run psql command" | ||
17 | exit $STATE_UNKNOWN | ||
18 | elif [[ -z "$lag" ]]; then | ||
19 | echo "UNKNOWN - No replication found for $user" | ||
20 | exit $STATE_UNKNOWN | ||
21 | else | ||
22 | output="Replication lag for $user 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 | ||