2
2
Monitoring
3
3
==========
4
4
5
-
6
-
7
5
.. contents:: On this page
8
6
:local:
9
7
:backlinks: none
@@ -13,31 +11,26 @@ Monitoring
13
11
Overview
14
12
--------
15
13
16
- .. What is on this page?
17
-
18
14
In this guide, you can learn how to set up and configure **monitoring** in the
19
- MongoDB Java driver.
15
+ {+ driver-long+} .
20
16
21
- .. What do any new terms mean?
17
+ Monitoring involves collecting information about the activities of a running
18
+ program, which you can use with an application performance management
19
+ library.
22
20
23
- Monitoring is the process of getting information about the activities a running
24
- program performs for use in an application or an application performance
25
- management library.
26
-
27
- Monitoring the MongoDB Java driver lets you understand the
28
- driver's resource usage and performance, and can help you make informed
21
+ Monitoring the {+driver-short+} lets you understand the driver's resource usage
22
+ and performance and can help you make informed
29
23
decisions when designing and debugging your application.
30
24
31
- .. What can you expect to see on this page?
32
-
33
25
In this guide you will learn how to perform these tasks:
34
26
35
- - :ref:`Monitor different types of events in the MongoDB Java Driver <monitoring-monitor-events>`
36
- - :ref:`Monitor connection pool events with Java Management Extensions (JMX) and JConsole <monitoring-jmx>`
27
+ - :ref:`Monitor Events <monitoring-monitor-events>`
28
+ - :ref:`Monitor Connection Pool Events with Java Management Extensions (JMX)
29
+ and JConsole <monitoring-jmx>`
37
30
38
31
This guide shows how to use information about the activity of the driver in code.
39
- If you would like to learn how to record events in the driver,
40
- consider reading our :doc:`guide on logging </ logging>`.
32
+ To learn how to record events in the driver, see the {+driver-short+}'s
33
+ :ref:`Logging < logging>` guide.
41
34
42
35
.. _monitoring-monitor-events:
43
36
@@ -65,8 +58,8 @@ The MongoDB Java driver organizes the events it defines into three categories:
65
58
66
59
The following sections show how to monitor each event category.
67
60
68
- For a full list of the events you can monitor,
69
- `see the event package of the MongoDB Java Driver <{+api+}/apidocs/mongodb-driver-core/com/mongodb/event/package-summary.html>`__.
61
+ To learn more about the events you can monitor, see the API documentation for `event classes
62
+ <{+api+}/apidocs/mongodb-driver-core/com/mongodb/event/package-summary.html>`__.
70
63
71
64
.. _command-events-java:
72
65
@@ -81,13 +74,14 @@ To monitor command events, write a class that implements the
81
74
``CommandListener`` interface and register an instance of that class with your
82
75
``MongoClient`` instance.
83
76
84
- For more information about MongoDB database commands, see the
85
- :manual:`MongoDB manual entry on database commands </reference/command/>`.
77
+ To learn more about MongoDB database commands, see the
78
+ :manual:`Database Commands </reference/command/>` guide in the
79
+ Server Manual.
86
80
87
81
.. note:: Internal Commands
88
82
89
- The driver does not publish events for commands it calls internally. This
90
- includes database commands the driver uses to monitor your cluster and
83
+ The {+ driver-short+} does not publish events for commands it calls internally.
84
+ This includes database commands the driver uses to monitor your cluster and
91
85
commands related to connection establishment (such as the initial ``hello``
92
86
command).
93
87
@@ -96,7 +90,8 @@ For more information about MongoDB database commands, see the
96
90
As a security measure, the driver redacts the contents of some command events. This
97
91
protects the sensitive information contained in these command events. For a
98
92
full list of redacted command events, see the
99
- :spec:`MongoDB command logging and monitoring specification </command-logging-and-monitoring/command-logging-and-monitoring.rst#security>`.
93
+ :spec:`Security </command-logging-and-monitoring/command-logging-and-monitoring.md#security>`
94
+ section of the MongoDB Command Logging and Monitoring specification in GitHub.
100
95
101
96
Example
102
97
^^^^^^^
@@ -109,7 +104,7 @@ To make a counter, do the following:
109
104
110
105
#. Make a class with counter functionality that implements the ``CommandListener`` interface.
111
106
#. Add an instance of the new class that implements ``CommandListener`` to a ``MongoClientSettings`` object.
112
- #. Configure a ``MongoClient`` instance with the ``MongoClientSettings`` object.
107
+ #. Configure a ``MongoClient`` instance by using the ``MongoClientSettings`` object.
113
108
114
109
The following code defines the ``CommandCounter`` class which implements the
115
110
``CommandListener`` interface:
@@ -121,8 +116,8 @@ The following code defines the ``CommandCounter`` class which implements the
121
116
:end-before: end command-listener-impl
122
117
123
118
The following code adds an instance of the ``CommandCounter`` class to a
124
- ``MongoClientSettings`` object, and configures a ``MongoClient`` instance with the
125
- ``MongoClientSettings`` object. The code then runs some database commands to test the
119
+ ``MongoClientSettings`` object, and configures a ``MongoClient`` instance by using the
120
+ ``MongoClientSettings`` object. The code then runs sample ``find()`` commands to test the
126
121
counter.
127
122
128
123
.. _listener-mongo-client-settings-example:
@@ -142,7 +137,7 @@ The preceding code snippet produces output that resembles the following:
142
137
{find=2}
143
138
{find=2, endSessions=1}
144
139
145
- For more information about the classes and methods mentioned in this section, see
140
+ To learn more about the classes and methods mentioned in this section, see
146
141
the following API Documentation:
147
142
148
143
- `CommandListener <{+api+}/apidocs/mongodb-driver-core/com/mongodb/event/CommandListener.html>`__
@@ -159,8 +154,8 @@ A server discovery and monitoring (SDAM) event is an event related to a change
159
154
in the state of the MongoDB instance or cluster you have connected the driver to.
160
155
161
156
The driver defines nine SDAM events. The driver divides these nine events
162
- between three separate listener interfaces which each listen for three of the
163
- nine events. Here are the three interfaces and the events they listen for:
157
+ between three separate listener interfaces. The following are the three interfaces
158
+ and the events they listen for:
164
159
165
160
- ``ClusterListener``: :spec:`topology </server-discovery-and-monitoring/server-discovery-and-monitoring.md#topology>`
166
161
related events
@@ -171,12 +166,17 @@ To monitor a type of SDAM event, write a class that
171
166
implements one of the three preceding interfaces and register an instance of that
172
167
class with your ``MongoClient`` instance.
173
168
174
- For a detailed description of each SDAM event in the driver, see the
175
- :spec:`MongoDB SDAM Logging and Monitoring Specification </server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.md#events-api>`.
169
+ For a detailed description of each SDAM event in the driver, see the
170
+ :spec:`Server API
171
+ </server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.md#events-api>`
172
+ section of th MongoDB SDAM Logging and Monitoring Specification in GitHub.
176
173
177
174
.. note:: Load Balanced Mode
178
175
179
- The driver doesn't emit heartbeat related events when in load balanced mode. For more details about SDAM events with load balancing, see :spec:`MongoDB Load Balancer Support Specification </load-balancers/load-balancers.md#server-discovery-logging-and-monitoring>`.
176
+ The driver doesn't emit heartbeat related events when in load balanced mode.
177
+ To learn more about SDAM events with load balancing, see the
178
+ :spec:`Server Discovery Logging and Monitoring </load-balancers/load-balancers.md#server-discovery-logging-and-monitoring>`
179
+ section of the MongoDB Load Balancer Support Specification in GitHub.
180
180
181
181
Example
182
182
^^^^^^^
@@ -203,7 +203,8 @@ The following code adds an instance of the ``IsWritable`` class to a
203
203
:start-after: start monitor-cluster-example
204
204
:end-before: end monitor-cluster-example
205
205
206
- The preceding code snippet produces output that resembles the following:
206
+ The preceding code snippet produces a confirmation message that resembles the
207
+ following:
207
208
208
209
.. code-block:: none
209
210
:copyable: false
@@ -226,8 +227,11 @@ Connection Pool Events
226
227
A connection pool event is an event related to a **connection pool** held by the driver.
227
228
A connection pool is a set of open TCP connections your driver maintains with
228
229
a MongoDB instance. Connection pools help reduce the number of network handshakes
229
- your application needs to perform with a MongoDB instance, and can help your
230
- application run faster.
230
+ your application needs to perform with a MongoDB instance and can help your
231
+ application run faster.
232
+
233
+ .. Add when page is ready: To learn more about connection pools, see the {+driver-short+}'s
234
+ .. :ref:`Connection Pools <connection-pools>` guide.
231
235
232
236
To monitor connection pool events, write a class that implements the
233
237
``ConnectionPoolListener`` interface and register an instance of that class with your
@@ -240,7 +244,7 @@ This example shows how to make a listener class that prints a message each time
240
244
you check out a connection from your connection pool.
241
245
242
246
The following code defines the ``ConnectionPoolLibrarian`` class which implements the
243
- ``ConnectionPoolListener`` interface.
247
+ ``ConnectionPoolListener`` interface:
244
248
245
249
.. literalinclude:: /includes/fundamentals/code-snippets/Monitoring.java
246
250
:language: java
@@ -250,7 +254,7 @@ The following code defines the ``ConnectionPoolLibrarian`` class which implement
250
254
251
255
The following code adds an instance of the ``ConnectionPoolLibrarian`` class to a
252
256
``MongoClient`` object. The code then runs a database command to test the
253
- librarian.
257
+ librarian:
254
258
255
259
.. literalinclude:: /includes/fundamentals/code-snippets/Monitoring.java
256
260
:language: java
@@ -282,8 +286,8 @@ Monitor Connection Pool Events with JMX
282
286
You can monitor connection pool events using **Java Management Extensions (JMX)**.
283
287
JMX provides tools to monitor applications and devices.
284
288
285
- For more information about JMX, see
286
- `the official Oracle JMX documentation <https://docs.oracle.com/javase/tutorial/jmx/index.html>`__.
289
+ To learn more information about JMX, see the official
290
+ `Oracle JMX documentation <https://docs.oracle.com/javase/tutorial/jmx/index.html>`__.
287
291
288
292
JMX Support
289
293
~~~~~~~~~~~
@@ -333,12 +337,12 @@ MXBeans registered on the platform MBean server have the following properties:
333
337
All MXBean instances created by the driver are under the domain
334
338
``"org.mongodb.driver"``.
335
339
336
- For more information about the topics discussed in this subsection, see the
340
+ To learn more about the topics discussed in this subsection, see the
337
341
following resources from Oracle:
338
342
339
- - `Platform MBean Server Reference Documentation <https://docs.oracle.com/en/java/javase/16/management/overview-java-se-monitoring-and-management.html#GUID-F7B9AB8A-F5A8-472A-AEC6-93B5B7FBE7CE>`__
340
- - `MXBean Documentation <https://docs.oracle.com/javase/tutorial/jmx/mbeans/mxbeans.html>`__
341
- - `MBean Documentation <https://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html>`__
343
+ - `Platform MBean Server Reference documentation <https://docs.oracle.com/en/java/javase/16/management/overview-java-se-monitoring-and-management.html#GUID-F7B9AB8A-F5A8-472A-AEC6-93B5B7FBE7CE>`__
344
+ - `MXBean documentation <https://docs.oracle.com/javase/tutorial/jmx/mbeans/mxbeans.html>`__
345
+ - `MBean documentation <https://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html>`__
342
346
343
347
JMX and JConsole Example
344
348
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -353,12 +357,12 @@ the Java Platform.
353
357
rather than a source of truth. For guaranteed up to date information, consult
354
358
the following official Oracle resources:
355
359
356
- - `JConsole documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__.
360
+ - `JConsole documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__
357
361
- `JMX documentation <https://docs.oracle.com/javase/tutorial/jmx/index.html>`__
358
362
359
363
The following code snippet adds a ``JMXConnectionPoolListener`` to a
360
364
``MongoClient`` instance. The code then pauses execution so you can
361
- navigate to JConsole and inspect your connection pools.
365
+ navigate to JConsole and inspect your connection pools:
362
366
363
367
.. literalinclude:: /includes/fundamentals/code-snippets/JMXMonitoring.java
364
368
:language: java
@@ -393,13 +397,13 @@ following:
393
397
- Exit JConsole by closing the JConsole window
394
398
- Stop the Java program running the preceding code snippet
395
399
396
- For more information about JMX and JConsole, see the following resources from
400
+ To learn more about JMX and JConsole, see the following resources from
397
401
Oracle:
398
402
399
- - `JConsole Documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__.
403
+ - `JConsole documentation <https://www.oracle.com/technical-resources/articles/java/jconsole.html>`__.
400
404
- `Monitoring and Management Guide <https://docs.oracle.com/en/java/javase/16/management/monitoring-and-management-using-jmx-technology.html>`__
401
405
402
- For more information about the ``JMXConnectionPoolListener`` class, see
406
+ To learn more about the ``JMXConnectionPoolListener`` class, see
403
407
the API Documentation for
404
408
`JMXConnectionPoolListener <{+api+}/apidocs/mongodb-driver-core/com/mongodb/management/JMXConnectionPoolListener.html>`__.
405
409
@@ -418,8 +422,8 @@ include MongoDB event data in the
418
422
`Zipkin <https://zipkin.io/>`__ distributed tracing system.
419
423
420
424
If you do not use Spring Cloud or need to include driver event data in a distributed
421
- tracing system other than Zipkin, you must write a command event listener that
422
- manages `spans <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html#getting-started-terminology>`__
425
+ tracing system other than Zipkin, you must write a command event listener that manages
426
+ `spans <https://docs.spring.io/spring-cloud-sleuth/docs/current-SNAPSHOT/reference/html/getting-started.html#getting-started-terminology>`__
423
427
for your desired distributed tracing system. To see an implementation of such a
424
428
listener, see the
425
429
:github:`TraceMongoCommandListener
0 commit comments