@@ -67,7 +67,7 @@ A command event is an event related to a MongoDB database command. Some
67
67
examples of database commands that produce command events are ``find``,
68
68
``insert``, ``delete``, and ``count``.
69
69
70
- To monitor command events, write a class that implements the
70
+ To monitor command events, create a class that implements the
71
71
``CommandListener`` interface and register an instance of that class with your
72
72
``MongoClient`` instance.
73
73
@@ -78,8 +78,8 @@ For more information on MongoDB database commands, see the
78
78
79
79
The driver does not publish events for commands it calls internally. This
80
80
includes database commands the driver uses to monitor your cluster and
81
- commands related to connection establishment ( such as the initial ``hello``
82
- command) .
81
+ commands related to connection establishment, such as the initial ``hello``
82
+ command.
83
83
84
84
.. important:: Redacted Output
85
85
@@ -93,19 +93,15 @@ Example
93
93
94
94
This example shows how to make a counter for database commands. The counter
95
95
keeps track of the number of times the driver successfully executes each database
96
- command, and prints this information every time a database command finishes.
96
+ command and prints this information every time a database command finishes.
97
97
98
- To make a counter, do the following :
98
+ To make a counter, follow these steps :
99
99
100
100
#. Make a class with counter functionality that implements the ``CommandListener`` interface.
101
- #. Add an instance of the new class that implements ``CommandListener`` to a ``MongoClientSettings`` object.
102
- #. Configure a ``MongoClient`` instance with the ``MongoClientSettings`` object.
101
+ #. Add an instance of the new class to a ``MongoClientSettings`` object.
102
+ #. Configure you ``MongoClient`` instance with the ``MongoClientSettings`` object.
103
103
104
- The following code defines the ``CommandCounter`` class which implements the
105
- ``CommandListener`` interface, then adds an instance of the ``CommandCounter`` class to a
106
- ``MongoClientSettings`` object. Then it configures a ``MongoClient`` instance with the
107
- ``MongoClientSettings`` object. The code then runs some database commands to test the
108
- counter:
104
+ The following code implements these steps:
109
105
110
106
.. _listener-mongo-client-settings-example:
111
107
@@ -116,38 +112,38 @@ counter:
116
112
117
113
.. output::
118
114
:language: console
115
+ :visible: false
119
116
120
117
{find=1}
121
118
{find=2}
122
119
{find=2, endSessions=1}
123
120
124
121
For more information on the classes and methods mentioned in this section, see
125
- the following API Documentation :
122
+ the following API documentation :
126
123
127
- - `CommandListener <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/CommandListener.html>`__
128
- - `MongoClientSettings <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/MongoClientSettings.html>`__
124
+ - `CommandListener <{+api+}/com/mongodb/event/CommandListener.html>`__
125
+ - `MongoClientSettings <{+api+}/com/mongodb/MongoClientSettings.html>`__
129
126
- `MongoClient <{+api+}/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
130
- - `CommandStartedEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/CommandStartedEvent.html>`__
131
- - `CommandSucceededEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/CommandSucceededEvent.html>`__
132
- - `CommandFailedEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/CommandFailedEvent.html>`__
127
+ - `CommandStartedEvent <{+api+}/com/mongodb/event/CommandStartedEvent.html>`__
128
+ - `CommandSucceededEvent <{+api+}/com/mongodb/event/CommandSucceededEvent.html>`__
129
+ - `CommandFailedEvent <{+api+}/com/mongodb/event/CommandFailedEvent.html>`__
133
130
134
131
Server Discovery and Monitoring Events
135
132
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
133
137
134
A server discovery and monitoring (SDAM) event is an event related to a change
138
135
in the state of the MongoDB instance or cluster you have connected the driver to.
139
136
140
- The driver defines nine SDAM events. The driver divides these nine events
141
- between three separate listener interfaces which each listen for three of the
142
- nine events. Here are the three interfaces and the events they listen for:
137
+ The driver defines nine SDAM events and provides the following listener
138
+ interfaces, which listen for three SDAM events each:
143
139
144
140
- ``ClusterListener``: topology-related events
145
141
- ``ServerListener``: events related to ``mongod`` or ``mongos`` processes
146
142
- ``ServerMonitorListener``: heartbeat related events
147
143
148
- To monitor a type of SDAM event, write a class that
149
- implements one of the three preceding interfaces and register an instance of that
150
- class with your ``MongoClient`` instance.
144
+ To monitor a type of SDAM event, create a class that implements one of the three
145
+ preceding interfaces and register an instance of that class with your
146
+ ``MongoClient`` instance.
151
147
152
148
For a detailed description of each SDAM event, see the :spec:`MongoDB SDAM monitoring events specification </server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.md>`.
153
149
@@ -157,10 +153,14 @@ Example
157
153
This example shows how to make a listener class that prints a message that lets
158
154
you know if the driver can write to your MongoDB instance.
159
155
160
- The following code defines the ``IsWritable`` class which implements the
161
- ``ClusterListener`` interface. Then it adds an instance of the ``IsWritable`` class to a
162
- ``MongoClient`` object. The code then runs a find operation to test the
163
- ``IsWritable`` class:
156
+ To make an event that reports write status:
157
+
158
+ #. Make a class that tracks and checks cluster description changes, and
159
+ implements the ``CommandListener`` interface.
160
+ #. Add an instance of the new class to a ``MongoClientSettings`` object.
161
+ #. Configure your ``MongoClient`` instance with the ``MongoClientSettings`` object.
162
+
163
+ The following code implements these steps:
164
164
165
165
.. io-code-block::
166
166
@@ -169,29 +169,30 @@ The following code defines the ``IsWritable`` class which implements the
169
169
170
170
.. output::
171
171
:language: console
172
+ :visible: false
172
173
173
174
Able to write to server
174
175
175
176
For more information on the classes and methods mentioned in this section, see
176
- the following API Documentation :
177
+ the following API documentation :
177
178
178
- - `ClusterListener <{+api+}/apidocs/mongodb-driver-core /com/mongodb/event/ClusterListener.html>`__
179
- - `ServerListener <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ServerListener.html>`__
180
- - `ServerMonitorListener <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ServerMonitorListener.html>`__
181
- - `MongoClientSettings <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/MongoClientSettings.html>`__
179
+ - `ClusterListener <{+core- api+}/com/mongodb/event/ClusterListener.html>`__
180
+ - `ServerListener <{+api+}/com/mongodb/event/ServerListener.html>`__
181
+ - `ServerMonitorListener <{+api+}/com/mongodb/event/ServerMonitorListener.html>`__
182
+ - `MongoClientSettings <{+api+}/com/mongodb/MongoClientSettings.html>`__
182
183
- `MongoClient <{+api+}/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
183
- - `ClusterDescriptionChangedEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ClusterDescriptionChangedEvent.html>`__
184
+ - `ClusterDescriptionChangedEvent <{+api+}/com/mongodb/event/ClusterDescriptionChangedEvent.html>`__
184
185
185
186
Connection Pool Events
186
187
~~~~~~~~~~~~~~~~~~~~~~
187
188
188
189
A connection pool event is an event related to a **connection pool** held by the driver.
189
190
A connection pool is a set of open TCP connections your driver maintains with
190
191
a MongoDB instance. Connection pools help reduce the number of network handshakes
191
- your application performs with a MongoDB instance, and can help your
192
+ your application performs with a MongoDB instance and can help your
192
193
application run faster.
193
194
194
- To monitor connection pool events, write a class that implements the
195
+ To monitor connection pool events, create a class that implements the
195
196
``ConnectionPoolListener`` interface and register an instance of that class with your
196
197
``MongoClient`` instance.
197
198
@@ -201,10 +202,13 @@ Example
201
202
This example shows how to make a listener class that prints a message each time
202
203
you check out a connection from your connection pool.
203
204
204
- The following code defines the ``ConnectionPoolLibrarian`` class which implements the
205
- ``ConnectionPoolListener`` interface. Then it adds an instance of the
206
- ``ConnectionPoolLibrarian`` class to a ``MongoClient`` object. The code then
207
- runs a database command to test the librarian.
205
+ To make an event that reports connection checkouts:
206
+
207
+ #. Make a class that tracks checkouts and implements the ``CommandListener`` interface.
208
+ #. Add an instance of the new class to a ``MongoClientSettings`` object.
209
+ #. Configure your ``MongoClient`` instance with the ``MongoClientSettings`` object.
210
+
211
+ The following code implements these steps:
208
212
209
213
.. io-code-block::
210
214
@@ -213,17 +217,18 @@ runs a database command to test the librarian.
213
217
214
218
.. output::
215
219
:language: console
220
+ :visible: false
216
221
217
222
Let me get you the connection with id 21...
218
223
219
224
For more information on the classes and methods mentioned in this section, see
220
- the following API Documentation :
225
+ the following API documentation :
221
226
222
- - `ConnectionPoolListener <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ConnectionPoolListener.html>`__
223
- - `MongoClientSettings <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/MongoClientSettings.html>`__
227
+ - `ConnectionPoolListener <{+api+}/com/mongodb/event/ConnectionPoolListener.html>`__
228
+ - `MongoClientSettings <{+api+}/com/mongodb/MongoClientSettings.html>`__
224
229
- `MongoClient <{+api+}/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
225
- - `ConnectionCheckedOutEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ConnectionCheckedOutEvent.html>`__
226
- - `ConnectionCheckOutFailedEvent <{+api+}/apidocs/mongodb-driver-core/ com/mongodb/event/ConnectionCheckOutFailedEvent.html>`__
230
+ - `ConnectionCheckedOutEvent <{+api+}/com/mongodb/event/ConnectionCheckedOutEvent.html>`__
231
+ - `ConnectionCheckOutFailedEvent <{+api+}/com/mongodb/event/ConnectionCheckOutFailedEvent.html>`__
227
232
228
233
.. _monitoring-jmx:
229
234
@@ -301,10 +306,10 @@ the Java Platform.
301
306
.. tip:: Consult the Official JMX and JConsole Documentation
302
307
303
308
The descriptions of JMX and JConsole in this example are illustrative
304
- rather than a source of truth. For guaranteed up to date information, consult
309
+ rather than a source of truth. For guaranteed up-to- date information, consult
305
310
the following official Oracle resources:
306
311
307
- - `JConsole documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__.
312
+ - `JConsole documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__
308
313
- `JMX documentation <https://docs.oracle.com/javase/tutorial/jmx/index.html>`__
309
314
310
315
The following code snippet adds a ``JMXConnectionPoolListener`` to a
@@ -318,6 +323,7 @@ navigate to JConsole and inspect your connection pools.
318
323
319
324
.. output::
320
325
:language: console
326
+ :visible: false
321
327
322
328
Navigate to JConsole to see your connection pools...
323
329
@@ -338,18 +344,18 @@ Once JConsole is open, perform the following actions in the GUI:
338
344
When you no longer want to inspect your connection pools in JConsole, do the
339
345
following:
340
346
341
- - Exit JConsole by closing the JConsole window
342
- - Stop the program running the preceding code snippet
347
+ #. Exit JConsole by closing the JConsole window
348
+ #. Stop the program running by the preceding code snippet
343
349
344
350
For more information on JMX and JConsole, see the following resources from
345
351
Oracle:
346
352
347
- - `JConsole Documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__.
353
+ - `JConsole Documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__
348
354
- `Monitoring and Management Guide <https://docs.oracle.com/en/java/javase/16/management/monitoring-and-management-using-jmx-technology.html>`__
349
355
350
356
For more information on the ``JMXConnectionPoolListener`` class, see
351
- the API Documentation for
352
- `JMXConnectionPoolListener <{+api+}/apidocs/mongodb-driver-core /com/mongodb/management/JMXConnectionPoolListener.html>`__.
357
+ the API documentation for
358
+ `JMXConnectionPoolListener <{+core- api+}/com/mongodb/management/JMXConnectionPoolListener.html>`__.
353
359
354
360
Include the Driver in Your Distributed Tracing System
355
361
-----------------------------------------------------
@@ -367,11 +373,10 @@ include MongoDB event data in the
367
373
368
374
If you do not use Spring Cloud or want to include driver event data in a distributed
369
375
tracing system other than Zipkin, you must write a command event listener that
370
- manages `spans <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html#getting-started-terminology>`__
376
+ manages `spans
377
+ <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html#getting-started-terminology>`__
371
378
for your desired distributed tracing system. To see an implementation of such a
372
- listener, see the Java source code for the
373
- :github:`TraceMongoCommandListener
374
- <spring-cloud/spring-cloud-sleuth/blob/eb01d5952b2e736970efbe3fc7e9784d119eeae9/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/mongodb/TraceMongoCommandListener.java>`
379
+ listener, see the Java source code for the :github:`TraceMongoCommandListener <spring-cloud/spring-cloud-sleuth/blob/eb01d5952b2e736970efbe3fc7e9784d119eeae9/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/mongodb/TraceMongoCommandListener.java>`
375
380
class in the Spring Cloud Sleuth source code.
376
381
377
382
To learn more about Spring Cloud Sleuth, see
@@ -380,3 +385,16 @@ in the Spring Cloud Sleuth documentation.
380
385
381
386
To view a detailed description of a distributed tracing system, see
382
387
`Dapper <https://research.google/pubs/pub36356/>`__ from Google Research.
388
+
389
+ .. tip::
390
+
391
+ To learn more about the concepts discussed in this section, review the
392
+ following resources:
393
+
394
+ - `Spring Cloud <https://spring.io/projects/spring-cloud>`__
395
+ - `Spring Cloud Sleuth <https://spring.io/projects/spring-cloud-sleuth>`__
396
+ - `spans <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html#getting-started-terminology>`__
397
+ - :github:`TraceMongoCommandListener <spring-cloud/spring-cloud-sleuth/blob/eb01d5952b2e736970efbe3fc7e9784d119eeae9/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/mongodb/TraceMongoCommandListener.java>`
398
+ - `Getting Started <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html>`__
399
+ - `Zipkin <https://zipkin.io/>`__
400
+ - `Dapper <https://research.google/pubs/pub36356/>`__
0 commit comments