2

I'm able to see queries in MongoDB, but I've tried to see what writes are being performed on a MongoDB database without success.

My application code doesn't have any write commands in it. Yet, when I load test my app, I'm seeing a whole bunch of writes in mongostat. I'm not sure where they're coming from.

Aside from logging writes (which I'm unable to do), are there any other methods that I can use to determine where those writes are coming from?

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • Abstract your writes using a middle man class, so all write go through one class and put logging in there. – Pete Garafano Sep 06 '13 at 17:48
  • There are no writes in the app code. – Homer6 Sep 06 '13 at 17:50
  • Please share details shown by mongostat to give us more insight into your problem – Nilesh Rajani Sep 06 '13 at 18:02
  • @NileshRajani I will share that shortly. I actually have a separate issue of MongoDB dying, which I wanted to keep as a separate SO question. – Homer6 Sep 06 '13 at 18:12
  • @NileshRajani I've posted the second question (with the mongostat output) here: http://stackoverflow.com/questions/18664166/why-is-mongodb-unresponsive-during-a-load-test Thank you for your assistance. – Homer6 Sep 06 '13 at 18:23

3 Answers3

4

You have a few options that I'm aware of:

a) If you suspect that the writes are going to a particular database, you can set the profiling level to 2 to log all queries

use [database name]
db.setProfilingLevel(2)
...
// disable when done
db.setProfilingLevel(0) 

b) You can start the database with various levels of versbosity using -v

  -v [ --verbose ]            be more verbose (include multiple times for more
                              verbosity e.g. -vvvvv)

c) You can use mongosniff to sniff the port

d) If you're using replication, you could also check the local.oplog.rs collection

jeffl
  • 446
  • 3
  • 2
  • I had tried the profiling level via the mongod command line arguments. However, that apparently didn't stick. When I went into the database, as you've suggested, db.getProfilingLevel() still equals 0. Setting it to 2 via db.setProfilingLevel(2) does stick, however it still does not log the writes. I'm not using replication. Mongosniff is not built on my version (I'm using mongo v1.8.2). I'm afraid that building a newer version would alter my results/stack/etc (ie. it's not that viable). Do you know, at which version, mongosniff was introduced? – Homer6 Sep 06 '13 at 18:09
  • Ouch...well, aside from the obligatory "you really should upgrade", I believe mongosniff was introduced in 2.x. Are you saying that the hundreds of inserts from the mongostat you posted in the other thread are not from your load test? When you say that the writes are not logged, where are you looking? db.system.profile or the logfile? – jeffl Sep 06 '13 at 19:10
  • I was looking in the logfile (but db.system.profile is empty too). Those writes are only from my load test. I can't explain them. I'm actually looking into upgrading too now, as obligatory as it may seem, it might be my best course of action. – Homer6 Sep 06 '13 at 19:43
  • Upgrading didn't help. Sorry, I still can't see the writes. I'm going to try mongosniff to see if it works (now that I have a different version). – Homer6 Sep 06 '13 at 20:18
2

I've tried all of jeffl's suggestions, and one of them was able to show me the writes: mongosniff. Thanks jeffl!

Here are the commands that I used to install mongosniff on my Ubuntu 10 box, in case someone else finds this useful:

git clone git://github.com/mongodb/mongo.git
cd mongo
git checkout r2.4.6
apt-get install scons libpcap-dev g++
scons mongosniff
build/linux2/normal/mongo/mongosniff --source NET lo 27017
Homer6
  • 15,034
  • 11
  • 61
  • 81
1

I made a command line tool to see the logs, and also activate the profiler activity first without the need of others client tools: "mongotail".

To activate the log profiling to level 2:

mongotail databasename -l 2

Then to show the latest 10 queries:

mongotail databasename

Also you can use the tool with the -f option, to see the changes in "real time".

mongotail databasename -f

And finally, filter the result with egrep to find a particular operation, like only show writes operations:

mongotail databasename -f | egrep "(INSERT|UPDATE|REMOVE)"

See documentation and installation instructions in: https://github.com/mrsarm/mongotail

Mariano Ruiz
  • 4,314
  • 2
  • 38
  • 34
  • Great job on assembling this package. It looks very well constructed. Thanks for contributing! – Homer6 Feb 27 '15 at 19:46