Documentation
Monitors / Monitor databases

Monitor databases

PostgreSQL, MySQL and MariaDB, Microsoft SQL Server, Oracle Database, Redis and MongoDB checks with a query or a command.

Database monitors connect with a connection string and run a query or a command. A successful check proves more than an open port: the server accepts the credentials and answers.

Create a dedicated user with read-only rights for monitoring. The connection string, password included, is stored encrypted with your ENCRYPTION_MASTER_KEY. When you edit a monitor, leave it empty to keep the current one.

PostgreSQL

The What to monitor card of a PostgreSQL monitorThe What to monitor card of a PostgreSQL monitor
A PostgreSQL check with SELECT 1.
  • PostgreSQL connection string: postgres://username:password@host:5432/database. The postgresql:// prefix works too.
  • Query: SELECT 1 by default.

MySQL and MariaDB

The What to monitor card of a MySQL / MariaDB monitorThe What to monitor card of a MySQL / MariaDB monitor
One protocol for MySQL and MariaDB.
  • MySQL/MariaDB connection string: mysql://username:password@host:3306/database. The mariadb:// prefix works too.
  • Query: SELECT 1 by default.

Microsoft SQL Server

The What to monitor card of a Microsoft SQL Server monitorThe What to monitor card of a Microsoft SQL Server monitor
A SQL Server check.
  • Microsoft SQL Server connection string: sqlserver://username:password@host:1433/database. The mssql:// prefix works too.
  • Query: SELECT 1 by default.

Oracle Database

The What to monitor card of an Oracle Database monitorThe What to monitor card of an Oracle Database monitor
An Oracle check with SELECT 1 FROM DUAL.
  • Oracle connection string: oracle://username:password@host:1521/service_name. The path is the service name, not a SID. The port is 1521 when omitted.
  • Query: SELECT 1 FROM DUAL by default. A trailing ; is removed. A PL/SQL block starting with BEGIN or DECLARE is sent as is.

Extra driver properties can be added as parameters of the connection string, for example ?oracle.net.ssl_server_dn_match=true. The session shows up as uptime-kotlin in v$session.

The log reads Oracle Database connection successful in 35ms, or Oracle Database connection failed: followed by the error of the driver, such as ORA-01017: invalid username/password.

Redis

The What to monitor card of a Redis monitorThe What to monitor card of a Redis monitor
A Redis check with PING.
  • Redis connection string: redis://username:password@host:6379/0. The rediss:// prefix is accepted too.
  • Command: PING by default.

MongoDB

The What to monitor card of a MongoDB monitorThe What to monitor card of a MongoDB monitor
A MongoDB check with the ping command.
  • MongoDB connection string: mongodb://username:password@host:27017/database?authSource=admin. The mongodb+srv:// prefix works too, for Atlas and other DNS seed lists. Several hosts of a replica set are separated by commas.
  • Command (JSON document): the command to run, {"ping": 1} by default.

The command runs on the database of the connection string, or on admin when there is none. The check succeeds when the answer contains ok: 1: MongoDB command successful in 12ms. An invalid JSON document fails with Invalid MongoDB command.

To check that a collection answers, use a command such as {"count": "orders", "limit": 1}. The user needs the rights to run it on that database.

Write a useful query

SELECT 1 checks that the server answers. A query on your own data goes further and catches a missing table, a broken replica or an exhausted connection pool:

SQL
SELECT 1 FROM orders LIMIT 1

Keep the query cheap: it runs at every interval. The check fails when the query fails or takes longer than the Timeout of the schedule.

Suggest a change on GitHub