Is there any way of getting the server IP from which db call is happening.
Mongodb is a sharded cluster of 3 and applications are running of kuberentes pods on different server
Hi @Aman_Saxena,
First, not every database query is logged by default , only the ‘slow’ queries that exceed 100ms.
If the slow queries are the one of interest that is fine, otherwise the slow query threshold can be adjusted by using https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel for example db.setProfilingLevel(0,0)
will log all queries.
Each query logged will have a attr.remote
field which is the ip/port of the client issuing the query.
For a sharded cluster this will be logged on the mongos.
Example:
{“t”:{“$date”:“2024-05-01T15:33:28.725+00:00”},“s”:“I”, “c”:“COMMAND”, “id”:51803, “ctx”:“conn2”,“msg”:“Slow query”,“attr”:{“type”:“command”,“ns”:“test.foo”,“appName”:“mongosh 2.2.5”,“command”:{“find”:“foo”,“filter”:{},“lsid”:{“id”:{“$uuid”:“b153ca90-522d-4a3d-a884-c2972ea86684”}},“$db”:“test”},“planSummary”:“EOF”,“planningTimeMicros”:50,“keysExamined”:0,“docsExamined”:0,“nBatches”:1,“cursorExhausted”:true,“numYields”:0,“nreturned”:0,“queryFramework”:“classic”,“reslen”:97,“locks”:{“FeatureCompatibilityVersion”:{“acquireCount”:{“r”:1}},“Global”:{“acquireCount”:{“r”:1}}},“storage”:{},“cpuNanos”:99127,“remote”:“172.17.0.1:44562”,“protocol”:“op_msg”,“durationMillis”:0}}
The remote client for this query was:
remote":"172.17.0.1:44562
Edit:
Be sure to set the profiler back to the default of 100ms db.setProfilingLevel(0,100)
as this can generate a LOT of logs if left at 0ms.
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
WiredTiger Crash Report | 0 | 562 | Apr 2024 |
High disk space usage | 3 | 509 | Nov 2024 |
Cloud Manager Support past 4.2 questions | 0 | 441 | Jun 2024 |
Podman Mongo db Replication - host dns getting resolved to 127.0.0.1 | 0 | 348 | Jul 2024 |
Mongodb-community v7 mongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017 | 1 | 244 | Aug 2024 |