- Reference >
- MongoDB Package Components >
mongosniff
mongosniff¶
On this page
Synopsis¶
mongosniff provides a low-level operation tracing/sniffing view
into database activity in real time. Think of mongosniff as a
MongoDB-specific analogue of tcpdump for TCP/IP network
traffic. Typically, mongosniff is most frequently used in driver
development.
Note
mongosniff requires libpcap and is only available for
Unix-like systems.
As an alternative to mongosniff, Wireshark, a popular
network sniffing tool is capable of inspecting and parsing the MongoDB
wire protocol.
Options¶
-
mongosniff¶
-
--help¶ Returns information on the options and use of mongosniff.
-
--forward<host><:port>¶ Declares a host to forward all parsed requests that the mongosniff intercepts to another
mongodinstance and issue those operations on that database instance.Specify the target host name and port in the
<host><:port>format.To connect to a replica set, specify the
replica set nameand a seed list of set members. Use the following form:
-
--source<NET [interface]>,<FILE[filename]>,<DIAGLOG[filename]>¶ Specifies source material to inspect. Use
--source NET [interface]to inspect traffic from a network interface (e.g.eth0orlo.) Use--source FILE [filename]to read captured packets in pcap format.
-
--objcheck¶ Displays invalid BSON objects only and nothing else. Use this option for troubleshooting driver development. This option has some performance impact on the performance of mongosniff.
-
<port>¶ Specifies alternate ports to sniff for traffic. By default, mongosniff watches for MongoDB traffic on port
27017. Append multiple port numbers to the end of mongosniff to monitor traffic on multiple ports.
Use¶
Use the following command to connect to a mongod or
mongos running on port 27017 and 27018 on the localhost
interface:
Use the following command to only log invalid BSON objects for
the mongod or mongos running on the localhost
interface and port 27018, for driver development and troubleshooting:
Build mongosniff¶
To build mongosniff yourself, Linux users can use the following
procedure:
Obtain prerequisites using your operating systems package management software. Dependencies include:
libpcap- to capture network packets.git- to download the MongoDB source code.sconsand a C++ compiler - to buildmongosniff.
Download a copy of the MongoDB source code using
git:Issue the following sequence of commands to change to the
mongo/directory and buildmongosniff:
Note
If you run scons mongosniff before installing libpcap you
must run scons clean before you can build mongosniff.