title: Measure CPU/RAM Usage while querying in MongoDB
body: <p>I have a database set up on MongoDB and I want to calculate the CPU and RAM usage for various queries.</p>
  
  <p>I'm trying to use the psutil library to do this. Here is one such example :</p>
  
  <pre><code>process = psutil.Process(44083) # Got the pid of mongod running by ps aux | grep mongod
  
  mem_usage = process.memory_info()[0]
  cpu_usage = process.cpu_percent()
  print mem_usage, cpu_usage
  
  cursor = db.production.find({'key':value})
  
  mem_usage = process.memory_info()[0]
  cpu_usage = process.cpu_percent()
  print mem_usage, cpu_usage
  </code></pre>
  
  <p>Is this the correct way to get the desired metrics?</p>