Database monitoring on a VM
An agent on a virtual machine can monitor databases running on the same host, and databases on other hosts it can reach over the network. This page walks you through adding one. For how coverages and the wizard work, see the Database monitoring overview.
What you can monitor
Section titled “What you can monitor”- Databases on the host. The agent discovers databases running on the host, including in containers, and lists them under Discovered on this host.
- Remote databases. A database on another host, or a managed service such as Amazon RDS, can be monitored from any agent that can reach it. Add it with Add database and enter its endpoint.
Every coverage is available on a VM, including log file coverages such as PostgreSQL server logs and the MySQL slow query log. Log file coverages read files on the agent’s host, so they only work for a database on that host.
How local databases are identified
Section titled “How local databases are identified”A database on the host often listens on localhost, which isn’t unique across your servers. The agent identifies it by the host’s routable address instead, so its metrics and traces line up. A database the agent reaches on the same host also gets host CPU, memory, and disk counted toward its health. See Telemetry identity.
Set up monitoring
Section titled “Set up monitoring”-
Make sure the agent is in managed config mode. In Settings → Agents, open the agent. If the Databases tab asks you to switch to managed, click Switch to managed. Manual edits to the collector configuration are replaced.
-
Open the wizard. On the Databases tab, click Monitor next to a discovered database, or Add database for one that wasn’t discovered. You can also start from Databases → Monitor a database.
-
Choose coverages. Standard metrics is always on. Turn on the others you need. See Engines and coverages.
-
Run the setup steps the wizard shows on the database, such as creating the monitoring user and its grants.
-
Fill in the connection. Enter the endpoint, such as
localhost:5432. Discovery fills in the engine and instance name but not the endpoint. Then enter the monitoring user and choose how to provide the password. See Database credentials. -
Click Save and apply. Data starts arriving within a minute.
Worked example: PostgreSQL on the host
Section titled “Worked example: PostgreSQL on the host”-
Create the monitoring user in PostgreSQL:
-
Enable
pg_stat_statementsfor query performance. Add it toshared_preload_librariesinpostgresql.conf, restart PostgreSQL, then run this in each database you monitor: -
Set the password variable for the agent. With the default environment variable mode and no instance name, the wizard reads
KM_SECRET_POSTGRESQL_PASSWORD. On Linux, add it to the agent’s environment file and restart the agent. See Database credentials. -
Open the wizard from the discovered PostgreSQL database. Turn on Query performance, Instance info, and Schema catalog, enter
localhost:5432as the endpoint andkmmonitoras the user, and click Save and apply.
The instance appears in the Databases module within a minute.