No release in over 3 years
Low commit activity in last 3 years
This plugin provides native PostgreSQL instrumentation for monitoring and metrics collection, including: service health, database connectivity, database locks, replication status, database size, `pg_stat_bgwriter` metrics, and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 0.10
~> 13.0
~> 3.2
~> 3.1
~> 0.79.0
~> 2.41.5
~> 1.25.0
~> 0.9.11

Runtime

= 3.3.4
= 1.2.3
 Project Readme

Sensu-Plugins-postgres

Build Status Gem Version Code Climate Test Coverage Dependency Status

Functionality

Files

  • bin/check-postgres-alive.rb
  • bin/check-postgres-connections.rb
  • bin/metric-postgres-dbsize.rb
  • bin/metric-postgres-statsbgwriter.rb
  • bin/metric-postgres-statstable.rb
  • bin/check-postgres-replication.rb
  • bin/metric-postgres-graphite.rb
  • bin/metric-postgres-statsdb.rb
  • bin/metric-postgres-connections.rb
  • bin/metric-postgres-locks.rb
  • bin/metric-postgres-statsio.rb
  • bin/check-postgres-query.rb
  • bin/metrics-postgres-query.rb
  • bin/metric-postgres-relation-size.rb

Usage

Use --help to see command arguments.

Sample usage

Check if PostgreSQL is alive

$ check-postgres-alive.rb -d template1 -f /var/lib/postgresql/.pgpass
CheckPostgres OK: Server version: {"version"=>"PostgreSQL 9.6.3 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit"}

Check replication status

$ check-postgres-replication.rb -m psql1.local -s psql2.local -d template1 -w 5 -c 10
CheckPostgresReplicationStatus OK: replication delayed by 0.0MB :: master:B0/B4031000 slave:B0/B4031000 m_segbytes:16777216

Check number of connections

$ export PGPASSWORD=this-is-secret-password
$ check-postgres-connections.rb -a -w 80 -c 90 -d template1 -u sensu
CheckPostgresConnections OK: PostgreSQL connections under threshold: 17%, 174 out of 997 connections

Default values

Argument Env variable Value
-f, --pgpass PGPASSFILE ~/.pgpass
-h, --hostname PGHOST localhost
-P, --port PGPORT 5432
-d, --database PGDATABASE postgres
-u, --user PGUSER postgres
-p, --password PGPASSWORD

Options precedence is following:

  1. command line arguments
  2. pgpass file
  3. env variables
  4. defaults

Pgpass file

When file ~/.pgpass is found it is used by default. You can also use -f, --pgpass command line argument or set PGPASSFILE env variable.

File format is:

hostname:port:database:username:password

Only first line is used. If database is set to * it is ommited.

You can ovveride pgpass values with command line arguments, e.g. -h for hostname.

Installation

gem install sensu-plugins-postgres

Centos installation

yum -y install gcc ruby-devel rubygems  postgresql-devel
sensu-install -p sensu-plugins-postgres

See Installation and Setup for details.

Known issues

When using Sensu with EMBEDDED_RUBY=true and installing Postgres checks with /usr/bin/sensu-install -p sensu-plugins-postgres you might get following error:

ERROR:  Error installing sensu-plugins-postgres:
	ERROR: Failed to build gem native extension.
[...]
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***

The reason is that libssl library which comes with Sensu is incompatible with libpq library installed on your system. There is no easy way to fix it. You might want to install sensu-plugins-postgres globally with gem install sensu-plugins-postgres.

Checks are in /usr/local/bin directory.

Notes