<page xmlns="http://projectmallard.org/1.0/"
      type="topic"
      id="basic-troubleshooting">

    <section id="basic-troubleshooting">
      <info>
        <link type="guide" xref="index#debugging" />
      </info>

      <title>Basic Troubleshooting</title>

      <p>The following is a short list of things to check when you have a problem.</p>

      <list>
        <item><p>Did you call <code>mongoc_init()</code> in <code>main()</code>? If not, you will likely see a segfault.</p></item>
        <item><p>Have you leaked any clients or cursors as can be found with <cmd>mongoc-stat <var>PID</var></cmd>?</p></item>
        <item><p>Have packets been delivered to the server? See egress bytes from <cmd>mongoc-stat <var>PID</var></cmd>.</p></item>
        <item><p>Does <code>valgrind</code> show any leaks? Ensure you call <code>mongoc_cleanup()</code> at the end of your process to cleanup lingering allocations from the MongoDB C driver.</p></item>
        <item><p>If compiling your own copy of MongoDB C driver, consider configuring with <code>--enable-tracing</code> to enable function tracing and hex dumps of network packets to <code>STDERR</code> and <code>STDOUT</code>.</p></item>
      </list>

    </section>

    <section id="perf-counters">
      <info>
        <link type="guide" xref="index#debugging" />
      </info>

      <title>Performance Counters</title>

      <p>
        The MongoDB C driver comes with a unique feature to help developers and sysadmins troubleshoot problems in production.
        Performance counters are available for each process using the driver.
        The counters can be accessed outside of the application process via a shared memory segment.
        This means that you can graph statistics about your application process easily from tools like Munin or Nagios.
        Your author often uses <code>watch --interval=0.5 -d mongoc-stat $PID</code> to monitor an application.
      </p>

      <note><p>Counters are currently available on UNIX-like platforms that support shared memory segments.</p></note>

      <list>
        <title>Available Counters</title>
        <item><p>Active and Disposed Cursors</p></item>
        <item><p>Active and Disposed Clients, Client Pools, and Socket Streams.</p></item>
        <item><p>Number of operations sent and received, by type.</p></item>
        <item><p>Bytes transferred and received.</p></item>
        <item><p>Authentication successes and failures.</p></item>
        <item><p>Number of wire protocol errors.</p></item>
      </list>

      <p>To access counters for a given process, simply provide the process id to the <code>mongoc-stat</code> program installed with the MongoDB C Driver.</p>

      <screen><output style="prompt">$ </output><input>mongoc-stat 22203</input><![CDATA[
   Operations : Egress Total        : The number of sent operations.                    : 13247
   Operations : Ingress Total       : The number of received operations.                : 13246
   Operations : Egress Queries      : The number of sent Query operations.              : 13247
   Operations : Ingress Queries     : The number of received Query operations.          : 0
   Operations : Egress GetMore      : The number of sent GetMore operations.            : 0
   Operations : Ingress GetMore     : The number of received GetMore operations.        : 0
   Operations : Egress Insert       : The number of sent Insert operations.             : 0
   Operations : Ingress Insert      : The number of received Insert operations.         : 0
   Operations : Egress Delete       : The number of sent Delete operations.             : 0
   Operations : Ingress Delete      : The number of received Delete operations.         : 0
   Operations : Egress Update       : The number of sent Update operations.             : 0
   Operations : Ingress Update      : The number of received Update operations.         : 0
   Operations : Egress KillCursors  : The number of sent KillCursors operations.        : 0
   Operations : Ingress KillCursors : The number of received KillCursors operations.    : 0
   Operations : Egress Msg          : The number of sent Msg operations.                : 0
   Operations : Ingress Msg         : The number of received Msg operations.            : 0
   Operations : Egress Reply        : The number of sent Reply operations.              : 0
   Operations : Ingress Reply       : The number of received Reply operations.          : 13246
      Cursors : Active              : The number of active cursors.                     : 1
      Cursors : Disposed            : The number of disposed cursors.                   : 13246
      Clients : Active              : The number of active clients.                     : 1
      Clients : Disposed            : The number of disposed clients.                   : 0
      Streams : Active              : The number of active streams.                     : 1
      Streams : Disposed            : The number of disposed streams.                   : 0
      Streams : Egress Bytes        : The number of bytes sent.                         : 794931
      Streams : Ingress Bytes       : The number of bytes received.                     : 589694
      Streams : N Socket Timeouts   : The number of socket timeouts.                    : 0
 Client Pools : Active              : The number of active client pools.                : 1
 Client Pools : Disposed            : The number of disposed client pools.              : 0
     Protocol : Ingress Errors      : The number of protocol errors on ingress.         : 0
         Auth : Failures            : The number of failed authentication requests.     : 0
         Auth : Success             : The number of successful authentication requests. : 0
]]></screen>

    </section>

    <section id="file-bug">
      <info>
        <link type="guide" xref="index#debugging" />
      </info>

      <title>Submitting a Bug Report</title>

      <p>Think you’ve found a bug? Want to see a new feature in the MongoDB C driver? Please open a case in our issue management tool, JIRA:</p>

      <list>
        <item><p><link href="https://jira.mongodb.org">Create an account and login</link>.</p></item>
        <item><p>Navigate to <link href="https://jira.mongodb.org/browse/CDRIVER">the CDRIVER project</link>.</p></item>
        <item><p>Click <em>Create Issue</em> - Please provide as much information as possible about the issue type and how to reproduce it.</p></item>
      </list>

      <p>Bug reports in JIRA for all driver projects (i.e. CDRIVER, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are <em>public</em>.</p>

    </section>

</page>
