check_pg_streaming_replication/README.md

79 lines
4.6 KiB
Markdown
Raw Normal View History

2019-03-15 16:35:31 +01:00
Nagios plugin to check Postgres Streaming replication
=====================================================
This script could be used as Nagios check plugin to verify Postgres Streaming replication state.
This script :
2019-03-15 17:21:18 +01:00
- check if Postgres is running (_CRITICAL_ raise if not)
2019-03-15 16:35:31 +01:00
- check if Postgres is in recovery mode :
- if Postgres is in recovery mode :
2019-03-15 17:21:18 +01:00
- retreive from Postgres the last _xlog_ file receive and the _xlog_ file replay
- check if Postgres recovery configuration file is NOT present (_CRITICAL_ raise if present)
- retreive master connection informations from Postgres recovery configuration file (_UNKNOWN_ raise on error). Default Postgres master TCP port will be used if port is not specify.
- retreive the current state and sync state of the host from Postgres master server by making a connection on master server (_UNKNOWN_ raise on error).
- check if the current state of the host is "streaming" (_CRITICAL_ raise if not)
- check if the current sync state of the host is "sync" (_CRITICAL_ raise if not)
- if the check of the current XLOG file of the master host is enabled :
- retreive current _xlog_ file from Postgres master server by making a connection on master server (_UNKNOWN_ raise on error).
- check if the current master _xlog_ file is the last received _xlog_ file (_CRITICAL_ raise if not)
- check if the last received _xlog_ file is the last replay _xlog_ file : if not, check the current delay with the last replayed transaction against _replay_warn_delay_ and _replay_crit_delay_ thresholds and raise corresponding error if they are exceeded
2019-03-15 17:21:18 +01:00
- Return _OK_ state
2019-03-15 16:35:31 +01:00
- if Postgres is not in recovery mode :
2019-03-15 17:21:18 +01:00
- check if Postgres recovery configuration file is present (_CRITICAL_ raise if present)
- check if stand-by client(s) is connected (_WARNING_ raise if not)
- Return _OK_ state with list and count of stand-by client(s)
2019-03-15 16:35:31 +01:00
**Note :** This script was originally write for PostgreSQL 9.1 and test on 9.1, 9.5 and 9.6 but it could be compatible with other versions of PostgreSQL. Do not hesitate to tell me how this script work with other versions and share some fix. All contributions are welcome !
Requirements
------------
2019-03-15 17:21:18 +01:00
* **On master node :** Slaves must be able to connect with user from `recovery.conf` to database with the same name (or another specify with `-D`) as trust (or via md5 using password specify in `~/.pgpass`).
2019-03-15 16:35:31 +01:00
2019-03-15 17:21:18 +01:00
* **On standby node :** `PG_USER` must be able to connect localy on the database with the same name (or another specify with `-D`) as trust (or via md5 using password specify in `~/.pgpass`).
* `sudo` must be install on each nodes.
2019-03-15 16:35:31 +01:00
Usage
-----
Usage : check_pg_streaming_replication [-d] [-h] [options]
-u pg_user Specify Postgres user (Default : postgres)
-b psql_bin Specify psql binary path (Default : /usr/bin/psql)
-m pg_main Specify Postgres main directory path
(By default, try to auto-detect it, on your system it :
/var/lib/postgresql/9.6/main)
-r recovery_conf Specify Postgres recovery configuration file path
(Default : [PG_MAIN]/recovery.conf)
-U pg_master_user Specify Postgres user to use on master (Default : user from recovery.conf file)
-p pg_port Specify default Postgres master TCP port (Default : 5432)
-D dbname Specify DB name on Postgres master/slave to connect on (Default : PG_USER)
-C 1/0 Enable or disable check if the current XLOG file of the master host is the same
of the last replay XLOG file (Default : 1)
-w replay_warn_delay Specify the replay warning delay in second (Default : 3)
-c replay_crit_delay Specify the replay critical delay in second (Default : 5)
-d Debug mode
-h Show this message
2019-03-15 16:35:31 +01:00
Copyright
---------
Copyright (c) 2014-2019 Benjamin Renard
License
-------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.