In this recipe, we will take a look at the mongostat
utility, which is bundled with standard MongoDB binary distributions. This tool gives good insights into MongoDB utilization and is also capable of being used programmatically.
- Connect to you mongod instance and run a bunch of inserts, updates, and deletes:
use mydb for(var x=0; x<20000; x++){ db.mycol.insert({age:(Math.round(Math.random()*100)%20)}); db.mycol.findAndModify({query: {age: (Math.round(Math.random()*100)%20)}, update:{$inc: {age: 2}}}); db.mycol.remove({age:(Math.round(Math.random()*100)%20)}); }
- In a separate Terminal, execute the
mongostat
command. You should see output similar to this:
- Execute
mongostat
to only give the insert rate and count:
mongostat -o 'host,metrics.document.inserted.rate()=insert_rate,metrics.document.inserted=inserted_count'
- You should see output similar...