Listing Sessions in Sharded Cluster

258 views
Skip to first unread message

rohit reddy

unread,
Jun 12, 2018, 11:40:46 AM6/12/18
to mongodb-user
Hello,
I am trying to list all the sessions connected to my sharded cluster and i want to do some agrregation to find out the following:-
a. Number of sessions by user
b. Number of sessions from client machine
c. Number of sessions by user from one sepcific client machine.



For this i am trying to use the $listSessions and $listLocalSessions

From the command, i know that i have more than 6500 sessions currently connected.
mongos> db.serverStatus().connections
{ "current" : 6553, "available" : 0, "totalCreated" : 6553 }

However, when i do the following commands,they do not return the list of seessions.

use config
mongos> db.aggregate( [  { $listLocalSessions: { allUsers: true } } ] )    ### this command returns nothing


use config
db.system.sessions.aggregate( [  { $listSessions: { allUsers: true } } ] )  ## this command returns only 20 sessions from nagios client, but does not list any of my client connection.


I have the following roles for my account.

"db" : "admin",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                },
                {
                        "role" : "userAdminAnyDatabase",
                        "db" : "admin"
                },
                {
                        "role" : "clusterAdmin",
                        "db" : "admin"
                }


Am i doing something incorrect here. any help is greatly appreciated.

Thanks
Rohit Reddy
 

Kevin Adistambha

unread,
Jul 2, 2018, 2:23:54 AM7/2/18
to mongodb-user

Hi Rohit

Are you trying to find out the connections or sessions related to some client? Those are two very different things, with sessions being introduced in MongoDB 3.6.

In terms of connections, there is currently no method to list them by user or addresses from within the mongo shell. Having said that, the information are present in the mongod log files and can be extracted by the mloginfo tool which is part of the mtools suite of tools. The mloginfo --connections <log file> command would show an output similar to:

$ mloginfo --connections mongod.log
     source: mongod.log
       host: unknown
      start: 2018 Mar 21 23:15:09.065
        end: 2018 Mar 22 00:14:47.980
date format: iso8601-local
     length: 3493
     binary: unknown
    version: >= 3.0 (iso8601 format, level, component)
    storage: unknown

CONNECTIONS
     total opened: 449
     total closed: 359
    no unique IPs: 12
socket exceptions: 1

192.168.111.86    opened: 110       closed: 89
192.168.112.161   opened: 108       closed: 80
192.168.114.86    opened: 107       closed: 85
....

However please note that this tool was not designed to show this information in real-time.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages