-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-45201 Cluster monitoring #133
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
Merged
lindseymoore
merged 11 commits into
mongodb:standardization
from
lindseymoore:DOCSP-45201
Jan 29, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6baf059
DOCSP-45201 Cluster monitoring
lindseymoore cdcf665
first draft
lindseymoore 7a109c8
remove eevrything not about cluster monitoring:
lindseymoore b7edbee
table changes
lindseymoore 9bda124
review
lindseymoore 67cb01f
final few changes
lindseymoore c59755a
NR review comments
lindseymoore c4158cd
NR comments
lindseymoore 7ca895b
look through
lindseymoore 263143f
tech review comments
lindseymoore 810655e
Merge branch 'standardization' into DOCSP-45201
lindseymoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
# start-available-subscriber | ||
subscriber = Mongo::Monitoring::ServerOpeningLogSubscriber.new | ||
|
||
# Globally subscribes to ServerOpening events by using the SERVER_OPENING monitoring topic | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_OPENING, subscriber) | ||
client = Mongo::Client.new(['127.0.0.1:27017']) | ||
|
||
# Subscribes to ServerOpening events at the client level by using the SERVER_OPENING monitoring topic | ||
client.subscribe( Mongo::Monitoring::SERVER_OPENING, subscriber ) | ||
# end-available-subscriber | ||
|
||
# start-sdam | ||
class SDAMLogSubscriber | ||
include Mongo::Loggable | ||
|
||
def succeeded(event) | ||
log_debug(format_event(event)) | ||
end | ||
|
||
private | ||
|
||
def logger | ||
Mongo::Logger.logger | ||
end | ||
|
||
def format_message(message) | ||
format("SDAM | %s".freeze, message) | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
|
||
class TopologyOpeningLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
"Topology type '#{event.topology.display_name}' initializing." | ||
end | ||
end | ||
|
||
class ServerOpeningLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
"Server #{event.address} initializing." | ||
end | ||
end | ||
|
||
class ServerDescriptionChangedLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
"Server description for #{event.address} changed from " + | ||
"'#{event.previous_description.server_type}' to '#{event.new_description.server_type}'." | ||
end | ||
end | ||
|
||
class TopologyChangedLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
if event.previous_topology != event.new_topology | ||
"Topology type '#{event.previous_topology.display_name}' changed to " + | ||
"type '#{event.new_topology.display_name}'." | ||
else | ||
"There was a change in the members of the '#{event.new_topology.display_name}' " + | ||
"topology." | ||
end | ||
end | ||
end | ||
|
||
class ServerClosedLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
"Server #{event.address} connection closed." | ||
end | ||
end | ||
|
||
class TopologyClosedLogSubscriber < SDAMLogSubscriber | ||
private | ||
|
||
def format_event(event) | ||
"Topology type '#{event.topology.display_name}' closed." | ||
end | ||
end | ||
#end-sdam | ||
|
||
# start-sdam-subscriber-global | ||
topology_opening_subscriber = TopologyOpeningLogSubscriber.new | ||
server_opening_subscriber = ServerOpeningLogSubscriber.new | ||
server_description_changed_subscriber = ServerDescriptionChangedLogSubscriber.new | ||
topology_changed_subscriber = TopologyChangedLogSubscriber.new | ||
server_closed_subscriber = ServerClosedLogSubscriber.new | ||
topology_closed_subscriber = TopologyClosedLogSubscriber.new | ||
|
||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::TOPOLOGY_OPENING, | ||
topology_opening_subscriber) | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_OPENING, | ||
server_opening_subscriber) | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_DESCRIPTION_CHANGED, | ||
server_description_changed_subscriber) | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::TOPOLOGY_CHANGED, | ||
topology_changed_subscriber) | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_CLOSED, | ||
server_closed_subscriber) | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::TOPOLOGY_CLOSED, | ||
topology_closed_subscriber) | ||
# end-sdam-subscriber-global | ||
|
||
# start-sdam-subscriber-client | ||
topology_opening_subscriber = TopologyOpeningLogSubscriber.new | ||
server_opening_subscriber = ServerOpeningLogSubscriber.new | ||
server_description_changed_subscriber = ServerDescriptionChangedLogSubscriber.new | ||
topology_changed_subscriber = TopologyChangedLogSubscriber.new | ||
server_closed_subscriber = ServerClosedLogSubscriber.new | ||
topology_closed_subscriber = TopologyClosedLogSubscriber.new | ||
|
||
sdam_proc = Proc.new do |client| | ||
client.subscribe(Mongo::Monitoring::TOPOLOGY_OPENING, | ||
topology_opening_subscriber) | ||
client.subscribe(Mongo::Monitoring::SERVER_OPENING, | ||
server_opening_subscriber) | ||
client.subscribe(Mongo::Monitoring::SERVER_DESCRIPTION_CHANGED, | ||
server_description_changed_subscriber) | ||
client.subscribe(Mongo::Monitoring::TOPOLOGY_CHANGED, | ||
topology_changed_subscriber) | ||
client.subscribe(Mongo::Monitoring::SERVER_CLOSED, | ||
server_closed_subscriber) | ||
client.subscribe(Mongo::Monitoring::TOPOLOGY_CLOSED, | ||
topology_closed_subscriber) | ||
end | ||
|
||
client = Mongo::Client.new(['127.0.0.1:27017'], database: 'test', | ||
sdam_proc: sdam_proc) | ||
# end-sdam-subscriber-client | ||
|
||
# start-heartbeat | ||
class HeartbeatLogSubscriber | ||
include Mongo::Loggable | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def started(event) | ||
log_debug("#{event.address} | STARTED") | ||
end | ||
|
||
def succeeded(event) | ||
log_debug("#{event.address} | SUCCEEDED | #{event.duration}s") | ||
end | ||
|
||
def failed(event) | ||
log_debug("#{event.address} | FAILED | #{event.error.class}: #{event.error.message} | #{event.duration}s") | ||
end | ||
|
||
private | ||
|
||
def logger | ||
Mongo::Logger.logger | ||
end | ||
|
||
def format_message(message) | ||
format("HEARTBEAT | %s".freeze, message) | ||
end | ||
end | ||
# end-heartbeat | ||
|
||
# start-heartbeat-subscribe | ||
subscriber = HeartbeatLogSubscriber.new | ||
|
||
# Globally subscribes to Server Opening events | ||
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::SERVER_HEARTBEAT, subscriber) | ||
|
||
# Subscribes to Server Opening events at the client level | ||
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test' ) | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client.subscribe( Mongo::Monitoring::SERVER_HEARTBEAT, subscriber ) | ||
# end-heartbeat-subscribe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. _ruby-monitoring: | ||
|
||
======================== | ||
Monitor Your Application | ||
======================== | ||
|
||
.. toctree:: | ||
:caption: Monitoring categories | ||
|
||
Cluster Monitoring </monitoring/cluster-monitoring> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.