Real-time Query Analytics for MongoDB¶
Use Real-time Query Analytics (RTA) to see what your MongoDB services are doing right now. RTA shows the operations that are running, so you can find the ones that are slow, scanning whole collections or waiting for a lock.
RTA also supports MySQL, Percona Server for MySQL and MariaDB, but shows different data for them. For those services, follow the MySQL instructions instead.
Choose between RTA and QAN¶
Use RTA when you’re troubleshooting a problem as it happens. For example, if your application slows down or stops responding, RTA shows you the operations that are running, how long they’ve been running and where they come from.
Query Analytics (QAN) works differently. It stores metrics for queries after they finish, so you can find slow, frequent or resource-intensive queries and spot trends over time. Because it relies on finished queries, QAN can’t show you what’s stuck right now.
In short, use QAN to understand query performance over time, and RTA to investigate what’s happening right now.
Prerequisites¶
Check the service requirements¶
RTA needs at least one MongoDB service monitored by PMM. If you haven’t set one up yet, connect MongoDB to PMM.
You need:
- PMM Client 3.7.0 or later on the monitored host. Run
pmm-admin statusto check. - A running MongoDB exporter for the service. RTA reuses its credentials, so you don’t need to configure anything else.
Check your role¶
Starting and stopping RTA sessions requires the Admin role. Users with other roles can view sessions that an Admin has already started.
To check what each role can do, review the standard role permissions.
Review privacy implications¶
RTA displays operations as MongoDB reports them, which may include:
- filter criteria and update values with sensitive information
- credentials passed in queries
- personal or confidential data used in query conditions
Any PMM user who can open the Query Analytics > Real-time page can see this data. Consider your security requirements before you use RTA in production.
RTA displays what MongoDB returns and exposes nothing beyond what db.currentOp() already provides.
Start an RTA session¶
You can start RTA from the PMM UI or from the command line:
To start monitoring a MongoDB service:
- Go to Query Analytics in the sidebar.
- Select the Real-time tab. If sessions are already running, the tab opens the sessions list. Click + New session there.
- Select a MongoDB service from the Cluster/Service drop-down and click Start session. The Real-time sessions list opens, with a row for each session you started.
- To open the live operations table, click the session’s name in the Session column. The table starts updating automatically.
- (Optional) To watch more services at once, for example all members of a replica set, select all of them in step 3. To add a service later, click All sessions, then + New session.
To start RTA on a specific MongoDB service from the command line:
- If you haven’t already, add the MongoDB service.
-
Get the IDs you need:
# Get your PMM Agent ID pmm-admin status # Get the MongoDB service ID pmm-admin inventory list services -
Prepare the command that adds the RTA agent. Unlike the UI, this command doesn’t reuse the exporter’s connection settings, so pass the MongoDB user and password:
pmm-admin inventory add agent rta-mongodb-agent <pmm-agent-id> <service-id> <mongodb-user> --password='<mongodb-password>' -
If the server requires TLS, add
--tlsand the certificate options to the command, such as--tls-ca-fileand--tls-certificate-key-file. -
Run the command. The output includes the RTA agent ID. Save it, because you need it to stop RTA later.
For all the options, see pmm-admin inventory add agent rta-mongodb-agent.
Find operations that need attention¶
When something is slow or stuck, start with the live operations table. It lists the operations running right now, with the longest-running ones at the top, so the most likely causes come first:

To find the operations behind your problem:
- Start at the top of the table. An operation with a high Elapsed time has been running for a long time and is a likely cause.
- If you’re watching several services, check Host to see which one the operation is running on.
- When you’ve found the operation, investigate it. If it has to stop right away, kill it.
Narrow down the operations¶
On a busy server, the live operations table can list many operations at once. To narrow it down to the ones behind your problem:
- If several sessions are running, select only the services you’re investigating in Cluster/Service. The view shows one database type at a time, so you can’t combine MongoDB and MySQL services in it.
- To find specific operations, click Show/Hide filters and filter by query text, or by a Min and Max elapsed time.
Pause the view¶
If an operation you want to check keeps moving or disappears on the next refresh, pause the view:
- Click Pause. The view stops updating, but PMM Client keeps collecting in the background.
- Check the operations you need. To see the latest data without resuming live updates, click Refresh. To keep a copy of what you see, export it.
- To go back to live updates, click Resume.
Control the refresh rate¶
Use Auto-refresh to adjust how often the view updates. The refresh rate only controls how often your browser reads the data that PMM Server already holds, so a faster refresh adds no load to your database.
PMM Client reads operations from the database at its own collect interval, every 2 seconds by default.
To change the collect interval:
- On the monitored host, run
pmm-admin listand find the agent ID of therta_mongodb_agent. -
Set the new interval, 1 second or more:
pmm-admin inventory change agent rta-mongodb-agent <agent-id> --collect-interval=5s
Investigate an operation¶
The Details tab of an operation shows what it’s doing and where it comes from:

To check an operation:
- Click the operation’s row. The view pauses while the pane is open, so the operation stays in place, and the Details tab shows the operation as it was when you clicked it. If live updates were running, they resume when you close the pane.
- To check whether the operation is still running, click Refresh. If it has finished, the pane says so.
- To see newer values for the operation, close the pane and click the row again.
Find out who sent an operation¶
Killing a problem operation helps only until it runs again. To fix it at the source, find the application or person behind it:
- In the operation’s Details tab, check Client app name, User name and Client address to find the application and host that sent it.
- Check Database name and Collection to see which part of your database it affects. If the same collection keeps showing up in slow operations, it may need better indexing.
Spot inefficient operations¶
A slow operation is often doing more work than it should. To find out why, check its Details tab:
- To check for a missing index, look at Plan summary.
COLLSCANmeans that the operation scanned the whole collection, which often means that an index is missing. - To check what kind of work it’s doing, look at Operation: query, insert, update or command. This tells you whether the slowdown comes from heavy writes, complex reads or unexpected administrative commands.
Find out when an operation started¶
To connect a slow operation with other events, such as a deployment, a traffic spike or an alert, compare its timestamps in the Details tab:
- Operation start time: when MongoDB started running the operation
- Data capture time: when PMM captured this snapshot
Check for lock contention¶
If operations seem stuck, check whether they’re waiting for a lock. In the operation’s Raw data tab, look for:
waitingForLock: true, which means that the operation is waiting for a locklocks, which shows the lock types the operation holds

Operations waiting for locks often point to write contention, or to a long-running operation that blocks others.
View raw data¶
View the raw data when you need a value that the Details tab doesn’t show, or want to confirm exactly what MongoDB reported. The raw data is the complete currentOp document for the operation, including the full command structure, driver version and platform details. These can help you find problems caused by outdated drivers or specific client configurations.
To view it, click the operation’s row and open the Raw data tab.
Stop a problematic operation¶
Killing an operation can leave data in an inconsistent state, so be careful, especially with writes. To stop an operation:
- Click the row to open the Details tab.
- Copy the Operation ID.
-
Connect to your MongoDB instance and run:
db.killOp(<operation_id>)
Export RTA data¶
You can export a snapshot of the current view to CSV. This captures operations that are still running and may never appear in QAN. For example, a long-running operation that’s killed before it finishes never reaches QAN, because QAN only records queries that finish.
To export the current view:
- Go to Query Analytics > Real-time.
- Click Pause.
- Apply any filters or sort order you want reflected in the export.
- Click Export.
The export includes all records across all pages and is saved as mongodb_rta_export_{timestamp}.csv.
Exported fields¶
The columns are generated from the query data that PMM returns, so the exact set depends on your PMM version. Most column names match the API field names. A few keep shorter names: operation_id, elapsed_exec_time_sec, service, user_name, data_capture_time and raw_query.
When a PMM version returns additional query data, the new columns are appended after the ones listed below. If you process the file automatically, match columns by header name rather than by position or column count.
A MongoDB export currently contains:
operation_id: unique identifier for the operationelapsed_exec_time_sec: how long the operation has been running, in secondsdb_instance_address: address of the MongoDB instanceclient_address: address of the client that sent the querydatabase_name: database the operation is running againstservice: PMM service nameuser_name: MongoDB user who issued the querycollection: collection the operation is targetingoperation: type of operation (query, insert, update, command)plan_summary: query plan summary (for example,COLLSCANorIXSCAN)client_app_name: name of the application that sent the queryoperation_start_time: when the database started executing this operationdata_capture_time: when PMM captured this snapshotraw_query: reconstructed query textservice_id: identifier of the PMM servicequery_text: query as shown in the Query text column
Share your view¶
To show a colleague what you’re looking at, click Share session settings in the page header. PMM copies a link that keeps your selected services, query text filter and page size.
The link opens live data with your filters applied, not the exact operations you were viewing, because RTA data updates continuously.
Stop an RTA session¶
Each running session adds load to the monitored database and to PMM Server, so stop sessions you no longer need.
Click All sessions in the Real-time view. To stop one session, click Stop next to it. To stop several, select them and click Stop selected, or click Stop all:

To stop RTA on a service, remove its RTA agent:
-
Find the RTA agent ID:
pmm-admin inventory list agents -
Remove the agent:
pmm-admin inventory remove agent <rta-agent-id>
This stops RTA for that service but doesn’t affect the MongoDB exporter or stored QAN metrics. To restart RTA, start a new session. For all the options, see pmm-admin inventory remove agent.
Troubleshooting¶
Session won’t start¶
When a session can’t start, its status shows Error.
For a cluster, the row shows how many of its services are running, for example 1 of 3 running. Hover over it to see the status of each service and the reason its agent reported. Unspecified means PMM can’t reach that service’s agent.
To fix it:
- Check the PMM Client version: run
pmm-admin statuson the monitored host. If PMM Client is older than 3.7.0, upgrade it. In that case, hovering over the Error status also shows the reason. - If PMM Client is up to date, find the reason in the pmm-agent log on the monitored host.
- Check the MongoDB exporter: go to Inventory > Services, click the Monitoring status of your MongoDB service, and check that the MongoDB exporter shows Running.
- Check your role: only users with the Admin role can start or stop sessions. If you’re not an Admin, ask one to start the session.
- Start the session again.
No operations appear¶
If the Real-time view stays empty, click All sessions and check the session’s status. If it shows Error, see Session won’t start.
If the session is running but the view is still empty, your database may have no operations that run long enough to catch. RTA sees only operations that are running at the moment PMM Client collects, so quick operations that start and finish between two collections never show up. To catch them, lower the collect interval, as described in Control the refresh rate. The interval can’t be shorter than 1 second, so use Query Analytics for shorter operations.
Some fields show “Unavailable”¶
Not every operation has every field. For example, a hello command, which works like a ping, has no Collection, User name or Plan summary.
The query text looks different from what I sent¶
MongoDB’s currentOp() doesn’t return the original query text, so RTA reconstructs it from the command structure. To see exactly what MongoDB returned, check the Raw data tab.