Skip to content

Commit 25df8ed

Browse files
committed
NR feedback 2
1 parent d7dd4c8 commit 25df8ed

File tree

1 file changed

+74
-56
lines changed

1 file changed

+74
-56
lines changed

source/monitoring.txt

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ A command event is an event related to a MongoDB database command. Some
6767
examples of database commands that produce command events are ``find``,
6868
``insert``, ``delete``, and ``count``.
6969

70-
To monitor command events, write a class that implements the
70+
To monitor command events, create a class that implements the
7171
``CommandListener`` interface and register an instance of that class with your
7272
``MongoClient`` instance.
7373

@@ -78,8 +78,8 @@ For more information on MongoDB database commands, see the
7878

7979
The driver does not publish events for commands it calls internally. This
8080
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.
8383

8484
.. important:: Redacted Output
8585

@@ -93,19 +93,15 @@ Example
9393

9494
This example shows how to make a counter for database commands. The counter
9595
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.
9797

98-
To make a counter, do the following:
98+
To make a counter, follow these steps:
9999

100100
#. 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.
103103

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:
109105

110106
.. _listener-mongo-client-settings-example:
111107

@@ -116,38 +112,38 @@ counter:
116112

117113
.. output::
118114
:language: console
115+
:visible: false
119116

120117
{find=1}
121118
{find=2}
122119
{find=2, endSessions=1}
123120

124121
For more information on the classes and methods mentioned in this section, see
125-
the following API Documentation:
122+
the following API documentation:
126123

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>`__
129126
- `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>`__
133130

134131
Server Discovery and Monitoring Events
135132
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136133

137134
A server discovery and monitoring (SDAM) event is an event related to a change
138135
in the state of the MongoDB instance or cluster you have connected the driver to.
139136

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:
143139

144140
- ``ClusterListener``: topology-related events
145141
- ``ServerListener``: events related to ``mongod`` or ``mongos`` processes
146142
- ``ServerMonitorListener``: heartbeat related events
147143

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.
151147

152148
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>`.
153149

@@ -157,10 +153,14 @@ Example
157153
This example shows how to make a listener class that prints a message that lets
158154
you know if the driver can write to your MongoDB instance.
159155

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:
164164

165165
.. io-code-block::
166166

@@ -169,29 +169,30 @@ The following code defines the ``IsWritable`` class which implements the
169169

170170
.. output::
171171
:language: console
172+
:visible: false
172173

173174
Able to write to server
174175

175176
For more information on the classes and methods mentioned in this section, see
176-
the following API Documentation:
177+
the following API documentation:
177178

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>`__
182183
- `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>`__
184185

185186
Connection Pool Events
186187
~~~~~~~~~~~~~~~~~~~~~~
187188

188189
A connection pool event is an event related to a **connection pool** held by the driver.
189190
A connection pool is a set of open TCP connections your driver maintains with
190191
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
192193
application run faster.
193194

194-
To monitor connection pool events, write a class that implements the
195+
To monitor connection pool events, create a class that implements the
195196
``ConnectionPoolListener`` interface and register an instance of that class with your
196197
``MongoClient`` instance.
197198

@@ -201,10 +202,13 @@ Example
201202
This example shows how to make a listener class that prints a message each time
202203
you check out a connection from your connection pool.
203204

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:
208212

209213
.. io-code-block::
210214

@@ -213,17 +217,18 @@ runs a database command to test the librarian.
213217

214218
.. output::
215219
:language: console
220+
:visible: false
216221

217222
Let me get you the connection with id 21...
218223

219224
For more information on the classes and methods mentioned in this section, see
220-
the following API Documentation:
225+
the following API documentation:
221226

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>`__
224229
- `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>`__
227232

228233
.. _monitoring-jmx:
229234

@@ -301,10 +306,10 @@ the Java Platform.
301306
.. tip:: Consult the Official JMX and JConsole Documentation
302307

303308
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
305310
the following official Oracle resources:
306311

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>`__
308313
- `JMX documentation <https://docs.oracle.com/javase/tutorial/jmx/index.html>`__
309314

310315
The following code snippet adds a ``JMXConnectionPoolListener`` to a
@@ -318,6 +323,7 @@ navigate to JConsole and inspect your connection pools.
318323

319324
.. output::
320325
:language: console
326+
:visible: false
321327

322328
Navigate to JConsole to see your connection pools...
323329

@@ -338,18 +344,18 @@ Once JConsole is open, perform the following actions in the GUI:
338344
When you no longer want to inspect your connection pools in JConsole, do the
339345
following:
340346

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
343349

344350
For more information on JMX and JConsole, see the following resources from
345351
Oracle:
346352

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>`__
348354
- `Monitoring and Management Guide <https://docs.oracle.com/en/java/javase/16/management/monitoring-and-management-using-jmx-technology.html>`__
349355

350356
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>`__.
353359

354360
Include the Driver in Your Distributed Tracing System
355361
-----------------------------------------------------
@@ -367,11 +373,10 @@ include MongoDB event data in the
367373

368374
If you do not use Spring Cloud or want to include driver event data in a distributed
369375
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>`__
371378
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>`
375380
class in the Spring Cloud Sleuth source code.
376381

377382
To learn more about Spring Cloud Sleuth, see
@@ -380,3 +385,16 @@ in the Spring Cloud Sleuth documentation.
380385

381386
To view a detailed description of a distributed tracing system, see
382387
`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

Comments
 (0)