Skip to content

Commit 0967895

Browse files
authored
DOCSP-30548: monitoring (command, connection pool, cluster topology) (#69)
1 parent 9e6416c commit 0967895

File tree

13 files changed

+789
-14
lines changed

13 files changed

+789
-14
lines changed

source/fundamentals.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Fundamentals
2323
/fundamentals/run-command
2424
/fundamentals/performance
2525
/fundamentals/runtimes
26+
/fundamentals/monitoring
2627

2728
..
2829
Connect to MongoDB Atlas from AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>
2930
/fundamentals/transactions
3031
/fundamentals/collations
31-
/fundamentals/monitoring
3232
/fundamentals/gridfs
3333
/fundamentals/encrypt-fields
3434
/fundamentals/geo

source/fundamentals/monitoring.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. _rust-monitoring:
2+
3+
==========
4+
Monitoring
5+
==========
6+
7+
.. toctree::
8+
:caption: Monitoring categories
9+
10+
/fundamentals/monitoring/cluster-monitoring
11+
/fundamentals/monitoring/command-monitoring
12+
/fundamentals/monitoring/connection-monitoring
13+
14+
- :ref:`Cluster Monitoring <rust-cluster-monitoring>`: monitor changes
15+
in your cluster configuration
16+
- :ref:`Command Monitoring <rust-command-monitoring>`: monitor command
17+
execution
18+
- :ref:`Connection Pool Monitoring <rust-connection-monitoring>`:
19+
monitor changes in the connection pool
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
.. _rust-cluster-monitoring:
2+
3+
==================
4+
Cluster Monitoring
5+
==================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecols
12+
13+
Overview
14+
--------
15+
16+
This guide shows you how to use the {+driver-short+} to monitor topology
17+
events in a MongoDB instance, replica set, or sharded cluster. The
18+
driver creates topology events, also known as Server Discovery and
19+
Monitoring (SDAM) events, when there are any changes in the state of the
20+
instance or cluster that you are connected to.
21+
22+
You can use information about topology changes in your
23+
application, or you can monitor cluster changes to learn more about
24+
how they affect your application.
25+
26+
This guide includes the following sections:
27+
28+
- :ref:`Event Descriptions <rust-cluster-monitoring-descriptions>` describes
29+
the SDAM events that the driver can generate
30+
31+
- :ref:`Event Subscription Example <rust-cluster-monitoring-example>`
32+
provides sample code that shows how to subscribe to an SDAM event
33+
34+
- :ref:`Example Event Documents <rust-cluster-monitoring-documents>`
35+
provides samples of each SDAM event
36+
37+
- :ref:`Additional Information <rust-cluster-addtl-info>`
38+
provides links to resources and API documentation for types
39+
and methods mentioned in this guide
40+
41+
.. _rust-cluster-monitoring-descriptions:
42+
43+
Event Descriptions
44+
------------------
45+
46+
You can subscribe to one or more of the following SDAM events:
47+
48+
.. list-table::
49+
:widths: 33 67
50+
:header-rows: 1
51+
52+
* - Event Name
53+
- Description
54+
55+
* - `ServerDescriptionChangedEvent <{+api+}/event/sdam/struct.ServerDescriptionChangedEvent.html>`__
56+
- Created when an instance state changes, such as when a replica set
57+
member changes from a secondary to a primary.
58+
59+
* - `ServerOpeningEvent <{+api+}/event/sdam/struct.ServerOpeningEvent.html>`__
60+
- Created when a connection to an instance, such as a replica set member, opens.
61+
62+
* - `ServerClosedEvent <{+api+}/event/sdam/struct.ServerClosedEvent.html>`__
63+
- Created when a connection to an instance, such as a replica set member, closes.
64+
65+
* - `TopologyDescriptionChangedEvent <{+api+}/event/sdam/struct.TopologyDescriptionChangedEvent.html>`__
66+
- Created when the topology description changes, such as when there
67+
is an election of a new primary or when a ``mongos`` proxy disconnects.
68+
69+
* - `TopologyOpeningEvent <{+api+}/event/sdam/struct.TopologyOpeningEvent.html>`__
70+
- Created before the driver attempts to connect to an instance.
71+
72+
* - `TopologyClosedEvent <{+api+}/event/sdam/struct.TopologyClosedEvent.html>`__
73+
- Created after all instance connections in the topology close.
74+
75+
* - `ServerHeartbeatStartedEvent <{+api+}/event/sdam/struct.ServerHeartbeatStartedEvent.html>`__
76+
- Created before the driver issues a ``hello`` command to an instance.
77+
78+
* - `ServerHeartbeatSucceededEvent <{+api+}/event/sdam/struct.ServerHeartbeatSucceededEvent.html>`__
79+
- Created when the ``hello`` command returns successfully from a
80+
MongoDB instance.
81+
82+
* - `ServerHeartbeatFailedEvent <{+api+}/event/sdam/struct.ServerHeartbeatFailedEvent.html>`__
83+
- Created when a ``hello`` command to a MongoDB instance does not
84+
return a successful response.
85+
86+
.. _rust-cluster-monitoring-example:
87+
88+
Event Subscription Example
89+
--------------------------
90+
91+
You can access one or more SDAM events by
92+
subscribing to them in your application. The following example connects
93+
to a MongoDB deployment and subscribes to the ``ServerOpeningEvent`` event type:
94+
95+
.. literalinclude:: /includes/fundamentals/code-snippets/monitoring/sdam-subscribe.rs
96+
:language: rust
97+
:dedent:
98+
:start-after: begin-sdam
99+
:end-before: end-sdam
100+
101+
.. _rust-cluster-monitoring-documents:
102+
103+
Example Event Documents
104+
-----------------------
105+
106+
The following sections show sample output for each type of SDAM event.
107+
108+
ServerDescriptionChangedEvent
109+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110+
111+
.. code-block:: none
112+
:copyable: false
113+
114+
ServerDescriptionChangedEvent {
115+
address: ...,
116+
topology_id: ...,
117+
previous_description: ...,
118+
new_description: ...,
119+
}
120+
121+
ServerOpeningEvent
122+
~~~~~~~~~~~~~~~~~~
123+
124+
.. code-block:: none
125+
:copyable: false
126+
127+
ServerOpeningEvent {
128+
address: ...,
129+
topology_id: ...,
130+
}
131+
132+
ServerClosedEvent
133+
~~~~~~~~~~~~~~~~~
134+
135+
.. code-block:: none
136+
:copyable: false
137+
138+
ServerClosedEvent {
139+
address: ...,
140+
topology_id: ...,
141+
}
142+
143+
TopologyDescriptionChangedEvent
144+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
146+
.. code-block:: none
147+
:copyable: false
148+
149+
TopologyDescriptionChangedEvent {
150+
topology_id: ...,
151+
previous_description: ...,
152+
new_description: ...,
153+
}
154+
155+
TopologyOpeningEvent
156+
~~~~~~~~~~~~~~~~~~~~
157+
158+
.. code-block:: none
159+
:copyable: false
160+
161+
TopologyOpeningEvent {
162+
topology_id: ...,
163+
}
164+
165+
TopologyClosedEvent
166+
~~~~~~~~~~~~~~~~~~~
167+
168+
.. code-block:: none
169+
:copyable: false
170+
171+
TopologyClosedEvent {
172+
topology_id: ...,
173+
}
174+
175+
ServerHeartbeatStartedEvent
176+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
177+
178+
.. code-block:: none
179+
:copyable: false
180+
181+
ServerHeartbeatStartedEvent {
182+
server_address: ...,
183+
awaited: false,
184+
driver_connection_id: 12,
185+
server_connection_id: ...,
186+
}
187+
188+
ServerHeartbeatSucceededEvent
189+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
191+
.. code-block:: none
192+
:copyable: false
193+
194+
ServerHeartbeatSucceededEvent {
195+
duration: ...,
196+
reply: ...,
197+
server_address: ...,
198+
awaited: false,
199+
driver_connection_id: 12,
200+
server_connection_id: ...,
201+
}
202+
203+
ServerHeartbeatFailedEvent
204+
~~~~~~~~~~~~~~~~~~~~~~~~~~
205+
206+
.. code-block:: none
207+
:copyable: false
208+
209+
ServerHeartbeatFailedEvent {
210+
duration: ...,
211+
failure: ...,
212+
server_address: ...,
213+
awaited: false,
214+
driver_connection_id: 12,
215+
server_connection_id: ...,
216+
}
217+
218+
.. _rust-cluster-addtl-info:
219+
220+
Additional Information
221+
----------------------
222+
223+
To learn more about monitoring a MongoDB deployment, see the :website:`How
224+
to Monitor MongoDB
225+
</basics/how-to-monitor-mongodb-and-what-metrics-to-monitor>` article.
226+
227+
To learn more about connecting to MongoDB, see the
228+
:ref:`rust-connect-to-mongodb`.
229+
230+
API Documentation
231+
~~~~~~~~~~~~~~~~~
232+
233+
To learn more about the methods and types mentioned in this
234+
guide, see the following API documentation:
235+
236+
- `SdamEventHandler <{+api+}/event/sdam/trait.SdamEventHandler.html>`__
237+
- `ClientOptions <{+api+}/options/struct.ClientOptions.html>`__
238+
- `Client::with_options() <{+api+}/struct.Client.html#method.with_options>`__

0 commit comments

Comments
 (0)