MongoDB::Monitoring(3pm) | User Contributed Perl Documentation | MongoDB::Monitoring(3pm) |
MongoDB::Monitoring - Internal event monitoring API for instrumentation
version v2.2.2
The MongoDB::MongoClient takes an optional "monitoring_callback" attribute, which can be used to monitor events that occur during the operation of the driver.
The API is very simple: given a code reference, a hashref for each event is passed to the code reference. Here is a simple example that just accumulates events in an array:
our @events; my $cb = sub { push @events, $_[0] }; MongoDB->connect( $uri, { monitoring_callback => $cb } );
Every event is a hash reference, with a "type" field indicating the type, e.g. "command_started". Each type is described below.
These events are fired for commands directly to the wire and the response.
command_started
This event is sent just before a command is put one the wire. It will be followed by either a "command_succeeded" or "command_failed" event.
Fields:
command_succeeded
This event is sent just after a command reply is received, but only if the database reply document contains a non-false "ok" field. NOTE: write errors will have "ok:1" even though they have write errors; for writes, success indicates that the write attempt was valid, not that the write succeeded.
Fields:
command_failed
This event is sent just after a command reply is received, but only if the database reply document contains a false "ok" field or if an exception occurred during send or receive operations.
Fields:
These events are fired when servers and topology are amended.
server_opening_event
This event is sent when a new server is added to the topology.
Fields:
server_closed_event
This event is sent when a server is removed from the topology.
Fields:
server_description_changed_event
This event is sent when the server description changes, but does not include changes to the RTT.
Fields:
topology_opening_event
This event is sent when the topology is created.
Fields:
topology_closed_event
This event is sent when the topology is closed.
Fields:
topology_description_changed_event
This event is sent when the topology description changes.
Fields:
server_heartbeat_started_event
This event is sent before the ismaster command is sent to the server.
Fields:
server_heartbeat_succeeded_event
This event is sent after the reply from the ismaster command arrives from a successful reply.
Fields:
server_heartbeat_failed_event
This event is sent if there is a failure from the ismaster command, which returns an error string of some sort.
Fields:
Certain commands are considered sensitive. When any of the following commands are seen in monitoring, the command body and database reply body are replaced with an empty document:
This software is Copyright (c) 2020 by MongoDB, Inc.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
2022-06-30 | perl v5.34.0 |