-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41982: cluster monitoring #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5dcbd15
564dfe9
fce8972
9dfc72a
8cf4fc1
fc1506c
25d4f88
e3351c5
4a39d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,15 +20,17 @@ Cluster Monitoring | |||||
Overview | ||||||
-------- | ||||||
|
||||||
This guide shows you how to use the {+php-library+} to monitor topology | ||||||
events in a MongoDB instance, replica set, or sharded cluster. The | ||||||
driver creates topology events, also known as Server Discovery and | ||||||
Monitoring (SDAM) events, when there are any changes in the state of the | ||||||
MongoDB instance or cluster that you are connected to. | ||||||
This guide shows you how to use the {+php-library+} to monitor server | ||||||
discovery and monitoring (SDAM) events in a MongoDB instance, replica | ||||||
set, or sharded cluster. These events occur when there | ||||||
are any changes in the state of the MongoDB instance or cluster that you | ||||||
are connected to. | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
You might use information about topology events in your | ||||||
application to understand cluster changes, assess cluster health, or | ||||||
perform capacity planning. | ||||||
You might use information about SDAM events in your application to | ||||||
understand cluster changes, assess cluster health, or perform capacity | ||||||
planning. | ||||||
|
||||||
.. _php-subscribe-sdam: | ||||||
|
||||||
Subscribe to Events | ||||||
------------------- | ||||||
|
@@ -53,10 +55,10 @@ server: | |||||
|
||||||
.. note:: | ||||||
|
||||||
As shown in the preceding code, you must implement all of the methods | ||||||
As shown in the preceding code, you must implement all the methods | ||||||
of the ``SDAMSubscriber`` interface, even for events you are not subscribing to. | ||||||
You can implement these methods with empty bodies so that the library | ||||||
does not generate any messages for these events. | ||||||
The example defines the extra methods as empty so that the | ||||||
application does not output any messages for those events. | ||||||
|
||||||
Then, use the ``addSubscriber()`` method to register ``MySubscriber`` | ||||||
with the client, as shown in the following code: | ||||||
|
@@ -81,53 +83,79 @@ outputs messages such as the following: | |||||
Event Descriptions | ||||||
------------------ | ||||||
|
||||||
You can subscribe to the following SDAM events by implementing the | ||||||
corresponding method from the ``SDAMSubscriber`` interface: | ||||||
You can subscribe to SDAM events by implementing the corresponding | ||||||
method from the ``SDAMSubscriber`` interface. The following table | ||||||
provides the name of each SDAM event, linked to the class's API | ||||||
documentation, and a description of when the event is published: | ||||||
|
||||||
.. list-table:: | ||||||
:widths: 35 65 | ||||||
:header-rows: 1 | ||||||
|
||||||
* - Event Name | ||||||
* - Event Type | ||||||
- Description | ||||||
|
||||||
* - ``ServerChangedEvent`` | ||||||
- Created when an instance state changes, such as from secondary to | ||||||
primary. | ||||||
* - :php:`ServerChangedEvent <mongodb-driver-monitoring-serverchangedevent>` | ||||||
- Created when the server description changes, such as the server's type | ||||||
changing from secondary to primary. | ||||||
|
||||||
* - ``ServerOpeningEvent`` | ||||||
- Created when the server is initialized. | ||||||
* - :php:`ServerOpeningEvent <mongodb-driver-monitoring-serveropeningevent>` | ||||||
- Created when the server description is instantiated with its | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
defaults. | ||||||
|
||||||
* - ``ServerClosedEvent`` | ||||||
* - :php:`ServerClosedEvent <mongodb-driver-monitoring-serverclosedevent>` | ||||||
- Created when the server is closed. | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
* - ``TopologyChangedEvent`` | ||||||
- Created when the topology changes, such as an election of a new | ||||||
primary or disconnection of a ``mongos`` proxy. | ||||||
* - :php:`TopologyChangedEvent <mongodb-driver-monitoring-topologychangedevent>` | ||||||
- Created when the topology description changes, such when there is | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you accidentally a word in this sentence.
Suggested change
|
||||||
an election of a new primary or disconnection of a ``mongos`` proxy. | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
* - ``TopologyOpeningEvent`` | ||||||
- Created when the topology is initialized. | ||||||
* - :php:`TopologyOpeningEvent <mongodb-driver-monitoring-topologyopeningevent>` | ||||||
- Created when the topology description is initialized. | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
* - ``TopologyClosedEvent`` | ||||||
* - :php:`TopologyClosedEvent <mongodb-driver-monitoring-topologyclosedevent>` | ||||||
- Created when the topology is closed. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd reword this as "the driver disconnects from the cluster". Given the event name, I don't think we need to repeat "topology is closed" in the description, although you can still include both if you like. In that case, maybe note the disconnect behavior with "i.e." or something. Per the SDAM Monitoring spec, this would always be the last event to be dispatched. In the PHP driver, it's not actually possible to observe this event when using default behavior, as we persist the libmongoc client object (and thus the connections) beyond the lifetime of the PHP script. So by the time a client is actually closed, there'd be no subscriber in memory to receive the event. This event can only be observed when specifying Having said that, I think it's sufficient to just refer to disconnecting from the cluster here. And admittedly, we (the PHP team) should improve the docs for these event classes. I created PHPC-2449 to track that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for providing this background! |
||||||
|
||||||
* - ``ServerHeartbeatStartedEvent`` | ||||||
- Created when the heartbeat is started. | ||||||
* - :php:`ServerHeartbeatStartedEvent <mongodb-driver-monitoring-serverheartbeatstartedevent>` | ||||||
- Created when the server monitor sends a ``hello`` call to the server. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
"Command" is less ambiguous. |
||||||
This action is called a heartbeat. | ||||||
|
||||||
* - ``ServerHeartbeatSucceededEvent`` | ||||||
* - :php:`ServerHeartbeatSucceededEvent <mongodb-driver-monitoring-serverheartbeatsucceededevent>` | ||||||
- Created when the heartbeat succeeds. | ||||||
|
||||||
* - ``ServerHeartbeatFailedEvent`` | ||||||
* - :php:`ServerHeartbeatFailedEvent <mongodb-driver-monitoring-serverheartbeatfailedevent>` | ||||||
- Created when the heartbeat fails. | ||||||
|
||||||
You can find a list of the monitoring subscriber classes and event | ||||||
methods in the :php:`Monitoring classes and subscriber functions | ||||||
<mongodb.monitoring>` section of the PHP manual. | ||||||
|
||||||
Remove a Subscriber | ||||||
------------------- | ||||||
|
||||||
Later in your application, you might not want to subscribe to | ||||||
SDAM events. To unregister a subscriber from your client, use the | ||||||
``MongoDB\Client::removeSubscriber()`` method. If you attempt to remove | ||||||
a nonexistent subscriber, the method doesn't perform any action. | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
The following code shows how to remove the subscriber that you | ||||||
registered in the :ref:`php-subscribe-sdam` section: | ||||||
|
||||||
.. literalinclude:: /includes/monitoring/sdam.php | ||||||
:start-after: start-remove-sub | ||||||
:end-before: end-remove-sub | ||||||
:language: php | ||||||
:copyable: | ||||||
:dedent: | ||||||
|
||||||
API Documentation | ||||||
----------------- | ||||||
|
||||||
To learn more about any of the classes or methods discussed in this guide, see the | ||||||
following API documentation: | ||||||
|
||||||
- :phpmethod:`MongoDB\Client::addSubscriber()` | ||||||
- :phpclass:`MongoDB\Client` | ||||||
- :phpmethod:`MongoDB\Client::removeSubscriber()` | ||||||
|
||||||
To learn more about subscriber classes and methods, see the following | ||||||
pages in the PHP manual: | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.