We use cookies or similar technologies to personalize your online experience and tailor marketing to you. Many of our product features require cookies to function properly. Your use of this site and online product constitutes your consent to these personalization technologies. Read our Privacy Policy to find out more.

X

External database statistics

While Mongo’s log files have a plethora of useful information and statistics, some information can’t be captured on a per-operation basis—metadata that captures the high-level health or behavior of a MongoDB instance. This data includes overall active lock count, queue length, master status, and system-level stats.

To that end, we’ve written an example script that can be run via cron, in order to actively poll a specific MongoDB instance and collect these statistics at regular intervals for collection by Honeycomb.

The script can be found on GitHub in our mongodbtools repository and is highly recommended for monitoring production MongoDB clusters. It’s customizable for your specific cluster and concerns.

Usage

Our script simply uses the mongo shell to capture and format the output of useful commands.

wget -q https://raw.githubusercontent.com/honeycombio/mongodbtools/master/scripts/mongo_stats.sh
chmod 755 mongo_stats.sh
./mongo_stats.sh YOUR_API_KEY  MongoDB locahost:27017

You are currently logged in to the team, so we have populated the write key here to the first write key for that team.

Note: While the field names collected by this script differ from those collected by the logs parser or the tcp collector, we highly recommend using the same dataset name here. Interleaving these two different types of events will provide a richer and more interesting set of analyses over your MongoDB cluster.

Example statistics

field name type value
ismaster bool true
version string 3.4.1
queue_size float 1
indexes_running float 0
nonyielding_running float 0
slow_queries_running float 0
hostname string localhost:27017
global_read_locks_per_sec float 6800.8454
global_write_locks_per_sec float 4090.6268
global_Write_locks_per_sec float 0
admin_read_locks_per_sec float 1355.04326
admin_Read_locks_per_sec float 0
admin_write_locks_per_sec float 4090.3626
admin_Write_locks_per_sec float 0
mycollection_read_locks_per_sec float 1354.9111
mycollection_Read_locks_per_sec float 0
mycollection_write_locks_per_sec float 4089.9663
mycollection_Write_locks_per_sec float 0
cpu_user float 2
cpu_system float 32
cpu_idle float 66
cpu_wait float 0
cpu_steal float 0

Note: MongoDB statistics and shell methods (and the information returned by the above) vary between different MongoDB versions. The fields extracted from your MongoDB log output may differ from those shown above, and we recommend customizing the provided example script to match your MongoDB version and specific needs.

Numbers are ingested as floats by default in Honeycomb, though you can coerce a field to integers in the Schema section of your dataset’s Overview.