diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-11 09:31:24 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-11 09:31:24 +0200 |
commit | 2bdbb0213a0f70705f81ac2eaf8349668b2c29b4 (patch) | |
tree | 06b1e40db99815133dcc40e3e68531d45e1bd228 /modules/profile/files/monitoring/check_postgres_replication | |
parent | 25c99a635507abfe6af4a1f0a9fc5a103d1880c0 (diff) | |
parent | d8bc769648c1528f5d749deee060d70e326ef431 (diff) | |
download | Puppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.tar.gz Puppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.tar.zst Puppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.zip |
Merge branch 'monitoring' into dev
Diffstat (limited to 'modules/profile/files/monitoring/check_postgres_replication')
-rw-r--r-- | modules/profile/files/monitoring/check_postgres_replication | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/profile/files/monitoring/check_postgres_replication b/modules/profile/files/monitoring/check_postgres_replication new file mode 100644 index 0000000..a550077 --- /dev/null +++ b/modules/profile/files/monitoring/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 | ||