Netwarden
Back to Documentation
Monitoringv2.0

Database Monitoring

Monitor PostgreSQL and MySQL/MariaDB on the machines the agent runs on

Last updated: November 21, 2026
3 min read

Database Monitoring

The agent watches PostgreSQL and MySQL (or MariaDB) servers on the machine it runs on: whether they are up, their connections, cache hit ratio, slow queries, locks and replication lag.

Detection

When a PostgreSQL or MySQL server runs on the machine, the agent notices it and starts watching it, without a restart; a database installed later is picked up too. To read the database's statistics it needs a user it can sign in with, set up as below. Without one, the database shows as unreachable.

PostgreSQL

1. Create a monitoring user

As a superuser:

sql
CREATE USER svc_netwarden WITH PASSWORD 'choose-a-long-random-password';
GRANT pg_monitor TO svc_netwarden;
GRANT CONNECT ON DATABASE postgres TO svc_netwarden;

pg_monitor (PostgreSQL 10 and later) gives read-only access to the statistics views and nothing else.

For slow-query counts, also enable the pg_stat_statements extension (add it to shared_preload_libraries, restart PostgreSQL, then CREATE EXTENSION pg_stat_statements;).

2. Allow it to connect

Make sure pg_hba.conf lets the user in from the local machine, for example:

conf
host    all     svc_netwarden  127.0.0.1/32    scram-sha-256
host    all     svc_netwarden  ::1/128         scram-sha-256

then sudo systemctl reload postgresql, and check:

bash
psql -h localhost -U svc_netwarden -d postgres -c "SELECT 1;"

3. Tell the agent

In /etc/netwarden/netwarden.conf:

yaml
enable_postgresql: true
postgresql_user: svc_netwarden
postgresql_password: choose-a-long-random-password
postgresql_database: postgres
# postgresql_host: localhost:5432
# postgresql_socket: /var/run/postgresql   # to connect through the socket instead

Then sudo systemctl restart netwarden.

MySQL and MariaDB

1. Create a monitoring user

sql
CREATE USER 'svc_netwarden'@'localhost' IDENTIFIED BY 'choose-a-long-random-password';
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'svc_netwarden'@'localhost';

PROCESS lets the agent read the server's status; REPLICATION CLIENT lets it read replication lag on a replica.

2. Tell the agent

yaml
enable_mysql: true
mysql_user: svc_netwarden
mysql_password: choose-a-long-random-password
# mysql_host: localhost:3306
# mysql_socket: /var/run/mysqld/mysqld.sock

Then sudo systemctl restart netwarden.

What is reported

| PostgreSQL | MySQL and MariaDB | |---|---| | Up or down | Up or down | | Active, idle and idle-in-transaction connections | Current connections and the most used | | Buffer cache hit ratio, blocks read and hit | InnoDB buffer pool hit ratio, reads and read requests | | Transactions committed and rolled back | Queries | | Slow queries (needs pg_stat_statements) | Slow queries | | Locks held | Table locks waited for | | Dead tuples | | | Replication lag on a replica | Replication lag on a replica |

The Database status widget shows them on any dashboard, and any of these metrics can carry an alert, for example replication lag above 30 seconds, or idle-in-transaction connections above 10.

Databases outside the machine

The agent reads databases on the machine it runs on. For a managed database (RDS, Cloud SQL, DigitalOcean), install the agent on a machine that can reach it and set postgresql_host or mysql_host to its address; connections to a remote host use TLS when the server offers it.

Related

Something unclear or wrong on this page? Write to us and the people who build Netwarden will fix it.