Connection Location of mongodb Fragmented Cluster Logs

  mongodb, question

How to locate from conn10217 in mongodb’s log fragment “I COMMAND [conn10217]” to the originating command request connected by mongos, and to which server (ip) the request is located.

1. By looking at mongodb’s source code, there is such a code in client thread initialization.

string fullDesc = desc;
 if ( str::equals( "conn" , desc ) && mp !  = NULL )
 fullDesc = str::stream() << desc << mp->connectionId();

2. From the source code, it can be seen that the number after conn is the internal assigned connection id, and by observing mongodb’s startup log, it is found that this id is incremented by 1 every time starting from 1, and the log will print out the opposite information (ip:port) and the connectionId after #.
图片描述

3. To sum up, it is only necessary to filter mongodb’s log mongod.log (my log file name here is mongod.log) to locate which host sent the command. The command is as follows:

cat mongod.log | grep accept | grep "#10217"

图片描述