Skip to content

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.

  • 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.

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.

  1. 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.

  2. 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.

  3. Choose coverages. Standard metrics is always on. Turn on the others you need. See Engines and coverages.

  4. Run the setup steps the wizard shows on the database, such as creating the monitoring user and its grants.

  5. 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.

  6. Click Save and apply. Data starts arriving within a minute.

  1. Create the monitoring user in PostgreSQL:

    CREATE USER kmmonitor WITH PASSWORD 'YOUR_PASSWORD';
    GRANT pg_monitor TO kmmonitor;
  2. Enable pg_stat_statements for query performance. Add it to shared_preload_libraries in postgresql.conf, restart PostgreSQL, then run this in each database you monitor:

    CREATE EXTENSION pg_stat_statements;
  3. 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.

  4. Open the wizard from the discovered PostgreSQL database. Turn on Query performance, Instance info, and Schema catalog, enter localhost:5432 as the endpoint and kmmonitor as the user, and click Save and apply.

The instance appears in the Databases module within a minute.