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 |
---|---|---|---|
MongoS 5.0.28 segfault with signal 11 | 0 | 91 | Aug 2024 |
Issue with Cluster Monitoring: Changing Hostname from localhost to 19b7c27076e1 | 0 | 19 | Sep 2024 |
Mongod.service; disabled - how to find the root cause | 1 | 101 | Oct 2024 |
Error accepting new connection on local endpoint | 1 | 117 | Oct 2024 |
Is mogodb free on self managed system? | 1 | 46 | Nov 2024 |