search

Home  >  Q&A  >  body text

Connection positioning of mongodb sharded cluster logs

How to locate conn10217 in the mongodb log fragment "I COMMAND [conn10217]" which is the command request initiated by the mongos connection, and which server (ip) the request came from.

phpcn_u1582phpcn_u15822770 days ago541

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-02 09:27:04

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

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

    2. It can be seen from the source code that the number after conn is the internally allocated connection id, and by observing the startup log of mongodb, it is found that this id starts from 1 and increases by 1 each time, and the peer information (ip) will be printed in the log. :port) and the connectionId after #.

    3. In summary, you only need to filter the mongodb 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"

    reply
    0
  • Cancelreply