Database Reference
In-Depth Information
Writing a plug-in for any arbitrary monitoring application isn't difficult. It mostly
involves running various statistics commands against a live MongoDB database. The
serverStatus , dbstats , and collstats commands usually provide all the informa-
tion you might need, and you can get all of them straight from the HTTP REST inter-
face, avoiding the need for a driver.
10.2.4
Diagnostic tools (mongosniff, bsondump)
MongoDB includes two diagnostic utilities. The first is mongosniff , which sniffs pack-
ets from a client to the MongoDB server and prints them intelligibly. If you happen to
be writing a driver or debugging an errant connection, then this is your hammer. You
can start it up like this to listen on the local network interface at the default port:
sudo mongosniff --source NET I0
Then when you connect with any client, say the MongoDB shell, you'll get an easy-to-
read stream of network chatter:
127.0.0.1:58022 -->> 127.0.0.1:27017 test.$cmd 61 bytes
id:89ac9c1d 2309790749 query: { isMaster: 1.0 } ntoreturn: -1
127.0.0.1:27017 <<-- 127.0.0.1:58022 87 bytes
reply n:1 cursorId: 0 { ismaster: true, ok: 1.0 }
You can see all the mongosniff options by running it with --help .
Another useful utility is bsondump , which allows you to examine raw BSON files.
BSON files are generated by the mongodump utility (discussed later) and by replica set
rollbacks. 8 For instance, let's say you've dumped a collection with a single document.
If that collection ends up in a file called users.bson , then you can examine the con-
tents pretty easily:
$ bsondump users.bson
{ "_id" : ObjectId( "4d82836dc3efdb9915012b91" ), "name" : "Kyle" }
As you can see, bsondump prints the BSON as JSON by default. If you're doing serious
debugging, you'll want to see the real composition of BSON types and sizes. For that,
run the utility in debug mode:
$ bsondump --type=debug users.bson
--- new object ---
size : 37
_id
type: 7 size: 17
name
type: 2 size: 15
This gives you the total size of the object (37 bytes), the types of the two fields (7 and 2),
and those fields' sizes.
8
There may be other situations where you'll find raw BSON, but MongoDB's data files aren't one of them, so
don't try to view them with bsondump .
Search WWH ::




Custom Search