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


- PostgreSQL connection string:
postgres://username:password@host:5432/database. Thepostgresql://prefix works too. - Query:
SELECT 1by default.
MySQL and MariaDB


- MySQL/MariaDB connection string:
mysql://username:password@host:3306/database. Themariadb://prefix works too. - Query:
SELECT 1by default.
Microsoft SQL Server


- Microsoft SQL Server connection string:
sqlserver://username:password@host:1433/database. Themssql://prefix works too. - Query:
SELECT 1by default.
Oracle Database


- Oracle connection string:
oracle://username:password@host:1521/service_name. The path is the service name, not a SID. The port is1521when omitted. - Query:
SELECT 1 FROM DUALby default. A trailing;is removed. A PL/SQL block starting withBEGINorDECLAREis 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


- Redis connection string:
redis://username:password@host:6379/0. Therediss://prefix is accepted too. - Command:
PINGby default.
MongoDB


- MongoDB connection string:
mongodb://username:password@host:27017/database?authSource=admin. Themongodb+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:
SELECT 1 FROM orders LIMIT 1Keep the query cheap: it runs at every interval. The check fails when the query fails or takes longer than the Timeout of the schedule.
