MongoD...itoring(3pm)
β¨ NAME β¨
MongoDB::Monitoring β the internal event monitoring API for instrumentation, bestie π
(it lives in the User Contributed Perl Documentation section of the manual, and yeah the title got truncated to MongoD...itoring(3pm) because man pages have a character limit and honestly? rude.)
π VERSION π
version v2.2.2 β that's the one, no cap π
πΈ DESCRIPTION πΈ
okay so listen. MongoDB::MongoClient takes an optional attribute called monitoring_callback, and it's literally there so you can spy on all the events happening while the driver is doing its little thing πβ¨
The API is giving extremely simple, and I mean that as a compliment. You hand it a code reference, and for every single event it passes a hashref to that code ref. That's it. That's the whole vibe.
Here's a baby example that just stacks up events in an array:
our @events;
my $cb = sub { push @events, $_[0] };
MongoDB->connect( $uri, { monitoring_callback => $cb } );
iconic behavior honestly π«Ά
π EVENT TYPES π
Every event is a hash reference, and it's got a type field telling you what kind it is, like "command_started". Each type gets its own little spotlight below π«
π₯ Command Monitoring
These events fire for commands going straight to the wire and for the response coming back. main character energy fr.
command_started
This one gets sent just before a command goes on the wire. It'll be followed by either a "command_succeeded" or a "command_failed" event β no cliffhangers left unresolved π
Fields:
type:"command_started"databaseName: the name of the database the command applies tocommandName: the name of the command being executed; for legacy operations that don't use commands, the driver converts them so they look like they're in command form β¨command: a hash reference representing the full command to be sentrequestId: the request identifier sent to the serverconnectionId: address and port of the destination server
command_succeeded
Sent just after a command reply comes in β but only if the database reply document has a non-false "ok" field.
β οΈ NOTE: write errors will have ok:1 even though they have write errors. For writes, success means the write attempt was valid, not that the write actually succeeded. it's giving "technically fine" π
Fields:
type:"command_succeeded"commandName: the name of the command being executeddurationSecs: the elapsed time in seconds since the"command_started"eventreply: a hash reference representing the full database replyrequestId: the request identifier sent to the serverconnectionId: address and port of the destination server
command_failed
Sent just after a command reply arrives β but only if the database reply document has a false "ok" field, or if an exception happened during send or receive operations π
Fields:
type:"command_failed"commandName: the name of the command being executeddurationSecs: the elapsed time in seconds since the"command_started"eventfailure: a string with a error message about the failureeval_error: if an exception occurs, this contains the value of$@when the exception was caughtreply: a hash reference representing the full database reply, or an empty hashref if the failure is due to an exceptionrequestId: the request identifier sent to the serverconnectionId: address and port of the destination server
π¦ Server Discovery and Monitoring
These events fire when servers and topology get amended π
server_opening_event
Sent when a new server is added to the topology π
Fields:
type:"server_opening_event"topologyId: The topology refaddraddress: address of the server
server_closed_event
Sent when a server is removed from the topology π₯²
Fields:
type:"server_closed_event"topologyId: The topology refaddraddress: address of the server
server_description_changed_event
Sent when the server description changes β but not for changes to the RTT, so don't come for me π
Fields:
type:"server_description_changed_event"address: address of the servertopologyId: The topology refaddrpreviousDescription: Server Description before the changenewDescription: Server Description after the change
topology_opening_event
Sent when the topology is created β¨
Fields:
type:"topology_opening_event"topologyId: The topology refaddr
topology_closed_event
Sent when the topology is closed πͺ
Fields:
type:"topology_closed_event"topologyId: The topology refaddr
topology_description_changed_event
Sent when the topology description changes π
Fields:
type:"topology_description_changed_event"topologyId: The topology refaddrpreviousDescription: Topology Description before the changenewDescription: Topology Description after the change
server_heartbeat_started_event
Sent before the ismaster command is sent to the server π
Fields:
type:"server_heartbeat_started_event"connectionId: address of the link to connect to
server_heartbeat_succeeded_event
Sent after the reply from the ismaster command arrives, from a successful reply π«Ά
Fields:
type:"server_heartbeat_succeeded_event"duration: time it took to send and receive a replyreply: the ismaster command replyconnectionId: address of the server
server_heartbeat_failed_event
Sent if there's a failure from the ismaster command, which returns an error string of some sort π
Fields:
type:"server_heartbeat_failed_event"duration: time it took to send and receive a replyfailure: Returns an error string of the failureconnectionId: address of the server
π§ REDACTION π§
oop β certain commands are considered sensitive π When any of these show up in monitoring, the command body and the database reply body get replaced with an empty document. privacy slay.
authenticatesaslStartsaslContinuegetnoncecreateUserupdateUsercopydbgetnoncecopydbsaslstart
π AUTHORS π
shoutout to the icons who made this:
- David Golden <david@mongodb.com>
- Rassi <rassi@mongodb.com>
- Mike Friedman <friedo@friedo.com>
- Kristina Chodorow <k.chodorow@gmail.com>
- Florian Ragwitz <rafl@debian.org>
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2020 by MongoDB, Inc.
It's free software, licensed under:
The Apache License, Version 2.0, January 2004
okay bestie that's the whole thing, you ate that read-through ππ
this was page MongoD...itoring(3pm) from perl v5.40.1, dated 2025-04-03 β go forth and monitor those events fr fr πβ¨π
π¦ where this page comes from
- debian trixie: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu resolute: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- ubuntu stonking: libmongodb-perl 2.2.2-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms