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.