check_pgactivity

by OPMDG

Nagios remote agent

132 Stars 41 Forks Last release: over 1 year ago (REL2_4) Other 680 Commits 34 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

=head1 NAME

check_pgactivity - PostgreSQL plugin for Nagios

=head1 SYNOPSIS

checkpgactivity {-w|--warning THRESHOLD} {-c|--critical THRESHOLD} [-s|--service SERVICE ] [-h|--host HOST] [-U|--username ROLE] [-p|--port PORT] [-d|--dbname DATABASE] [-S|--dbservice SERVICE_NAME] [-P|--psql PATH] [--debug] [--status-file FILE] [--path PATH] [-t|--timemout TIMEOUT] checkpgactivity [-l|--list] check_pgactivity [--help]

=head1 DESCRIPTION

check_pgactivity is designed to monitor PostgreSQL clusters from Nagios. It offers many options to measure and monitor useful performance metrics.

=over

=item B<-s>, B<--service> SERVICE

The Nagios service to run. See section SERVICES for a description of available services or use C<--list> for a short service and description list.

=item B<-h>, B<--host> HOST

Database server host or socket directory (default: $PGHOST or "localhost")

See section C for more informations.

=item B<-U>, B<--username> ROLE

Database user name (default: $PGUSER or "postgres").

See section C for more informations.

=item B<-p>, B<--port> PORT

Database server port (default: $PGPORT or "5432").

See section C for more informations.

=item B<-d>, B<--dbname> DATABASE

Database name to connect to (default: $PGDATABASE or "template1").

B! This is not necessarily one of the database that will be checked. See C<--dbinclude> and C<--dbexclude> .

See section C for more informations.

=item B<-S>, B<--dbservice> SERVICE_NAME

The connection service name from pg_service.conf to use.

See section C for more informations.

=item B<--dbexclude> REGEXP

Some services automatically check all the databases of your cluster (note: that does not mean they always need to connect on all of them to check them though). C<--dbexclude> excludes any database whose name matches the given Perl regular expression. Repeat this option as many time as needed.

See C<--dbinclude> as well. If a database match both dbexclude and dbinclude arguments, it is excluded.

=item B<--dbinclude> REGEXP

Some services automatically check all the databases of your cluster (note: that does not imply that they always need to connect to all of them though). Some always exclude the 'postgres' database and templates. C<--dbinclude> checks B databases whose names match the given Perl regular expression. Repeat this option as many time as needed.

See C<--dbexclude> as well. If a database match both dbexclude and dbinclude arguments, it is excluded.

=item B<-w>, B<--warning> THRESHOLD

The Warning threshold.

=item B<-c>, B<--critical> THRESHOLD

The Critical threshold.

=item B<-F>, B<--format> OUTPUT_FORMAT

The output format. Supported output are: C, C, C, C, C, C and C.

Using the C format, the results are written in a binary file (using perl module C) given in argument C<--output>. If no output is given, defaults to file C in the same directory as the script.

The C and C formats are equivalent to the C and C formats respectively. The only difference is that they enforce the units to follow the strict Nagios specs: B, c, s or %. Any unit absent from this list is dropped (Bps, Tps, etc).

=item B<--tmpdir> DIRECTORY

Path to a directory where the script can create temporary files. The script relies on the system default temporary directory if possible.

=item B<-P>, B<--psql> FILE

Path to the C executable (default: "psql").

=item B<--status-file> PATH

Path to the file where service status information is kept between successive calls. Default is to save check_pgactivity.data in the same directory as the script.

=item B<--dump-status-file>

Dump the content of the status file and exit. This is useful for debugging purpose.

=item B<--dump-bin-file> [PATH]

Dump the content of the given binary file previously created using C<--format binary>. If no path is given, defaults to file C in the same directory as the script.

=item B<-t>, B<--timeout> TIMEOUT

Timeout (default: "30s"), as raw (in seconds) or as an interval. This timeout will be used as C for psql and URL timeout for C service.

=item B<-l>, B<--list>

List available services.

=item B<-V>, B<--version>

Print version and exit.

=item B<--debug>

Print some debug messages.

=item B<-?>, B<--help>

Show this help page.

=back

=head2 THRESHOLDS

THRESHOLDS provided as warning and critical values can be raw numbers, percentages, intervals or sizes. Each available service supports one or more formats (eg. a size and a percentage).

=over

=item B

If THRESHOLD is a percentage, the value should end with a '%' (no space). For instance: 95%.

=item B

If THRESHOLD is an interval, the following units are accepted (not case sensitive): s (second), m (minute), h (hour), d (day). You can use more than one unit per given value. If not set, the last unit is in seconds. For instance: "1h 55m 6" = "1h55m6s".

=pod

=item B

If THRESHOLD is a size, the following units are accepted (not case sensitive): b (Byte), k (KB), m (MB), g (GB), t (TB), p (PB), e (EB) or Z (ZB). Only integers are accepted. Eg. C<1.5MB> will be refused, use C<1500kB>.

The factor between units is 1024 bytes. Eg. C<1g = 1G = 1024*1024*1024.>

=back

=head2 CONNECTIONS

check_pgactivity allows two different connection specifications: by service or by specifying values for host, user, port, and database. Some services can run on multiple hosts, or needs to connect to multiple hosts.

You might specify one of the parameters below to connect to your PostgreSQL instance. If you don't, no connection parameters are given to psql: connection relies on binary defaults and environment.

The format for connection parameters is:

=over

=item B C<--dbservice SERVICE_NAME>

Define a new host using the given service. Multiple hosts can be defined by listing multiple services separated by a comma. Eg.

--dbservice service1,service2

For more information about service definition, see: Lhttps://www.postgresql.org/docs/current/libpq-pgservice.html

=item B C<--host HOST>, C<--port PORT>, C<--user ROLE> or C<--dbname DATABASE>

One parameter is enough to define a new host. Usual environment variables (PGHOST, PGPORT, PGDATABASE, PGUSER, PGSERVICE) or default values are used for missing parameters.

If multiple values are given, define as many host as maximum given values.

Values are associated by position. Eg.:

--host h1,h2 --port 5432,5433

Means "host=h1 port=5432" and "host=h2 port=5433".

If the number of values is different between parameters, any host missing a parameter will use the first given value for this parameter. Eg.:

--host h1,h2 --port 5433

Means: "host=h1 port=5433" and "host=h2 port=5433".

=item B

For instance:

--dbservice s1 --host h1 --port 5433

means: use "service=s1" and "host=h1 port=5433" in this order. If the service supports only one host, the second host is ignored.

=item B

You can not overwrite services connections variables with parameters C<--host HOST>, C<--port PORT>, C<--user ROLE> or C<--dbname DATABASE>

=back

=head2 SERVICES

Descriptions and parameters of available services.

=over

=item B

Check if all archived WALs exist between the oldest and the latest WAL in the archive folder and make sure they are 16MB. The given folder must have archived files from ONE cluster. The version of PostgreSQL that created the archives is only checked on the last one, for performance consideration.

This service requires the argument C<--path> on the command line to specify the archive folder path to check. Obviously, it must have access to this folder at the filesystem level: you may have to execute it on the archiving server rather than on the PostgreSQL instance.

The optional argument C<--suffix> defines the suffix of your archived WALs; this is useful for compressed WALs (eg. .gz, .bz2, ...). Default is no suffix.

This service needs to read the header of one of the archives to define how many segments a WAL owns. Check_pgactivity automatically handles files with extensions .gz, .bz2, .xz, .zip or .7z using the following commands:

gzip -dc bzip2 -dc xz -dc unzip -qqp 7z x -so

If needed, provide your own command that writes the uncompressed file to standard output with the C<--unarchiver> argument.

Optional argument C<--ignore-wal-size> skips the WAL size check. This is useful if your archived WALs are compressed and checkpgactivity is unable to guess the original size. Here are the commands checkpgactivity uses to guess the original size of .gz, .xz or .zip files:

gzip -ql xz -ql unzip -qql

Default behaviour is to check the WALs size.

Perfdata contains the number of archived WALs and the age of the most recent one.

Critical and Warning define the max age of the latest archived WAL as an interval (eg. 5m or 300s ).

Required privileges: unprivileged role; the system user needs read access to archived WAL files.

Sample commands:

checkpgactivity -s archivefolder --path /path/to/archives -w 15m -c 30m checkpgactivity -s archivefolder --path /path/to/archives --suffix .gz -w 15m -c 30m checkpgactivity -s archivefolder --path /path/to/archives --ignore-wal-size --suffix .bz2 -w 15m -c 30m checkpgactivity -s archivefolder --path /path/to/archives --unarchiver "unrar p" --ignore-wal-size --suffix .rar -w 15m -c 30m

=item B (8.1+)

Check if the archiver is working properly and the number of WAL files ready to archive.

Perfdata returns the number of WAL files waiting to be archived.

Critical and Warning thresholds are optional. They apply on the number of files waiting to be archived. They only accept a raw number of files.

Whatever the given threshold, a critical alert is raised if the archiver process did not archive the oldest waiting WAL to be archived since last call.

Required privileges: superuser (<v11), grant execute on function pgstatfile(text) for v11+.

=item B (8.1+)

Check the autovacuum activity on the cluster.

Perfdata contains the age of oldest running autovacuum and the number of workers by type (VACUUM, VACUUM ANALYZE, ANALYZE, VACUUM FREEZE).

Thresholds, if any, are ignored.

Required privileges: unprivileged role.

=item B (all)

Check the total number of connections in the PostgreSQL cluster.

Perfdata contains the number of connections per database.

Critical and Warning thresholds accept either a raw number or a percentage (eg. 80%). When a threshold is a percentage, it is compared to the difference between the cluster parameters C and C.

Required privileges: an unprivileged user only sees its own queries; a pg_monitor (10+) or superuser (<10) role is required to see all queries.

=item B (8.2+)

Check the status of all backends. Depending on your PostgreSQL version, statuses are: C, C, C (>=9.0 only), C, C, C, C, C and C. B appears when you are not allowed to see the statuses of other connections.

This service supports the argument C<--exclude REGEX> to exclude queries matching the given regular expression.

You can use multiple C<--exclude REGEX> arguments.

Critical and Warning thresholds are optional. They accept a list of 'statuslabel=value' separated by a comma. Available labels are C, C<idlexact>, C, C, C and C. Values are raw numbers or time units and empty lists are forbidden. Here is an example:

-w 'waiting=5,idle_xact=10' -c 'waiting=20,idle_xact=30,active=1d'

Perfdata contains the number of backends for each status and the oldest one for each of them, for 8.2+.

Note that the number of backends reported in Nagios message B excluded backends.

Required privileges: an unprivileged user only sees its own queries; a pg_monitor (10+) or superuser (<10) role is required to see all queries.

=item B (12+)

Check for data checksums error, reported in pgstatdatabase.

This service requires that data checksums are enabled on the target instance. UNKNOWN will be returned if that's not the case.

Critical and Warning thresholds are optional. They only accept a raw number of checksums errors per database. If the thresholds are not provided, a default value of

1
will be used for both thresholds.

Checksums errors are CRITICAL issues, so it's highly recommended to keep default threshold, as immediate action should be taken as soon as such a problem arises.

Perfdata contains the number of error per database.

Required privileges: unprivileged user.

=item B (8.1+)

Check the age of the backup label file.

Perfdata returns the age of the backup_label file, -1 if not present.

Critical and Warning thresholds only accept an interval (eg. 1h30m25s).

Required privileges: unprivileged role (9.3+); superuser (<9.3)

=item B (8.3+)

Check the percentage of pages written by backends since last check.

This service uses the status file (see C<--status-file> parameter).

Perfdata contains the ratio per second for each C counter since last execution. Units Nps for checkpoints, max written clean and fsyncs are the number of "events" per second.

Critical and Warning thresholds are optional. If set, they I accept a percentage.

Required privileges: unprivileged role.

=item B

Estimate bloat on B-tree indexes.

Warning and critical thresholds accept a comma-separated list of either raw number(for a size), size (eg. 125M) or percentage. The thresholds apply to B size, not object size. If a percentage is given, the threshold will apply to the bloat size compared to the total index size. If multiple threshold values are passed, check_pgactivity will choose the largest (bloat size) value.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

It also supports a C<--exclude REGEX> parameter to exclude relations matching a regular expression. The regular expression applies to "database.schemaname.relationname". This enables you to filter either on a relation name for all schemas and databases, on a qualified named relation (schema + relation) for all databases or on a qualified named relation in only one database.

You can use multiple C<--exclude REGEX> parameters.

Perfdata will return the number of indexes of concern, by warning and critical threshold per database.

A list of the bloated indexes will be returned after the perfdata. This list contains the fully qualified bloated index name, the estimated bloat size, the index size and the bloat percentage.

Required privileges: superuser (<10) able to log in all databases, or at least those in C; superuser (<10); on PostgreSQL 10+, a user with the role pg_monitor suffices, provided that you grant SELECT on the system table pg_statistic to the pg_monitor role, in each database of the cluster: C

=item B (all)

Check the commit and rollback rate per second since last call.

This service uses the status file (see --status-file parameter).

Perfdata contains the commit rate, rollback rate, transaction rate and rollback ratio for each database since last call.

Critical and Warning thresholds are optional. They accept a list of comma separated 'label=value'. Available labels are B, B and B, which will be compared to the number of rollbacks, the rollback rate and the rollback ratio of each database. Warning or critical will be raised if the reported value is greater than B, B or B.

Required privileges: unprivileged role.

=item B (8.0+)

Check the most important settings.

Warning and Critical thresholds are ignored.

Specific parameters are : C<--workmem>, C<--maintenanceworkmem>, C<--sharedbuffers>,C<--walbuffers>, C<--checkpointsegments>, C<--effectivecachesize>, C<--nocheckautovacuum>, C<--nocheckfsync>, C<--nocheckenable>, C<--nochecktrack_counts>.

Required privileges: unprivileged role.

=item B (all)

Perform a simple connection test.

No perfdata is returned.

This service ignores critical and warning arguments.

Required privileges: unprivileged role.

=item B (all)

Perform the given user query.

Specify the query with C<--query>. The first column will be used to perform the test for the status if warning and critical are provided.

The warning and critical arguments are optional. They can be of format integer (default), size or time depending on the C<--type> argument. Warning and Critical will be raised if they are greater than the first column, or less if the C<--reverse> option is used.

All other columns will be used to generate the perfdata. Each field name is used as the name of the perfdata. The field value must contain your perfdata value and its unit appended to it. You can add as many fields as needed. Eg.:

SELECT pgdatabasesize('postgres'), pgdatabasesize('postgres')||'B' AS db_size

Required privileges: unprivileged role (depends on the query).

=item B (8.1+)

B of database sizes, and B of every databases.

This service uses the status file (see C<--status-file> parameter).

Perfdata contains the size of each database and their size delta since last call.

Critical and Warning thresholds are optional. They are a list of optional 'label=value' separated by a comma. It allows to fine tune the alert based on the absolute C and/or the C size. Eg.:

-w 'size=500GB' -c 'size=600GB'
-w 'delta=1%' -c 'delta=10%'
-w 'size=500GB,delta=1%' -c 'size=600GB,delta=10GB'

The C label accepts either a raw number or a size and checks the total database size. The C label accepts either a raw number, a percentage, or a size. The aim of the delta parameter is to detect unexpected database size variations. Delta thresholds are absolute value, and delta percentages are computed against the previous database size. A same label must be filled for both warning and critical.

For backward compatibility, if a single raw number or percentage or size is given with no label, it applies on the size difference for each database since the last execution. Both threshold bellow are equivalent:

-w 'delta=1%' -c 'delta=10%'
-w '1%' -c '10%'

This service supports both C<--dbexclude> and C<--dbinclude> parameters.

Required privileges: unprivileged role.

=item B (all)

Check the cache hit ratio on the cluster.

This service uses the status file (see C<--status-file> parameter).

Perfdata returns the cache hit ratio per database. Template databases and databases that do not allow connections will not be checked, nor will the databases which have never been accessed.

Critical and Warning thresholds are optional. They only accept a percentage.

This service supports both C<--dbexclude> and C<--dbinclude> parameters.

Required privileges: unprivileged role.

=item B (9.0)

Check the data delta between a cluster and its hot standbys.

You must give the connection parameters for two or more clusters.

Perfdata returns the data delta in bytes between the master and each hot standby cluster listed.

Critical and Warning thresholds are optional. They can take one or two values separated by a comma. If only one value given, it applies to both received and replayed data. If two values are given, the first one applies to received data, the second one to replayed ones. These thresholds only accept a size (eg. 2.5G).

This service raises a Critical if it doesn't find exactly ONE valid master cluster (ie. critical when 0 or 2 and more masters).

Required privileges: unprivileged role.

=item B (9.0+)

Checks if the cluster is in recovery and accepts read only queries.

This service ignores critical and warning arguments.

No perfdata is returned.

Required privileges: unprivileged role.

=item B (all)

Checks if the cluster accepts read and/or write queries. This state is reported as "in production" by pg_controldata.

This service ignores critical and warning arguments.

No perfdata is returned.

Required privileges: unprivileged role.

=item B (8.2+)

Check if there are invalid indexes in a database.

A critical alert is raised if an invalid index is detected.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

This service supports a C<--exclude REGEX> parameter to exclude indexes matching a regular expression. The regular expression applies to "database.schemaname.indexname". This enables you to filter either on a relation name for all schemas and databases, on a qualified named index (schema + index) for all databases or on a qualified named index in only one database.

You can use multiple C<--exclude REGEX> parameters.

Perfdata will return the number of invalid indexes per database.

A list of invalid indexes will be returned after the perfdata. This list contains the fully qualified index name. If excluded index is set, the number of exclude indexes is returned.

Required privileges: unprivileged role able to log in all databases.

=item B (9.1+)

Checks if the replication is paused. The service will return UNKNOWN if executed on a master server.

Thresholds are optional. They must be specified as interval. OK will always be returned if the standby is not paused, even if replication delta time hits the thresholds.

Critical or warning are raised if last reported replayed timestamp is greater than given threshold AND some data received from the master are not applied yet. OK will always be returned if the standby is paused, or if the standby has already replayed everything from master and until some write activity happens on the master.

Perfdata returned: * paused status (0 no, 1 yes, NaN if master) * lag time (in second) * data delta with master (0 no, 1 yes)

Required privileges: unprivileged role.

=item B (8.2+)

Check on each databases that the oldest C (from autovacuum or not) is not older than the given threshold.

This service uses the status file (see C<--status-file> parameter) with PostgreSQL 9.1+.

Perfdata returns oldest C per database in seconds. With PostgreSQL 9.1+, the number of [auto]analyses per database since last call is also returned.

Critical and Warning thresholds only accept an interval (eg. 1h30m25s) and apply to the oldest execution of analyse.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

Required privileges: unprivileged role able to log in all databases.

=item B (8.2+)

Check that the oldest vacuum (from autovacuum or otherwise) in each database in the cluster is not older than the given threshold.

This service uses the status file (see C<--status-file> parameter) with PostgreSQL 9.1+.

Perfdata returns oldest vacuum per database in seconds. With PostgreSQL 9.1+, it also returns the number of [auto]vacuums per database since last execution.

Critical and Warning thresholds only accept an interval (eg. 1h30m25s) and apply to the oldest vacuum.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

Required privileges: unprivileged role able to log in all databases.

=item B (all)

Check the number of locks on the hosts.

Perfdata returns the number of locks, by type.

Critical and Warning thresholds accept either a raw number of locks or a percentage. For percentage, it is computed using the following limits for 7.4 to 8.1:

maxlockspertransaction * maxconnections

for 8.2+:

maxlockspertransaction * (maxconnections + maxpreparedtransactions)

for 9.1+, regarding lockmode :

maxlockspertransaction * (maxconnections + maxpreparedtransactions) or maxpredlockspertransaction * (maxconnections + maxprepared_transactions)

Required privileges: unprivileged role.

=item B (all)

Check the longest running query in the cluster.

Perfdata contains the max/avg/min running time and the number of queries per database.

Critical and Warning thresholds only accept an interval.

This service supports both C<--dbexclude> and C<--dbinclude> parameters.

It also supports argument C<--exclude REGEX> to exclude queries matching the given regular expression from the check.

Above 9.0, it also supports C<--exclude REGEX> to filter out application_name.

You can use multiple C<--exclude REGEX> parameters.

Required privileges: an unprivileged role only checks its own queries; a pg_monitor (10+) or superuser (<10) role is required to check all queries.

=item B (all)

Checks oldest database by transaction age.

Critical and Warning thresholds are optional. They accept either a raw number or percentage for PostgreSQL 8.2 and more. If percentage is given, the thresholds are computed based on the "autovacuumfreezemax_age" parameter. 100% means that some table(s) reached the maximum age and will trigger an autovacuum freeze. Percentage thresholds should therefore be greater than 100%.

Even with no threshold, this service will raise a critical alert if a database has a negative age.

Perfdata returns the age of each database.

This service supports both C<--dbexclude> and C<--dbinclude> parameters.

Required privileges: unprivileged role.

=item B (all)

Check if the cluster is running the most recent minor version of PostgreSQL.

Latest versions of PostgreSQL can be fetched from PostgreSQL official website if check_pgactivity has access to it, or must be given as a parameter.

Without C<--critical> or C<--warning> parameters, this service attempts to fetch the latest version numbers online. A critical alert is raised if the minor version is not the most recent.

You can optionally set the path to your prefered retrieval tool using the C<--path> parameter (eg. C<--path '/usr/bin/wget'>). Supported programs are: GET, wget, curl, fetch, lynx, links, links2.

If you do not want to (or cannot) query the PostgreSQL website, provide the expected versions using either C<--warning> OR C<--critical>, depending on which return value you want to raise.

The given string must contain one or more MINOR versions separated by anything but a '.'. For instance, the following parameters are all equivalent:

--critical "10.1 9.6.6 9.5.10 9.4.15 9.3.20 9.2.24 9.1.24 9.0.23 8.4.22" --critical "10.1, 9.6.6, 9.5.10, 9.4.15, 9.3.20, 9.2.24, 9.1.24, 9.0.23, 8.4.22" --critical "10.1,9.6.6,9.5.10,9.4.15,9.3.20,9.2.24,9.1.24,9.0.23,8.4.22" --critical "10.1/9.6.6/9.5.10/9.4.15/9.3.20/9.2.24/9.1.24/9.0.23/8.4.22"

Any other value than 3 numbers separated by dots (before version 10.x) or 2 numbers separated by dots (version 10 and above) will be ignored. If the running PostgreSQL major version is not found, the service raises an unknown status.

Perfdata returns the numerical version of PostgreSQL.

Required privileges: unprivileged role; access to http://www.postgresql.org required to download version numbers.

=item B (8.1+)

Check the oldest I (aka. prepared transaction) in the cluster.

Perfdata contains the max/avg age time and the number of prepared transactions per databases.

Critical and Warning thresholds only accept an interval.

Required privileges: unprivileged role.

=item B (8.3+)

Check the oldest I transaction.

Perfdata contains the max/avg age and the number of idle transactions per databases.

Critical and Warning thresholds only accept an interval.

This service supports both C<--dbexclude> and C<--dbinclude> parameters.

Above 9.2, it supports C<--exclude> to filter out connections. Eg., to filter out pgdump and pgdumpall, set this to 'pgdump,pgdumpall'.

Required privileges: an unprivileged role checks only its own queries; a pg_monitor (10+) or superuser (<10) role is required to check all queries.

=item B

Check the age and size of backups.

This service uses the status file (see C<--status-file> parameter).

The C<--path> argument contains the location to the backup folder. The supported format is a glob pattern matching every folder or file that you need to check. If appropriate, the probe should be run as a user with sufficient privileges to check for the existence of files.

The C<--pattern> is required, and must contain a regular expression matching the backup file name, extracting the database name from the first matching group. For example, the pattern "(\w+)-\d+.dump" can be used to match dumps of the form:

mydb-20150803.dump
otherdb-20150803.dump
mydb-20150806.dump
otherdb-20150806.dump
mydb-20150807.dump

Optionally, a C<--global-pattern> option can be supplied to check for an additional global file.

Tip : For compatibility with pgback, you should use C<--path> '/path/*{dump,sql}' C<--pattern> '(\w+)[0-9-]+.dump' C<--global-pattern> 'pgglobal[0-9-]+.sql'

The C<--critical> and C<--warning> thresholds are optional. They accept a list of 'metric=value' separated by a comma. Available metrics are C and C, respectively the age of the oldest and newest backups, and C, which must be the maximum variation of size since the last check, expressed as a size or a percentage. C, expressed in B, is the minimum variation of size needed to raise an alert.

This service supports the C<--dbinclude> and C<--dbexclude> arguments, to respectively test for the presence of include or exclude files.

The argument C<--exclude> enables you to exclude files younger than an interval. This is useful to ignore files from a backup in progress. Eg., if your backup process takes 2h, set this to '125m'.

Perfdata returns the age of the oldest and newest backups, as well as the size of the newest backups.

Required privileges: unprivileged role; the system user needs read access on the directory containing the dumps (but not on the dumps themselves).

=item B

Check if this script is running the given version of check_pgactivity. You must provide the expected version using either C<--warning> OR C<--critical>.

No perfdata is returned.

Required privileges: none.

=item B (8.2+)

Check that the instance data directory rights are 700, and belongs to the system user currently running postgresql.

The check on rights works on all Unix systems.

Checking the user only works on Linux systems (it uses /proc to avoid dependencies). Before 9.3, you need to provide the expected owner using the C<--uid> argument, or the owner will not be checked.

Required privileges: <11:superuser v11: user with pg_monitor or pg_read_all_setting The system user must also be able to read the folder containing PGDATA: B

=item B (9.4+)

Check the number of WAL files and pg_replslot files retained by each replication slots.

Perfdata returns the number of WAL and pgreplslot files that each replication slot has to keep. This service needs superuser privileges since v10 to obtain pgreplslot files. Unless replslot_files will be at 0.

Critical and Warning thresholds are optional. They accept either a raw number (for backward compatibility, only wal threshold will be used) or a list 'wal=value' and 'replslot=value'. Respectively number of kept wal files or number of files in pg_replslot for each slot.

Required privileges: <10: unprivileged role v10: unprivileged role, or superuser to monitor logical replication v11+: unprivileged user with GRANT EXECUTE on function pglsdir(text)

Here is an example:

-w 'wal=50,replslot=20' -c 'wal=100,replslot=40'

=item B (9.0+)

Check if the current settings have changed since they were stored in the service file.

The "known" settings are recorded during the very first call of the service. To update the known settings after a configuration change, call this service again with the argument C<--save>.

No perfdata.

Critical and Warning thresholds are ignored.

A Critical is raised if at least one parameter changed.

Required privileges: unprivileged role.

=item B (7.4+)

Check all sequences assigned to a column (the smallserial, serial and bigserial types), and raise an alarm if the column or sequences gets too close to the maximum value.

Perfdata returns the sequences that trigger the alert.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

Critical and Warning thresholds accept a percentage of the sequence filled.

Required privileges: unprivileged role able to log in all databases

=item B (9.5+)

Check the age of the statistics snapshot (statistics collector's statistics). This probe helps to detect a frozen stats collector process.

Perfdata returns the statistics snapshot age.

Critical and Warning thresholds accept a raw number of seconds.

Required privileges: unprivileged role.

=item B (9.1+)

Check the data delta between a cluster and its standbys in streaming replication.

Optional argument C<--slave> allows you to specify some slaves that MUST be connected. This argument can be used as many times as desired to check multiple slave connections, or you can specify multiple slaves connections at one time, using comma separated values. Both methods can be used in a single call. The provided values must be of the form "APPLICATION_NAME IP". Both following examples will check for the presence of two slaves:

--slave 'slave1 192.168.1.11' --slave 'slave2 192.168.1.12' --slave 'slave1 192.168.1.11','slave2 192.168.1.12'

This service supports a C<--exclude REGEX> parameter to exclude every result matching a regular expression on application_name or IP address fields.

You can use multiple C<--exclude REGEX> parameters.

Perfdata returns the data delta in bytes between the master and every standbies found, the number of standbies connected and the number of excluded standbies.

Critical and Warning thresholds are optional. They can take one or two values separated by a comma. If only one value is supplied, it applies to both flushed and replayed data. If two values are supplied, the first one applies to flushed data, the second one to replayed data. These thresholds only accept a size (eg. 2.5G).

Required privileges: unprivileged role.

=item B (9.5+)

Check if tables are changed to unlogged. In 9.5, you can switch between logged and unlogged.

Without C<--critical> or C<--warning> parameters, this service attempts to fetch all unlogged tables.

A critical alert is raised if an unlogged table is detected.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

This service supports a C<--exclude REGEX> parameter to exclude relations matching a regular expression. The regular expression applies to "database.schemaname.relationname". This enables you to filter either on a relation name for all schemas and databases, on a qualified named relation (schema + relation) for all databases or on a qualified named relation in only one database.

You can use multiple C<--exclude REGEX> parameters.

Perfdata will return the number of unlogged tables per database.

A list of the unlogged tables will be returned after the perfdata. This list contains the fully qualified table name. If C<--exclude REGEX> is set, the number of excluded tables is returned.

Required privileges: unprivileged role able to log in all databases, or at least those in C<--dbinclude>.

=item B

Estimate bloat on tables.

Warning and critical thresholds accept a comma-separated list of either raw number(for a size), size (eg. 125M) or percentage. The thresholds apply to B size, not object size. If a percentage is given, the threshold will apply to the bloat size compared to the table + TOAST size. If multiple threshold values are passed, check_pgactivity will choose the largest (bloat size) value.

This service supports both C<--dbexclude> and C<--dbinclude> parameters. The 'postgres' database and templates are always excluded.

This service supports a C<--exclude REGEX> parameter to exclude relations matching the given regular expression. The regular expression applies to "database.schemaname.relationname". This enables you to filter either on a relation name for all schemas and databases, on a qualified named relation (schema + relation) for all databases or on a qualified named relation in only one database.

You can use multiple C<--exclude REGEX> parameters.

B: With a non-superuser role, this service can only check the tables that the given role is granted to read!

Perfdata will return the number of tables matching the warning and critical thresholds, per database.

A list of the bloated tables will be returned after the perfdata. This list contains the fully qualified bloated table name, the estimated bloat size, the table size and the bloat percentage.

Required privileges: superuser (<10) able to log in all databases, or at least those in C; superuser (<10); on PostgreSQL 10+, a user with the role pg_monitor suffices, provided that you grant SELECT on the system table pg_statistic to the pg_monitor role, in each database of the cluster: C

=item B (8.1+)

Check the number and size of temp files.

This service uses the status file (see C<--status-file> parameter) for 9.2+.

Perfdata returns the number and total size of temp files found in C folders. They are aggregated by database until 8.2, then by tablespace (see GUC temp_tablespaces).

Starting with 9.2, perfdata returns as well the number of temp files per database since last run, the total size of temp files per database since last run and the rate at which temp files were generated.

Critical and Warning thresholds are optional. They accept either a number of file (raw value), a size (unit is B to define a size) or both values separated by a comma.

Thresholds are applied on current temp files being created AND the number/size of temp files created since last execution.

Required privileges: <10: superuser v10: an unprivileged role is possible but it will not monitor databases that it cannot access, nor live temp files v11: an unprivileged role is possible but must be granted EXECUTE on functions pglsdir(text), pgreadfile(text), pgstatfile(text); the same restrictions than on v10 will still apply v12+: a role with pg_monitor privilege.

=item B (8.1+)

Returns time since postmaster start ("uptime", from 8.1), since configuration reload (from 8.4), and since shared memory initialization (from 10).

Please note that the uptime is unaffected when the postmaster resets all its children (for example after a kill -9 on a process or a failure).

From 10+, the 'time since shared memory init' aims at detecting this situation: in fact we use the age of the oldest non-client child process (usually checkpointer, writer or startup). This needs pgmonitor access to read pgstat_activity.

Critical and Warning thresholds are optional. If both are set, Critical is raised when the postmaster uptime or the time since shared memory initialization is less than the critical threshold.

Warning is raised when the time since configuration reload is less than the warning threshold. If only a warning or critical threshold is given, it will be used for both cases. Obviously these alerts will disappear from themselves once enough time has passed.

Perfdata contain the three values (when available).

Required privileges: pg_monitor on PG10+; otherwise unprivileged role.

=item B (8.1+)

Check the number of WAL files.

Perfdata returns the total number of WAL files, current number of written WAL, the current number of recycled WAL, the rate of WAL written to disk since the last execution on the master cluster and the current timeline.

Critical and Warning thresholds accept either a raw number of files or a percentage. In case of percentage, the limit is computed based on:

100% = 1 + checkpointsegments * (2 + checkpointcompletion_target)

For PostgreSQL 8.1 and 8.2:

100% = 1 + checkpoint_segments * 2

If C is set for 9.0 to 9.4, the limit is the greatest of the following formulas:

100% = 1 + checkpointsegments * (2 + checkpointcompletiontarget) 100% = 1 + walkeepsegments + 2 * checkpointsegments

For 9.5 and above, the limit is:

100% = maxwalsize (as a number of WAL) + walkeepsegments (if set)

Required privileges: <10:superuser (<10) v10:unprivileged user with pgmonitor v11+ :unprivileged user with pgmonitor, or with grant EXECUTE on function pglswaldir

=back

=head2 EXAMPLES

=over

=item Execute service "last_vacuum" on host "host=localhost port=5432":

checkpgactivity -h localhost -p 5432 -s lastvacuum -w 30m -c 1h30m

=item Execute service "hotstandbydelta" between hosts "service=pg92" and "service=pg92s":

checkpgactivity --dbservice pg92,pg92s --service hotstandby_delta -w 32MB -c 160MB

=item Execute service "streaming_delta" on host "service=pg92" to check its slave "stby1" with the IP address "192.168.1.11":

checkpgactivity --dbservice pg92 --slave "stby1 192.168.1.11" --service streamingdelta -w 32MB -c 160MB

=item Execute service "hit_ratio" on host "slave" port "5433, excluding database matching the regexps "idelone" and "(?i:sleep)":

checkpgactivity -p 5433 -h slave --service hitratio --dbexclude idelone --dbexclude "(?i:sleep)" -w 90% -c 80%

=item Execute service "hit_ratio" on host "slave" port "5433, only for databases matching the regexp "importantone":

checkpgactivity -p 5433 -h slave --service hitratio --dbinclude importantone -w 90% -c 80%

=back

=head1 VERSION

check_pgactivity version 2.4, released on Wed Jan 30 2019

=head1 LICENSING

This program is open source, licensed under the PostgreSQL license. For license terms, see the LICENSE provided with the sources.

=head1 AUTHORS

Author: Open PostgreSQL Monitoring Development Group Copyright: (C) 2012-2019 Open PostgreSQL Monitoring Development Group

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.