In the Mongodb, I can see there are 54 connections from different applications in my local server. Is there anyway to see which one of my applications are using Mongodb more than the others?
Imagine I have 10 application using mongo db with different names and ports.
This is full MongoDB log:
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] MongoDB starting : pid=10554 port=27017 dbpath=/var/lib/mongodb 64-bit host=s19497827.onlinehome-server.com
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] db version v3.0.14
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] git version: 08352afcca24bfc145240a0fac9d28b978ab77f3
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] build info: Linux ip-10-30-223-232 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 BOOST_LIB_VERSION=1_49
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] allocator: tcmalloc
2017-09-05T11:04:34.772+0430 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2017-09-05T11:04:34.805+0430 W - [initandlisten] Detected unclean shutdown - /var/lib/mongodb/mongod.lock is not empty.
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] journal dir=/var/lib/mongodb/journal
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover begin
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover lsn: 749244
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover /var/lib/mongodb/journal/j._0
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover skipping application of section seq:80 < lsn:749244
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover skipping application of section seq:522054 < lsn:749244
2017-09-05T11:04:34.819+0430 I JOURNAL [initandlisten] recover applying initial journal section with sequence number 749244
2017-09-05T11:04:34.821+0430 I JOURNAL [initandlisten] recover cleaning up
2017-09-05T11:04:34.821+0430 I JOURNAL [initandlisten] removeJournalFiles
2017-09-05T11:04:34.822+0430 I JOURNAL [initandlisten] recover done
2017-09-05T11:04:34.847+0430 I JOURNAL [durability] Durability thread started
2017-09-05T11:04:34.847+0430 I JOURNAL [journal writer] Journal writer thread started
2017-09-05T11:04:34.847+0430 I CONTROL [initandlisten]
2017-09-05T11:04:34.847+0430 I CONTROL [initandlisten] ** WARNING: You are running in OpenVZ which can cause issues on versions of RHEL older than RHEL6.
2017-09-05T11:04:34.848+0430 I CONTROL [initandlisten]
2017-09-05T11:04:34.952+0430 I NETWORK [initandlisten] waiting for connections on port 27017
2017-09-05T11:04:37.040+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55262 #1 (1 connection now open)
2017-09-05T11:04:37.040+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55264 #2 (2 connections now open)
2017-09-05T11:04:37.041+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55266 #3 (3 connections now open)
2017-09-05T11:04:37.042+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55268 #4 (4 connections now open)
2017-09-05T11:04:37.043+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55270 #5 (5 connections now open)
2017-09-05T11:04:37.043+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55272 #6 (6 connections now open)
2017-09-05T11:04:37.043+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55274 #7 (7 connections now open)
2017-09-05T11:04:37.043+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55276 #8 (8 connections now open)
2017-09-05T11:04:37.043+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55278 #9 (9 connections now open)
2017-09-05T11:04:37.044+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55280 #10 (10 connections now open)
2017-09-05T11:04:37.044+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55282 #11 (11 connections now open)
2017-09-05T11:04:37.045+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55284 #12 (12 connections now open)
2017-09-05T11:04:37.046+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55286 #13 (13 connections now open)
2017-09-05T11:04:37.047+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55288 #14 (14 connections now open)
2017-09-05T11:04:37.047+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55290 #15 (15 connections now open)
2017-09-05T11:04:37.058+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55292 #16 (16 connections now open)
2017-09-05T11:04:37.525+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55324 #17 (17 connections now open)
2017-09-05T11:04:37.870+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55348 #18 (18 connections now open)
2017-09-05T11:04:38.030+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55360 #19 (19 connections now open)
2017-09-05T11:04:38.097+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55366 #20 (20 connections now open)
2017-09-05T11:04:38.527+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55396 #21 (21 connections now open)
2017-09-05T11:04:38.545+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55398 #22 (22 connections now open)
2017-09-05T11:04:38.958+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55430 #23 (23 connections now open)
2017-09-05T11:04:38.964+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55432 #24 (24 connections now open)
2017-09-05T11:04:38.966+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55434 #25 (25 connections now open)
2017-09-05T11:04:38.971+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55436 #26 (26 connections now open)
2017-09-05T11:04:38.993+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55440 #27 (27 connections now open)
2017-09-05T11:04:38.996+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55442 #28 (28 connections now open)
2017-09-05T11:04:38.998+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55444 #29 (29 connections now open)
2017-09-05T11:04:38.998+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55446 #30 (30 connections now open)
2017-09-05T11:04:39.001+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55448 #31 (31 connections now open)
2017-09-05T11:04:39.002+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55450 #32 (32 connections now open)
2017-09-05T11:04:39.002+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55452 #33 (33 connections now open)
2017-09-05T11:04:39.113+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55460 #34 (34 connections now open)
2017-09-05T11:04:39.132+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55464 #35 (35 connections now open)
2017-09-05T11:04:39.147+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55466 #36 (36 connections now open)
2017-09-05T11:04:39.148+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55470 #37 (37 connections now open)
2017-09-05T11:04:39.616+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55496 #38 (38 connections now open)
2017-09-05T11:04:39.622+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55498 #39 (39 connections now open)
2017-09-05T11:04:40.295+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55540 #40 (40 connections now open)
2017-09-05T11:04:40.351+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55546 #41 (41 connections now open)
2017-09-05T11:04:40.576+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55562 #42 (42 connections now open)
2017-09-05T11:04:41.106+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55594 #43 (43 connections now open)
2017-09-05T11:04:41.246+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55608 #44 (44 connections now open)
2017-09-05T11:04:41.615+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55630 #45 (45 connections now open)
2017-09-05T11:04:41.621+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55632 #46 (46 connections now open)
2017-09-05T11:04:41.625+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55634 #47 (47 connections now open)
2017-09-05T11:04:41.625+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55636 #48 (48 connections now open)
2017-09-05T11:04:41.652+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55638 #49 (49 connections now open)
2017-09-05T11:04:42.300+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55682 #50 (50 connections now open)
2017-09-05T11:04:42.609+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55698 #51 (51 connections now open)
2017-09-05T11:04:42.682+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55702 #52 (52 connections now open)
2017-09-05T11:04:42.979+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55722 #53 (53 connections now open)
2017-09-05T11:04:43.161+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55740 #54 (54 connections now open)
2017-09-05T11:04:43.711+0430 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55780 #55 (55 connections now open)
When I run the command:
sudo lsof | grep mongod | grep TCP
The result is:
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
lsof: WARNING: can't stat() fuse.mongobooster-4.0.2-x86_64.AppImage file system /tmp/.mount_XnRJeB
Output information may be incomplete.
mongod 10082 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
signalP.g 10082 10083 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
signalP.g 10082 10083 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
signalP.g 10082 10083 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
signalP.g 10082 10083 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
Backgro.k 10082 10084 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
Backgro.k 10082 10084 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
Backgro.k 10082 10084 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
Backgro.k 10082 10084 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10089 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10089 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10089 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10089 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10090 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10090 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10090 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10090 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10091 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10091 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10091 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10091 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10092 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10092 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10092 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10092 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10093 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10093 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10093 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10093 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10094 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10094 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10094 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10094 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10095 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10095 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10095 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10095 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10096 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10096 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10096 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10096 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
mongod 10082 10097 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
mongod 10082 10097 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
mongod 10082 10097 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
mongod 10082 10097 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
WTJourn.F 10082 10098 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
WTJourn.F 10082 10098 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
WTJourn.F 10082 10098 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
WTJourn.F 10082 10098 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
DeadlineM 10082 10099 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
DeadlineM 10082 10099 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
DeadlineM 10082 10099 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
DeadlineM 10082 10099 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
ftdc 10082 10100 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
ftdc 10082 10100 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
ftdc 10082 10100 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
ftdc 10082 10100 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
RangeDele 10082 10101 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
RangeDele 10082 10101 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
RangeDele 10082 10101 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
RangeDele 10082 10101 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
TTLMonito 10082 10102 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
TTLMonito 10082 10102 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
TTLMonito 10082 10102 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
TTLMonito 10082 10102 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
clientcur 10082 10103 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
clientcur 10082 10103 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
clientcur 10082 10103 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
clientcur 10082 10103 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
Periodi.k 10082 10104 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
Periodi.k 10082 10104 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
Periodi.k 10082 10104 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
Periodi.k 10082 10104 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
thread1 10082 10105 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
thread1 10082 10105 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
thread1 10082 10105 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
thread1 10082 10105 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
conn2 10082 10122 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
conn2 10082 10122 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
conn2 10082 10122 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
conn2 10082 10122 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
conn3 10082 10123 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
conn3 10082 10123 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
conn3 10082 10123 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
conn3 10082 10123 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
conn4 10082 10124 mongodb 7u IPv4 74307 0t0 TCP localhost:27017 (LISTEN)
conn4 10082 10124 mongodb 40u IPv4 167764 0t0 TCP localhost:27017->localhost:52582 (ESTABLISHED)
conn4 10082 10124 mongodb 41u IPv4 167765 0t0 TCP localhost:27017->localhost:52584 (ESTABLISHED)
conn4 10082 10124 mongodb 42u IPv4 167766 0t0 TCP localhost:27017->localhost:52586 (ESTABLISHED)
Best Answer
As per your log i am able to see you are using linux O.S. So, the below grep command you are able to see how connections open to the MongoDB port (27017) on my computer.
As per you log statement, After execution the above query . which you have already said in your question statement.
I am able to see your log statement like
I would like to say that here in your case
three connections
open for the mongodb by default port27017
.And for the number of connection
It gives no of connections opend and avail but not shows the connections from which client.
Even you can also get directly by querying
for your ref Here