MongoDb에 대한 현재 연결 수를 확인합니다.
특정 MongoDB 서버에 접속되어 있는 클라이언트의 수를 취득하기 위한 명령어는 무엇입니까?
관리 데이터베이스에 연결하여 실행db.serverStatus():
> var status = db.serverStatus()
> status.connections
{"current" : 21, "available" : 15979}
>
문의하면 직접 얻을 수 있습니다.
db.serverStatus().connections
MongoDb의 기능을 이해하려면db.serverStatus().connectionsresponse mean은 매뉴얼을 참조해 주십시오.
접속
"connections" : { "current" : <num>, "available" : <num>, "totalCreated" : NumberLong(<num>) },연결 - 연결 상태를 보고하는 문서입니다.이 값을 사용하여 서버의 현재 부하 및 용량 요건을 평가합니다.
connections.current 클라이언트에서 데이터베이스 서버로의 착신 접속 수.이 숫자에는 현재 셸 세션이 포함됩니다.이 데이터에 컨텍스트를 추가하려면 connections.available 값을 고려하십시오.
이 값에는 셸 연결이나 복제 세트 구성원이나 mongos 인스턴스 등의 다른 서버로부터의 연결을 포함한 모든 수신 연결이 포함됩니다.
connections.available 미사용 착신 접속 수.이 값을 connections.current 값과 조합하여 데이터베이스의 연결 부하를 이해하고 UNIX ulimit Settings 문서에서 사용 가능한 연결의 시스템 임계값에 대한 자세한 내용을 확인하십시오.
connections.totalCreated 서버에 생성된 모든 착신 연결 수입니다.이 숫자에는 이후 닫힌 연결이 포함됩니다.
클라이언트별 접속수IP(합계)
이를 사용하여 IPAddress별 연결 수를 총 연결 수로 표시합니다.이것은 문제를 디버깅하는 데 큰 도움이 되었습니다.최대 연결 수를 기록하기 전에 도착해!
Mongo Shell의 경우:
db.currentOp(true).inprog.reduce((accumulator, connection) => { ipaddress = connection.client ? connection.client.split(":")[0] : "Internal"; accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1; accumulator["TOTAL_CONNECTION_COUNT"]++; return accumulator; }, { TOTAL_CONNECTION_COUNT: 0 })
포맷 완료:
db.currentOp(true).inprog.reduce(
(accumulator, connection) => {
ipaddress = connection.client ? connection.client.split(":")[0] : "Internal";
accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1;
accumulator["TOTAL_CONNECTION_COUNT"]++;
return accumulator;
},
{ TOTAL_CONNECTION_COUNT: 0 }
)
반환 예:
{
"TOTAL_CONNECTION_COUNT" : 331,
"192.168.253.72" : 8,
"192.168.254.42" : 17,
"127.0.0.1" : 3,
"192.168.248.66" : 2,
"11.178.12.244" : 2,
"Internal" : 41,
"3.100.12.33" : 86,
"11.148.23.34" : 168,
"81.127.34.11" : 1,
"84.147.25.17" : 3
}
(Atlas 내부 모니터링의 192.x.x.x 주소)
"내부"는 외부 클라이언트가 없는 내부 프로세스입니다.다음과 같이 다음 목록을 볼 수 있습니다.
db.currentOp(true).inprog.filter(connection => !connection.client).map(connection => connection.desc);
db.serverStatus()는 open 및 available 연결 중 no를 제공하지만 클라이언트의 연결은 표시하지 않습니다.자세한 내용은 다음 명령을 사용하십시오.sudo lsof | grep mongod | grep TCP리플리케이션을 했을 때 필요하고 프라이머리 노드의 클라이언트 접속은 세컨더리 노드보다 크다.
$ sudo lsof | grep mongod | grep TCP
mongod 5733 Al 6u IPv4 0x08761278 0t0 TCP *:28017 (LISTEN)
mongod 5733 Al 7u IPv4 0x07c7eb98 0t0 TCP *:27017 (LISTEN)
mongod 5733 Al 9u IPv4 0x08761688 0t0 TCP 192.168.1.103:27017->192.168.1.103:64752 (ESTABLISHED)
mongod 5733 Al 12u IPv4 0x08761a98 0t0 TCP 192.168.1.103:27017->192.168.1.103:64754 (ESTABLISHED)
mongod 5733 Al 13u IPv4 0x095fa748 0t0 TCP 192.168.1.103:27017->192.168.1.103:64770 (ESTABLISHED)
mongod 5733 Al 14u IPv4 0x095f86c8 0t0 TCP 192.168.1.103:27017->192.168.1.103:64775 (ESTABLISHED)
mongod 5733 Al 17u IPv4 0x08764748 0t0 TCP 192.168.1.103:27017->192.168.1.103:64777 (ESTABLISHED)
현재 컴퓨터의 MongoDB 포트(27017)에 5개의 접속이 열려 있는 것을 나타냅니다.제 경우 Scalatra 서버에서 MongoDB에 접속하고 있으며 MongoDB Casbah 드라이버를 사용하고 있지만 사용하는 클라이언트에 관계없이 (TCP/IP를 사용하여 접속하고 있는 한) 동일한 lsof TCP 연결이 표시됩니다.
그냥 사용하시면 됩니다.
db.serverStatus().connections
또한 이 기능은 Mongo DB에 연결된 IP 주소를 찾는 데 도움이 됩니다.
db.currentOp(true).inprog.forEach(function(x) { print(x.client) })
mongo 데이터베이스에 대한 모든 연결을 다음 명령으로 확인하려고 했습니다.
netstat -anp --tcp --udp | grep mongo
이 명령어는 mongodb의 모든 tcp 접속을 보다 상세하게 표시할 수 있습니다.
tcp 0 0 10.26.2.185:27017 10.26.2.1:2715 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.1:1702 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.185:39506 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.185:40021 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.185:39509 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.184:46062 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.184:46073 ESTABLISHED 1442/./mongod
tcp 0 0 10.26.2.185:27017 10.26.2.184:46074 ESTABLISHED 1442/./mongod
OS X 에서는, 네트워크 인터페이스상의 접속도 직접 참조해 주세요.
$ lsof -n -i4TCP:27017
mongod 2191 inanc 7u IPv4 0xab6d9f844e21142f 0t0 TCP 127.0.0.1:27017 (LISTEN)
mongod 2191 inanc 33u IPv4 0xab6d9f84604cd757 0t0 TCP 127.0.0.1:27017->127.0.0.1:56078 (ESTABLISHED)
stores.te 18704 inanc 6u IPv4 0xab6d9f84604d404f 0t0 TCP 127.0.0.1:56078->127.0.0.1:27017 (ESTABLISHED)
" " " 를 할 필요가 .
grepetc를 하면 됩니다lsof의 인수입니다.MongoDb의 CLI 연결도 참조하고 @milan의 답변도 참조하십시오(편집한 지 얼마 안 됨).
다음과의 좀 더 설명해 주세요.db.currentOp(true)
출처: https://jira.mongodb.org/browse/SERVER-5085
이것은 오래된 게시물이고 현재 이전보다 더 많은 옵션이 제공되고 있기 때문에 죄송합니다.
db.getSiblingDB("admin").aggregate( [
{ $currentOp: { allUsers: true, idleConnections: true, idleSessions: true } }
,{$project:{
"_id":0
,client:{$arrayElemAt:[ {$split:["$client",":"]}, 0 ] }
,curr_active:{$cond:[{$eq:["$active",true]},1,0]}
,curr_inactive:{$cond:[{$eq:["$active",false]},1,0]}
}
}
,{$match:{client:{$ne: null}}}
,{$group:{_id:"$client",curr_active:{$sum:"$curr_active"},curr_inactive:{$sum:"$curr_inactive"},total:{$sum:1}}}
,{$sort:{total:-1}}
] )
출력 예:
{ "_id" : "xxx.xxx.xxx.78", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.76", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.73", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.77", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.74", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.75", "curr_active" : 0, "curr_inactive" : 1428, "total" : 1428 }
{ "_id" : "xxx.xxx.xxx.58", "curr_active" : 0, "curr_inactive" : 510, "total" : 510 }
{ "_id" : "xxx.xxx.xxx.57", "curr_active" : 0, "curr_inactive" : 459, "total" : 459 }
{ "_id" : "xxx.xxx.xxx.55", "curr_active" : 0, "curr_inactive" : 459, "total" : 459 }
{ "_id" : "xxx.xxx.xxx.56", "curr_active" : 0, "curr_inactive" : 408, "total" : 408 }
{ "_id" : "xxx.xxx.xxx.47", "curr_active" : 1, "curr_inactive" : 11, "total" : 12 }
{ "_id" : "xxx.xxx.xxx.48", "curr_active" : 1, "curr_inactive" : 7, "total" : 8 }
{ "_id" : "xxx.xxx.xxx.51", "curr_active" : 0, "curr_inactive" : 8, "total" : 8 }
{ "_id" : "xxx.xxx.xxx.46", "curr_active" : 0, "curr_inactive" : 8, "total" : 8 }
{ "_id" : "xxx.xxx.xxx.52", "curr_active" : 0, "curr_inactive" : 6, "total" : 6 }
{ "_id" : "127.0.0.1", "curr_active" : 1, "curr_inactive" : 0, "total" : 1 }
{ "_id" : "xxx.xxx.xxx.3", "curr_active" : 0, "curr_inactive" : 1, "total" : 1 }
mongo-shell을 사용하여 MongoDB에 연결하고 다음 명령을 실행합니다.
db.serverStatus().connections
예:
mongo> db.serverStatus().connections
{ "current" : 3, "available" : 816, "totalCreated" : NumberLong(1270) }
db.runCommand ( { "connPoolStats" : 1 } )
{
"numClientConnections" : 0,
"numAScopedConnections" : 0,
"totalInUse" : 0,
"totalAvailable" : 0,
"totalCreated" : 0,
"hosts" : {
},
"replicaSets" : {
},
"ok" : 1
}
로컬 시스템에서 mongodb 인스턴스에 연결
- sudo mongo "mongodb://MONGO_HOST_IP:27017" --authentication 데이터베이스 관리자
접속되어 있는 모든 클라이언트와 그 상세 내용을 알 수 있습니다.
-
db.currentOp(true)
또는 Mongo Atlas에 로그인한 후 클러스터로 이동하여 연결 상태를 확인할 수 있습니다.
언급URL : https://stackoverflow.com/questions/8975531/check-the-current-number-of-connections-to-mongodb
'programing' 카테고리의 다른 글
| Oracle SQL 이스케이프 문자('&'의 경우) (0) | 2023.03.03 |
|---|---|
| 배열에 존재하는 값을 기반으로 한ng-show (0) | 2023.03.03 |
| 돔 렌더링이 완료된 후 디렉티브를 실행하려면 어떻게 해야 합니까? (0) | 2023.02.26 |
| Angular에서의 지시 장치 테스트에서 서비스를 주입하는 방법JS (0) | 2023.02.26 |
| 스프링 MVC와 스프링부츠의 차이점 (0) | 2023.02.26 |
