@@ -20,15 +20,17 @@ Cluster Monitoring
20
20
Overview
21
21
--------
22
22
23
- This guide shows you how to use the {+php-library+} to monitor topology
24
- events in a MongoDB instance, replica set, or sharded cluster. The
25
- driver creates topology events, also known as Server Discovery and
26
- Monitoring (SDAM) events, when there are any changes in the state of the
27
- MongoDB instance or cluster that you are connected to.
23
+ This guide shows you how to use the {+php-library+} to monitor server
24
+ discovery and monitoring (SDAM) events in a MongoDB instance, replica
25
+ set, or sharded cluster. These events occur when there
26
+ are any changes in the state of the MongoDB instance or cluster that you
27
+ are connected to.
28
28
29
- You might use information about topology events in your
30
- application to understand cluster changes, assess cluster health, or
31
- perform capacity planning.
29
+ You might use information about SDAM events in your application to
30
+ understand cluster changes, assess cluster health, or perform capacity
31
+ planning.
32
+
33
+ .. _php-subscribe-sdam:
32
34
33
35
Subscribe to Events
34
36
-------------------
@@ -55,8 +57,8 @@ server:
55
57
56
58
As shown in the preceding code, you must implement all of the methods
57
59
of the ``SDAMSubscriber`` interface, even for events you are not subscribing to.
58
- You can implement these methods with empty bodies so that the library
59
- does not generate any messages for these events.
60
+ The example defines the extra methods as empty so that the
61
+ application does not output any messages for those events.
60
62
61
63
Then, use the ``addSubscriber()`` method to register ``MySubscriber``
62
64
with the client, as shown in the following code:
@@ -81,53 +83,79 @@ outputs messages such as the following:
81
83
Event Descriptions
82
84
------------------
83
85
84
- You can subscribe to the following SDAM events by implementing the
85
- corresponding method from the ``SDAMSubscriber`` interface:
86
+ You can subscribe to SDAM events by implementing the corresponding
87
+ method from the ``SDAMSubscriber`` interface. The following table
88
+ provides the name of each SDAM event, linked to the class's API
89
+ documentation, and a description of when the event is published:
86
90
87
91
.. list-table::
88
92
:widths: 35 65
89
93
:header-rows: 1
90
94
91
- * - Event Name
95
+ * - Event Type
92
96
- Description
93
97
94
- * - `` ServerChangedEvent` `
95
- - Created when an instance state changes, such as from secondary to
96
- primary.
98
+ * - :php:` ServerChangedEvent <mongodb-driver-monitoring-serverchangedevent.php> `
99
+ - Created when the server description changes, such as the server's type
100
+ changing from secondary to primary.
97
101
98
- * - ``ServerOpeningEvent``
99
- - Created when the server is initialized.
102
+ * - :php:`ServerOpeningEvent <mongodb-driver-monitoring-serveropeningevent.php>`
103
+ - Created when the server description is instantiated with its
104
+ defaults.
100
105
101
- * - `` ServerClosedEvent` `
106
+ * - :php:` ServerClosedEvent <mongodb-driver-monitoring-serverclosedevent.php> `
102
107
- Created when the server is closed.
103
108
104
- * - `` TopologyChangedEvent` `
105
- - Created when the topology changes, such as an election of a new
106
- primary or disconnection of a ``mongos`` proxy.
109
+ * - :php:` TopologyChangedEvent <mongodb-driver-monitoring-topologychangedevent.php> `
110
+ - Created when the topology description changes, such when there is
111
+ an election of a new primary or disconnection of a ``mongos`` proxy.
107
112
108
- * - `` TopologyOpeningEvent` `
109
- - Created when the topology is initialized.
113
+ * - :php:` TopologyOpeningEvent <mongodb-driver-monitoring-topologyopeningevent.php> `
114
+ - Created when the topology description is initialized.
110
115
111
- * - `` TopologyClosedEvent` `
116
+ * - :php:` TopologyClosedEvent <mongodb-driver-monitoring-topologyclosedevent.php> `
112
117
- Created when the topology is closed.
113
118
114
- * - ``ServerHeartbeatStartedEvent``
115
- - Created when the heartbeat is started.
119
+ * - :php:`ServerHeartbeatStartedEvent <mongodb-driver-monitoring-serverheartbeatstartedevent.php>`
120
+ - Created when the server monitor sends a ``hello`` call to the server.
121
+ This action is called a heartbeat.
116
122
117
- * - `` ServerHeartbeatSucceededEvent` `
123
+ * - :php:` ServerHeartbeatSucceededEvent <mongodb-driver-monitoring-serverheartbeatsucceededevent.php> `
118
124
- Created when the heartbeat succeeds.
119
125
120
- * - `` ServerHeartbeatFailedEvent` `
126
+ * - :php:` ServerHeartbeatFailedEvent <mongodb-driver-monitoring-serverheartbeatfailedevent.php> `
121
127
- Created when the heartbeat fails.
122
128
129
+ You can find a list of the monitoring subscriber classes and event
130
+ methods in the :php:`Monitoring classes and subscriber functions
131
+ <mongodb.monitoring.php>` section of the PHP manual.
132
+
133
+ Remove a Subscriber
134
+ -------------------
135
+
136
+ Later in your application, you might not want to subscribe to
137
+ SDAM events. To unregister a subscriber from your client, use the
138
+ ``MongoDB\Client::removeSubscriber()`` method. If you attempt to remove
139
+ a nonexistent subscriber, the method doesn't perform any action.
140
+
141
+ The following code shows how to remove the subscriber that you
142
+ registered in the :ref:`php-subscribe-sdam` section:
143
+
144
+ .. literalinclude:: /includes/monitoring/sdam.php
145
+ :start-after: start-remove-sub
146
+ :end-before: end-remove-sub
147
+ :language: php
148
+ :copyable:
149
+ :dedent:
150
+
123
151
API Documentation
124
152
-----------------
125
153
126
154
To learn more about any of the classes or methods discussed in this guide, see the
127
155
following API documentation:
128
156
129
157
- :phpmethod:`MongoDB\Client::addSubscriber()`
130
- - :phpclass :`MongoDB\Client`
158
+ - :phpmethod :`MongoDB\Client::removeSubscriber() `
131
159
132
160
To learn more about subscriber classes and methods, see the following
133
161
pages in the PHP manual:
0 commit comments