정의
db.setProfilingLevel(level, options)버전 5.0에서 변경되었습니다.
mongod인스턴스의 경우, 이 메서드는 데이터베이스 프로파일러를 활성화, 비활성화 또는 구성합니다. 프로파일러는 실행 중인mongod인스턴스의 쓰기 작업, 커서, 데이터베이스 명령의 성능에 대한 데이터를 캡처하고 기록합니다. 프로파일러가 비활성화된 경우 이 메서드는 저속 작업이 진단 로그에 기록되는 방식을 구성합니다.참고
db.setProfilingLevel()이 포함된 프로파일링 수준의 변경 사항은 지속되지 않습니다. 서버가 다시 시작되면 이 값은0(기본값) 또는operationProfiling.mode설정이나--profile명령줄 옵션으로 설정된 값으로 되돌아갑니다.If the database profiler level is
1or2(specifically, the database profiler is enabled), the slowms and sampleRate affect the behavior of both the profiler and thediagnostic log.If the database profiler level is
0(specifically, database profiler is disabled), the slowms and sampleRate, affect only the diagnostic log.mongos인스턴스를 사용하면 이 메서드는slowms,sampleRate,filter구성 설정을 설정하여 진단 로그에 작업이 기록되는 방식을 구성합니다.mongos에는 프로파일러가 쓸 수 있는 컬렉션이 없으므로mongos인스턴스에 데이터베이스 프로파일러를 활성화할 수 없습니다.mongos인스턴스의 경우profile수준은0이어야 합니다.You can specify a filter on both
mongodandmongosinstances to control which operations are logged by the profiler. When you specify afilterfor the profiler, the slowms, and sampleRate options are not used for profiling and slow-query log lines.db.setProfilingLevel()provides a wrapper around theprofilecommand.MongoDB 부터는 명령 또는
profile래퍼 메서드를 5.0 사용하여 데이터베이스levelslowmssampleRatefilterdb.setProfilingLevel()프로파일러,, 또는 에 수행한 변경 사항이 에log file기록됩니다.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
중요
이 명령은 M0 및 Flex 클러스터에서 지원되지 않습니다. 자세한 내용은 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
The db.setProfilingLevel() method has the following form:
db.setProfilingLevel(<level>, <options>)
매개변수
Parameter | 유형 | 설명 | ||||||
|---|---|---|---|---|---|---|---|---|
integer | 데이터베이스 프로파일러 수준을 구성합니다. 사용할 수 있는 프로파일러 수준은 다음과 같습니다.
Because profiling is not available on | |||||||
문서 또는 정수 | 선택 사항. 정수 또는 옵션 문서를 사용할 수 있습니다. 문서 대신
|
반환
이 메서드는 해당 설정의 이전 값이 포함된 문서를 반환합니다.
{ "was" : 2, "slowms" : 100, "sampleRate" : 1, "filter" : { "$and" : [ { "op" : { "$eq" : "query" } }, { "millis" : { "$gt" : 20000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1 }
{ "was" : 0, "slowms" : 100, "sampleRate" : 1, "filter" : { "$and" : [ { "op" : { "$eq" : "query" } }, { "millis" : { "$gte" : 2000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1572991238, 1), "signature" : { "hash" : BinData(0,"hg6GnlrVhV9MAhwWdeHmHQ4T4qU="), "keyId" : Long("6755945537557495811") } }, "operationTime" : Timestamp(1572991238, 1) }
{ "was" : 0, "slowms" : 100, "sampleRate" : 1, "filter" : { "$and" : [ { "op" : { "$eq" : "query" } }, { "millis" : { "$gte" : 2000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1, "operationTime" : Timestamp(1572991499, 2), "$clusterTime" : { "clusterTime" : Timestamp(1572991499, 2), "signature" : { "hash" : BinData(0,"nhCquIxUw7thlrBudXe3PnsnvP0="), "keyId" : Long("6755946491040235540") } } }
구제척으로:
was는 이전 수준 설정입니다.slowms는 이전 slowms 설정입니다.sampleRate는 이전 sampleRate 설정입니다.filter는 이전 필터 설정입니다.note는filter의 동작을 설명하는 문자열입니다. 이 필드는filter도 있는 경우에만 출력에 나타납니다.
참고
filter 및 note 필드는 이전 수준 설정에 있었던 경우에만 출력에 나타납니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.
행동
경고
프로파일링은 성능을 저하시키고 시스템 로그에서 암호화되지 않은 쿼리 데이터를 노출시킬 수 있습니다. 프로덕션 배포서버에서 프로파일러를 구성하고 활성화하기 전에 이것이 성능과 보안에 미치는 영향을 신중하게 고려하세요.
잠재적인 성능 저하에 대한 자세한 내용은 프로파일러 오버헤드를 참조하십시오.
예시
프로파일러 활성화 및 저속 작업 임계값과 샘플 속도 설정
다음은 mongod 인스턴스에서 설정할 수 있는 값의 예입니다.
the profiling level to
1,the slow operation threshold slowms to
20milliseconds, andthe sampleRate to
0.42.
db.setProfilingLevel(1, { slowms: 20, sampleRate: 0.42 })
이 작업은 이전 설정 값이 포함된 문서를 반환합니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.
프로파일러 비활성화 및 저속 작업 임계값과 샘플 속도 설정
다음은 mongod 또는 mongos 인스턴스에서 설정할 수 있는 값의 예입니다.
the profiling level to
0,the slow operation threshold slowms to
20milliseconds, andthe sampleRate to
0.42.
db.setProfilingLevel(0, { slowms: 20, sampleRate: 0.42 })
이 작업은 이전 설정 값이 포함된 문서를 반환합니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.
프로파일링될 작업을 결정하기 위한 필터 설정
다음은 mongod 인스턴스에서 설정할 수 있는 값의 예입니다.
the profiling level to
1,
db.setProfilingLevel( 1, { filter: { op: "query", millis: { $gt: 2000 } } } )
이 작업은 이전 설정 값이 포함된 문서를 반환합니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.
프로파일러를 활성화하지 않고 필터 설정
You can set a filter without enabling the database profiler. The following example uses a filter with a profiling level of 0.
db.setProfilingLevel( 0, { filter: { op: "query", millis: { $gt: 2000 } } } )
프로파일링 수준이 0이므로 프로파일러가 비활성화됩니다. 및 일치하는 작업을 프로파일러 컬렉션에 기록하지 않습니다. 필터는 여전히 진단 로그에 적용됩니다.
이 작업은 이전 설정 값이 포함된 문서를 반환합니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.
필터 설정 해제
프로필 필터를 지우려면 filter: "unset" 옵션으로 db.setProfilingLevel()을 실행합니다.
db.setProfilingLevel( 1, { filter: "unset" } )
이 작업은 이전 설정 값이 포함된 문서를 반환합니다.
현재 프로파일링 수준을 보려면 db.getProfilingStatus()를 참조하세요.