Skip to content

Commit de05238

Browse files
committed
wip
1 parent 46de623 commit de05238

File tree

6 files changed

+157
-80
lines changed

6 files changed

+157
-80
lines changed

source/crud.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ CRUD Operations
2626
Query Documents </query>
2727
Update Documents </update>
2828
Delete Documents </delete>
29-
Bulk Write Operations </write/bulk-write>
30-
Transactions </write/transactions>
31-
32-
configure CRUD
33-
retryable reads
34-
retryable writes
35-
Store Large Files </write/gridfs>
36-
geospatial
29+
Bulk Write Operations </bulk-write>
30+
Transactions </transactions>
31+
Configure CRUD Operations </configure>
32+
Store Large Files </gridfs>
33+
Geospatial Queries </geospatial>
3734

3835
Overview
3936
--------

source/crud/configure.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Overview
2323

2424
In this guide, you can learn how to configure read and write operations in {+driver-short+}.
2525

26+
Read and Write Settings
27+
-----------------------
28+
2629
You can control how the driver routes read operations by setting a **read preference**.
2730
You can also control options for how the driver waits for acknowledgment of
2831
read and write operations on a replica set by setting a **read concern** and a
@@ -86,7 +89,7 @@ MongoDB Server manual:
8689
- :manual:`Write Concern </reference/write-concern/>`
8790

8891
Tag Sets
89-
~~~~~~~~
92+
--------
9093

9194
In {+mdb-server+}, you can apply key-value :manual:`tags
9295
</core/read-preference-tags/>` to replica-set
@@ -110,7 +113,7 @@ center (``'dc': 'sf'``):
110113
'test', read_preference=Secondary([{'dc': 'ny'}, {'dc': 'sf'}]))
111114

112115
Local Threshold
113-
~~~~~~~~~~~~~~~
116+
---------------
114117

115118
If multiple replica-set members match the read preference and tag sets you specify,
116119
{+driver-short+} reads from the nearest replica-set members, chosen according to
@@ -140,7 +143,7 @@ within 35 milliseconds of the closest member's ping time.
140143
command-line option.
141144

142145
Retryable Reads and Writes
143-
~~~~~~~~~~~~~~~~~~~~~~~~~~
146+
--------------------------
144147

145148
{+driver-short+} automatically retries certain read and write operations a single time
146149
if they fail due to a network or server error.

source/index.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ MongoDB {+driver-short+} Documentation
1818
Data Formats </data-formats>
1919
Indexes </indexes>
2020
Run a Database Command </run-command>
21-
Logging </logging> Monitoring </monitoring>
21+
Atlas Search <https://www.mongodb.com/docs/atlas/atlas-search/>
22+
Atlas Vector Search <https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/>
23+
Time Series </time-series>
24+
Change Streams </change-streams>
25+
Logging and Monitoring </logging-and-monitoring>
2226
Security </security>
2327
Versioning
2428
API Documentation <{+api-root+}>
2529
Issues & Help </issues-and-help>
2630

2731
Databases & Collections </databases-collections>
28-
Write Data </write-operations>
29-
Read Data </read>
3032
Aggregation </aggregation>
3133
Serialization </serialization>
3234
Third-Party Tools </tools>

source/logging-and-monitoring.txt

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
.. _pymongo-monitoring-logging:
2+
3+
======================
4+
Monitoring and Logging
5+
======================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: debugging, printing, event, subscribe, listener
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to configure **monitoring** in {+driver-short+}
24+
by using {+driver-short+}'s callback-based interface. Monitoring is the process of
25+
gathering information about your application's performance and resource usage as it runs.
26+
This can help you make informed decisions when designing and debugging your application.
27+
28+
This guide also covers **logging**, which lets you record information obtained during
29+
monitoring to an external log.
30+
31+
Event Types
32+
-----------
33+
34+
The driver provides information about your application by emitting events. You can
35+
listen for driver events to monitor your application.
36+
37+
The type of event that the driver emits depends on the operation being performed.
38+
The following table describes the types of events that the driver emits:
39+
40+
.. list-table::
41+
:header-rows: 1
42+
:widths: 30 70
43+
44+
* - Event Type
45+
- Description
46+
* - Command events
47+
- Events related to MongoDB database commands, such as ``find``, ``insert``,
48+
``delete``, and ``count``. To learn how to use {+driver-short+} to run a
49+
database command, see :ref:`<pymongo-run-command>`. For more information about
50+
MongoDB database commands, see :manual:`Database Commands </reference/command/>`
51+
in the {+mdb-server+} manual.
52+
53+
As a security measure, the driver redacts the contents of some
54+
command events. This protects the sensitive information contained in these command
55+
events.
56+
57+
* - Server Discovery and Monitoring (SDAM) events
58+
- Events related to changes in the state of the MongoDB deployment.
59+
60+
* - Connection Pool events
61+
- Events related to the connection pool held by the driver.
62+
63+
For a complete list of events the driver emits, see the
64+
`pymongo.monitoring <{+api-root+}pymongo/monitoring.html>`__ API documentation.
65+
66+
Listening for Events
67+
--------------------
68+
69+
To monitor an event, you must pass an event listener to your application's ``MongoClient``.
70+
The following steps describe how to monitor your application by using an event listener:
71+
72+
1. Create a class that inherits from one of the event listener base classes
73+
provided by {+driver-short+}. The base class you choose depends on the type of event
74+
you want to monitor. For example, to monitor command events, create a class
75+
that inherits from ``CommandListener``.
76+
#. Implement the methods of the base class that correpond to the events you want to monitor.
77+
#. Pass an instance of your listener class to the ``MongoClient`` constructor.
78+
79+
The following code implements a ``CommandListener`` to listen for command events, a
80+
``ServerListener`` to listen for SDAM events, and a ``ConnectionPoolListener`` to listen for
81+
connection pool events:
82+
83+
.. literalinclude:: /includes/monitoring/monitoring.py
84+
:language: python
85+
:start-after: start-monitoring
86+
:end-before: end-monitoring
87+
:copyable: true
88+
89+
Logging
90+
-------
91+
92+
{+driver-short+} supports {+language+}'s native logging library. You can configure the logging
93+
verbosity for the following components:
94+
95+
- ``pymongo.command``, which logs command operations
96+
- ``pymongo.connection``, which logs connection management operations
97+
- ``pymongo.serverSelection``, which logs server selection operations
98+
99+
In addition to configuring these options individually, you can configure the global
100+
logging level by setting the log level on ``pymongo``. To learn more about the native
101+
logging library, see the `Python logging library documentation <https://docs.python.org/3/howto/logging.html>`__.
102+
103+
Examples
104+
~~~~~~~~
105+
106+
The following example sets the global logging level to ``INFO``:
107+
108+
.. code-block:: python
109+
110+
import logging
111+
logging.getLogger("pymongo").setLevel(logging.INFO)
112+
113+
The following example sets the log level on the ``pymongo.command`` component to
114+
``DEBUG``:
115+
116+
.. code-block:: python
117+
118+
import logging
119+
logging.getLogger("pymongo.command").setLevel(logging.DEBUG)
120+
121+
Configuring Truncation
122+
~~~~~~~~~~~~~~~~~~~~~~
123+
124+
If you enable logging for the ``pymongo.command`` component, the resulting logs will
125+
be truncated after 1000 bytes by default. You can configure this truncation limit
126+
by setting the ``MONGODB_LOG_MAX_DOCUMENT_LENGTH`` environment variable to your
127+
desired length, as shown in the following example:
128+
129+
.. code-block:: python
130+
131+
import os
132+
os.environ["MONGODB_LOG_MAX_DOCUMENT_LENGTH"] = "2000"
133+
134+
API Documentation
135+
-----------------
136+
137+
To learn more about the methods and classes used to monitor events in the driver, see the
138+
following API documentation:
139+
140+
- `monitoring <{+api-root+}pymongo/monitoring.html>`__
141+
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__

source/logging.txt

Lines changed: 0 additions & 66 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)