MongoDB is an open source, NoSQL, document-oriented database system. The MongoDB plugin allows you to monitor your databases running on your instances.
Even if you don't configure the MongoDB plugin, Stackdriver Monitoring discovers MongoDB services running in your Google Cloud Platform project by:
- Searching instance names for mongodb
- Checking for ports opened to 27017, 27018, or 27019 via firewall rules
These discovered services appear on the MongoDB Services page in the Resources menu. After you install the monitoring agent and the MongoDB plugin on your instances, Stackdriver Monitoring populates the MongoDB Services page with inventory and metrics.
Configuring Stackdriver Monitoring to monitor MongoDB
After you install the monitoring agent, configure the MongoDB plugin on your instances.
For a MongoDB database with access roles (configured to run in "auth" mode), you
must configure a user with the clusterMonitor role on the admin database.
This user and password are referred to as
STATS_PASS in the
In "noauth" mode, any program that can connect to the MongoDB server can run arbitrary queries and commands on it. Therefore, "noauth" mode is generally considered less safe. When your database runs in "noauth" mode, you don't need any credentials in the plugin configuration file.
Enabling the MongoDB monitoring plugin
If you want to monitor a cluster of multiple MongoDB servers (one primary and one or more secondaries), the monitoring agent should be installed on each node in the cluster.
cd /opt/stackdriver/collectd/etc/collectd.d/ && curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mongodb.conf
To run MongoDB in "auth" mode, edit the configuration file and replace
STATS_PASSwith the correct username and password.
Make other configuration changes, such as Port or Host, as needed.
When finished, restart the monitoring agent:
sudo service stackdriver-agent restart
You can find additional information about plugin configuration options at collectd.org.
What is monitored
The MongoDB plugin monitors the following metrics:
- Current Connections (count): The number of active connections to MongoDB.
- Global Lock Hold Time (ms): How long the global lock has been held.
- Mapped Memory (bytes): The amount of mapped memory used by MongoDB. This is roughly equivalent to the total size of your databases, due to the use of memory mapped files.
- Virtual Memory (bytes): The amount of virtual memory used by MongoDB. If the virtual memory size is significantly larger than mapped memory size (e.g. 3 or more times), this may indicate a memory leak.
- Resident Memory (bytes): The amount of resident memory that is used by MongoDB. This is the amount of RAM being physically used by the databases.
- Operations [command, delete, getmore, insert, query, update] (count/s): The number of [command, delete, getmore, insert, query, update] operations executed per second.
- Database [Collection, Index, Object, Extents] Count (count): The number of [collections, indices, objects, extents] currently in the database.
- Database Data Size (bytes): The size of the data currently in the database.
- Database Storage Size (bytes): The size of the storage currently allocated to the database.
- Database Index Size (bytes): The size of the index for the database.
For details, see Agent metrics list: MongoDB.