mongodb에서 slow query 로그를 출력할 수 있다. /etc/mongod.conf에 다음을 추가해야 한다.


operationProfiling:

  mode: slowOp

  slowOpThresholdMs: 100




slowOpThresholdMs의 디폴트 값은 100ms 이다.


mode의 디폴트값은 off이다. 

mode가 off 라면, 전혀 프로파일링 하지 않음

slowOp라면, 오직 slow 명령어에 대해서만 프로파일링한다.

on이라면, 모든 명령어에 대해서 프로파일링한다.



mongo 클라이언트에서 profile status를 확인할 수 있다.


replset:PRIMARY> db.getProfilingStatus()

{ "was" : 0, "slowms" : 100 }


위에 profile설정 (/etc/mongod.conf)를 수정하고 난 후, 재시작하고 mongo 클라이언트로 접속해서 profile status를 확인한다.


replset:PRIMARY> db.getProfilingStatus()

{ "was" : 1, "slowms" : 200 }



mongo 클라이언트에서 동적으로 profile level을 수정할 수 있다.


> db.setProfilingLevel(0,20)

> db.setProfilingLevel(0)




참고 

http://docs.mongodb.org/manual/reference/configuration-options/

http://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/

Posted by '김용환'
,