Docs Menu
Docs Home
/
MongoDB 데이터베이스 도구
/

mongostat 예시

이 페이지의 내용

이 페이지에서는 mongostat에 대한 예시를 보여줍니다.

mongo shell이 아닌 시스템 명령줄에서 mongostat을 실행하세요.

첫 번째 예에서 mongostat 는 20초 동안 1초마다 데이터를 반환합니다. mongostat는 포트 27017의 로컬호스트 인터페이스에서 실행 중인 mongod 인스턴스에서 데이터를 수집합니다. 다음 호출은 모두 동일한 동작을 생성합니다.

mongostat --rowcount=20 1
mongostat --rowcount=20
mongostat -n=20 1
mongostat -n=20

다음 예제에서 mongostat은 프로그램이 실행되는 동안 5분(또는 300초)마다 데이터를 반환합니다. mongostat은 포트 27017의 로컬호스트 인터페이스에서 실행 중인 mongod 인스턴스에서 데이터를 수집합니다. 다음 호출은 동일한 동작을 생성합니다.

mongostat --rowcount=0 300
mongostat -n=0 300
mongostat 300

다음 예제에서 mongostat 은 1시간 동안 5 분마다 데이터를 반환합니다(12 번). mongostat 은 포트 27017 의 로컬 호스트 인터페이스에서 실행되는 mongod 인스턴스에서 데이터를 수집합니다. 다음 호출은 동일한 동작을 생성합니다.

mongostat --rowcount=12 300
mongostat -n=12 300

-O 를 사용하면 serverStatus 출력의 필드를 지정하여 기본 mongostat 출력에 추가할 수 있습니다. 사용자 지정 파일 이름에 공백을 포함하는 경우 필드 이름 주위에 추가 따옴표를 넣지 마세요.

다음 예시는 기본 mongostat 출력에 필드를 추가합니다.

mongostat -O='host,version,network.numRequests=network requests'

mongostat 출력은 다음과 유사합니다.

insert query update delete getmore command dirty used flushes vsize res qrw arw net_in net_out conn time host version network requests
*0 *0 *0 *0 0 2|0 0.0% 0.0% 0 2.51G 19.0M 0|0 0|0 158b 39.4k 2 Oct 11 12:14:45.878 localhost:37017 3.3.14 91
*0 *0 *0 *0 0 1|0 0.0% 0.0% 0 2.51G 19.0M 0|0 0|0 157b 39.3k 2 Oct 11 12:14:46.879 localhost:37017 3.3.14 95
*0 *0 *0 *0 0 1|0 0.0% 0.0% 0 2.51G 19.0M 0|0 0|0 157b 39.2k 2 Oct 11 12:14:47.884 localhost:37017 3.3.14 99

기본 출력에 추가되는 필드는 다음과 같습니다.

network.numRequests 필드에는 '네트워크 요청'이라는 사용자 정의 필드 이름이 있습니다.

-o는 출력에 포함할 mongostat 열을 지정합니다. 모든 serverStatus 필드를 mongostat 출력 열로 지정할 수 있습니다.

다음 예시에서는 mongostat에 대한 사용자 지정 필드를 사용합니다.

mongostat --port 27500 -o='host,opcounters.insert.rate()=Insert Rate,opcounters.query.rate()=Query Rate,opcounters.command.rate()=Command Rate,wiredTiger.cache.pages requested from the cache=Pages Req,metrics.document.inserted=inserted rate'

mongostat 출력은 다음과 유사합니다.

host Insert Rate Query Rate Command Rate Pages Req Inserted Rate
localhost:27500 180 1 8 2999446 9638
localhost:27500 40 3 12 2999601 9678
localhost:27500 181 2 9 3000207 9859
localhost:27500 39 2 12 3000362 9899
localhost:27500 181 2 11 3000969 10080
localhost:27500 39 2 10 3001124 10120

카운터 및 해당 사용자 지정 필드 이름은 다음과 같습니다:

카운터
사용자 지정 필드 이름
opcounters.insert.rate
삽입 속도
opcounters.query.rate
쿼리 속도
opcounters.command.rate
명령 속도
캐시에서 요청된 wiredTiger.cache.pages
페이지 요구 사항
metrics.document.inserted
삽입 속도

.rate()(을)를 사용하면 숫자 필드가 하나의 mongostat 호출에서 다음 호출로 변경된 초당 속도를 볼 수 있습니다. 예를 들어, 삽입 작업 중에 문서가 삽입된 속도를 볼 수 있습니다. 따라서 .rate()(은)는 mongod 인스턴스의 성능을 확인하는 데 도움이 될 수 있습니다.

다음 예에서는 metrics.document.inserted serverStatus 필드의 변화율을 보고합니다. 이 호출은 -o 의 열 이름 지정 기능을 사용하여 metrics.document.inserted.rate() 를 '삽입된 속도(inserted rate)'로, metrics.document.inserted 를 '삽입됨(inserted)'으로 레이블합니다.

mongostat -o='host,mem,bits,metrics.document.inserted.rate()=inserted rate,metrics.document.inserted=inserted' --rowcount=5

이 경우 출력은 다음과 유사합니다:

host mem.bits inserted rate inserted
localhost:37017 64 501 3455
localhost:37017 64 967 13128
localhost:37017 64 972 22851
localhost:37017 64 214 25000
localhost:37017 64 0 25000

.diff() 은(는) 현재 serverStatus 필드 값과 이전 mongostat 호출의 값 간의 차이를 반환합니다. 다음 예제에서는 컬렉션에 삽입되는 문서 수에 대한 통계를 반환합니다. inserted diff 은(는) 후속 호출 간의 metrics.document.inserted 필드 차이이고 insertedmetrics.document.inserted 값입니다.

mongostat -o='host,mem.bits,metrics.document.inserted.diff()=inserted diff,metrics.document.inserted=inserted' --rowcount=5

이 경우 출력은 다음과 유사합니다:

host mem.bits inserted diff inserted
localhost:27017 64 0 25359
localhost:27017 64 94 25453
localhost:27017 64 938 26391
localhost:27017 64 964 27355
localhost:27017 64 978 28333

대부분의 경우 --discover 옵션을 사용하면 전체 머신 그룹의 상태에 대한 보다 완전한 스냅샷을 제공하는 데 도움이 됩니다. mongos 프로세스가 로컬 머신의 27017 포트에서 실행 중인 샤드 클러스터 에 연결된 경우, 다음 형식을 사용하여 클러스터의 모든 멤버로부터 통계를 반환할 수 있습니다.

mongostat --discover

옵션을 사용하여 --interactive 비스크롤 ncurses 에서 통계를 볼 수 있습니다. - 스타일 대화형 출력. --interactive 옵션을 사용하면 특정 호스트, 열 또는 필드를 강조 표시하여 볼 수 있습니다. --discover 와 결합하면 --interactive 는 다음 예제에서와 같이 복제본 세트 또는 샤드 클러스터의 모든 멤버에 대한 통계를 표시합니다.

mongostat --discover --interactive

그러면 샤드 클러스터의 출력은 다음과 비슷해집니다:

host insert query update delete getmore command dirty used flushes mapped vsize res faults qrw arw net_in net_out conn set repl time
hostname.local:27018 *0 *0 *0 *0 0 1|0 0.0% 0.0% 0 3.25G 25.0M n/a 0|0 1|0 157b 43.9k 19 tic PRI Nov 2 11:44:46.439
hostname.local:27019 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 3.18G 26.0M n/a 0|0 1|0 322b 44.4k 12 tic SEC Nov 2 11:44:46.439
hostname.local:27020 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 3.18G 26.0M n/a 0|0 1|0 322b 44.4k 12 tic SEC Nov 2 11:44:46.439
hostname.local:27021 2017 *0 *0 *0 826 1029|0 0.0% 0.0% 0 3.25G 31.0M n/a 0|0 1|0 1.74m 1.60m 20 tac PRI Nov 2 11:44:46.439
hostname.local:27022 *2021 *0 *0 *0 0 2|0 0.0% 0.0% 0 3.19G 32.0M n/a 0|0 1|0 322b 44.6k 12 tac SEC Nov 2 11:44:46.438
hostname.local:27023 *2022 *0 *0 *0 0 3|0 0.0% 0.0% 0 3.19G 33.0M n/a 0|0 1|0 323b 44.7k 12 tac SEC Nov 2 11:44:46.438
localhost:27017 2071 *0 *0 *0 0 2073|0 0 0B 2.43G 9.00M 0 0|0 0|0 249k 130k 4 RTR Nov 2 11:44:47.429
Press '?' to toggle help

버전 100.1.0의 새로운 기능.

AWS IAM 자격 증명을 통해 인증을 지원하도록 구성된 MongoDB Atlas 클러스터에 연결하려면 다음과 같이 connection stringmongostat에 제공하세요.

mongostat 'mongodb+srv://<aws access key id>:<aws secret access key>@cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' <other options>

이러한 방식으로 AWS IAM 자격 증명을 사용하여 Atlas에 연결하면 이 예와 같이 MONGODB-AWS authentication mechanism$external authSource가 사용됩니다.

AWS 세션 토큰을 사용하는 경우에도 다음과 같이 AWS_SESSION_TOKEN authMechanismProperties 값과 함께 제공합니다.

mongostat 'mongodb+srv://<aws access key id>:<aws secret access key>@cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:<aws session token>' <other options>

참고

AWS 액세스 키 ID, 보안 액세스 키 또는 세션 토큰에 다음 문자가 포함되어 있는 경우

: / ? # [ ] @

이러한 문자는 퍼센트 인코딩을 사용해 변환해야 합니다.

또는 다음과 같이 --username, --password--awsSessionToken 옵션을 대신 사용하여 AWS 액세스 키 ID, 시크릿 액세스 키 및 세션 토큰(선택 사항)을 각각 연결 문자열 외부에 제공할 수 있습니다.

mongostat 'mongodb+srv://cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' --username <aws access key id> --password <aws secret access key> --awsSessionToken <aws session token> <other options>

명령줄 매개변수로 제공되는 경우 이러한 세 가지 옵션에는 퍼센트 인코딩이 필요하지 않습니다.

표준 AWS IAM 환경 변수를 사용하여 플랫폼에서 이러한 자격 증명을 설정할 수도 있습니다. mongostatMONGODB-AWS authentication mechanism을 사용할 때 다음 환경 변수를 확인합니다.

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_SESSION_TOKEN

설정된 경우 이러한 자격 증명은 연결 문자열이나 명시적 옵션을 통해 지정할 필요가 없습니다.

참고

AWS 환경 변수를 사용하여 이러한 값을 지정하기로 선택한 경우 이러한 자격 증명에 해당하는 명시적 또는 연결 문자열 옵션과 조합하여 사용할 수 없습니다. 액세스 키 ID 비밀 액세스 키(사용 중인 경우 세션 토큰도 함께 필요)에 환경 변수를 사용하거나 또는 명시적 또는 연결 문자열 옵션을 사용하여 각각을 지정합니다.

다음 예시에서는 bash 셸에서 이러한 환경 변수를 설정합니다.

export AWS_ACCESS_KEY_ID='<aws access key id>'
export AWS_SECRET_ACCESS_KEY='<aws secret access key>'
export AWS_SESSION_TOKEN='<aws session token>'

다른 셸에서 환경 변수를 설정하는 구문은 다를 수 있습니다. 자세한 내용은 사용 중인 플랫폼의 설명서를 참조하세요.

다음 명령어로 이러한 환경 변수가 설정되었는지 확인할 수 있습니다.

env | grep AWS

설정이 완료되면 다음 예제에서는 이러한 환경 변수를 사용하여 MongoDB Atlas 클러스터에 연결합니다.

mongostat 'mongodb+srv://cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' <other options>

돌아가기

행동