MongoDB Integration

The MongoDB integration ingests performance and health metrics from your MongoDB instances into Middleware. This way, you can track connections, operations, index/storage usage, network I/O, locks, and more in dashboards and alerts.

Prerequisites

The Middleware Host Agent must be installed on the host that can reach your MongoDB instance(s). If you haven't installed it yet, follow the Middleware Installation Guide first.

MongoDB Profiling Setup

Before configuring the Middleware integration, you need to set up MongoDB profiling to enable query performance monitoring.

Create a user with profiling permissions

Create a user in the admin database with profiling permissions:

1use admin
2db.createUser({
3  user: "otelProfiler",
4  pwd: "StrongPasswordHere",
5  roles: [
6    { role: "dbAdminAnyDatabase", db: "admin" },   // can manage profiling in all DBs
7    { role: "clusterMonitor", db: "admin" }        // can read monitoring info
8  ]
9})

Test the profiling setup

Log in with the new user and test the profiling configuration:

1mongo -u otelProfiler -p StrongPasswordHere --authenticationDatabase admin

Once connected, test profiling on a database:

1use mydb
2db.setProfilingLevel(2)   // enables full profiling
3db.getProfilingStatus()

If profiling is enabled correctly, you should see output similar to this:

1testdb> db.getProfilingStatus()
2{ was: 2, slowms: 1, sampleRate: 1, ok: 1 }

Setup

1 Create database credentials (YAML)

Create a credentials file on the host running the Middleware Host Agent. If your database is not password-protected, you may omit the username and password fields. Docker users should create this file under /var/log. Example: /home/ubuntu/mongodb-creds.yaml

1mongodb:
2  hosts:
3    - endpoint: localhost:27017
4  username: mongodb
5  password: mongodb
6  profiling_level: 1
7  slow_ms: 10

Here:

  • profiling_level controls MongoDB profiler behavior:
    • 0 disables profiling,
    • 1 profiles queries slower than slow_ms (ms),
    • 2 profiles all queries. slow_ms is only used when profiling_level is 1.

Config Attributes:

AttributeDescription
endpointEndpoint for MongoDB connection. Required.
usernameUsername for MongoDB connection. Required if your DB requires auth.
passwordPassword for MongoDB connection. Required if your DB requires auth.
profiling_levelProfiler level: 0, 1, or 2. 0 disables profiling; 1 uses slow_ms; 2 profiles all queries. Optional.
slow_msSlow-query threshold in ms (used only when profiling_level: 1). Optional.

Tip: Keep this file readable by the agent only (e.g., restrict filesystem permissions) and ensure the host can reach the MongoDB endpoint. (The official doc calls out the fields and their meanings; this tip simply makes the usage explicit.)

2 Open the integration in Middleware

In the Middleware app, go to Installations → All Integrations → MongoDB. This opens the MongoDB integration form.

MongoDB Overview

3 Enable the integration

In the MongoDB integration form:

  1. Add/Select the host (the one where you created the YAML).
  2. Paste the credentials file path from Step 1.
  3. Click Save.
MongoDB Host

After saving, the integration begins ingesting metrics; a default dashboard will appear (give it a few minutes if you’ve just connected).

Visualize Analytics

Default MongoDB Dashboard

Once the integration is enabled, a MongoDB dashboard is added under Dashboard Builder. Use it to validate the setup and start exploring key metrics without building widgets from scratch.

MongoDB Dashbaord

Create a Custom MongoDB Widget

When creating a new dashboard widget, select the mongodb data source to browse the full list of MongoDB metrics and build charts aligned to your SLOs.

Alerts

You can alert on any MongoDB metric. Create a rule with 'Database' as the detection method and 'MongoDB' as the database type; the 'Metrics' dropdown will list all MongoDB metrics. Choose your metric, set conditions/thresholds, and add recipients.

Metrics Collected

Inventory & Storage

Metric NameDescription
mongodb.database.countNumber of existing databases
mongodb.collection.countNumber of collections
mongodb.object.countNumber of objects
mongodb.data.sizeSize of the collection; data compression does not affect this value
mongodb.storage.sizeTotal amount of storage allocated to this collection
mongodb.index.countNumber of indexes
mongodb.index.sizeTotal space allocated to all database indexes, including free index space
mongodb.extent.countNumber of extents

Connections, Sessions & Cursors

Metric NameDescription
mongodb.connection.countNumber of connections
mongodb.session.countTotal number of active sessions
mongodb.cursor.countNumber of opened cursors maintained for clients
mongodb.cursor.timeout.countNumber of cursors that have timed out

Operations & Profiling

Metric NameDescription
mongodb.operation.countNumber of operations executed
mongodb.operation.repl.countNumber of replicated operations executed
mongodb.document.operation.countNumber of document operations executed
mongodb.operation.timeTotal time spent performing operations
mongodb.operation.latency.timeTotal latency of operations

Index Usage

Metric NameDescription
mongodb.index.access.countNumber of times an index has been accessed

Network

Metric NameDescription
mongodb.network.io.receiveNumber of bytes received
mongodb.network.io.transmitNumber of bytes transmitted
mongodb.network.request.countNumber of requests received by a server

Locks & Concurrency

Metric NameDescription
mongodb.global_lock.timeTotal time the global lock has been held
mongodb.lock.acquire.countNumber of times a lock was acquired in the specified mode
mongodb.lock.acquire.wait_countNumber of times lock acquisitions encountered waits due to locks held in conflicting modes
mongodb.lock.acquire.timeCumulative wait time for the lock acquisitions
mongodb.lock.deadlock.countNumber of times lock acquisitions encountered deadlocks

Cache & Memory

Metric NameDescription
mongodb.cache.operationsNumber of cache operations
mongodb.memory.usageAmount of memory used

Health & Uptime

Metric NameDescription
mongodb.healthHealth status of the server
mongodb.uptimeAmount of time the server has been running

Troubleshooting

“Integrations” menu not visible

If Integrations isn’t visible in Middleware, your user role likely lacks Installation permissions. Ask an administrator to add Installation permission to your role in Settings.

Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.