mongodb 日誌分析工具mtools

kunlunzhiying發表於2018-08-30


mlogfilter 

slices log files by time, merges log files, filters slow queries, finds table scans, shortens log lines, filters by other atributes, convert to JSON

mloginfo 

returns info about log file, like start and end time, version, binary, special sections like restarts, connections, distinct view

mplotqueries 

visualize logfiles with different types of plots (requires matplotlib)

mlogvis 

creates a self-contained html file that shows an interactive visualization in a web browser (as an alternative to mplotqueries)

mlaunch 

a script to quickly spin up local test environments, including replica sets and sharded systems (requires pymongo)

mgenerate 

generates structured pseudo-random data based on a template for testing and reproduction



安裝過程


<pip 安裝>

yum -y install glibc-devel python-devel 

yum -y install python-pip 

yum -y install python-pymongo 

pip install mtools


<setup.py 安裝>


yum -y install glibc-devel python-devel


wget -O - ftp://ftp.no.sohu.com/pub/software/unix/Mongodb/utils/psutil-4.3.1.tar.gz | tar -zxvf - cd psutil-4.3.1


 python setup.py install 


yum -y install python-{ordereddict,argparse,dateutil,matplotlib,nose,pymongo,psutil} 

yum -y install numpy pip install --upgrade matplotlib 

wget -O - ftp://ftp.no.sohu.com/pub/software/unix/Mongodb/utils/mtools-1.2.1.tar.gz | tar -zxvf - cd mtools-1.2.1 

python setup.py install



使用說明


詳細使用說明請參考:URL見下文


mloginfo

對日誌中各類最常出現情況進行統計


# mloginfo mongod.log


統計客戶端連線次數


# mloginfo mongod.log --connections


統計各類資訊出現的次數

# mloginfo mongod.log --distinct


語句的執行次數、用時等統計資訊

# mloginfo mongod.log --queries


統計 MongoDB 程式的啟動資訊

# mloginfo mongod.log --restart


mlogfilter 過濾日誌


a.從某時間點開始顯示


mlogfilter mongod.log --from 2018 Apr 6 0:00 | head


b.檢視最後一小時的日誌

# mlogfilter mongod.log --from "end -1h" | head -n3


c.取某時間點後一個小時的日誌


mlogfilter mongod.log --from Apr 6 0:00 --to "+1h" | tail -n3


過濾表名

mlogfilter mongod.log --namespace serverside.user | head -n3


操作型別

mlogfilter mongod.log --operation update | head -n3


看連線數

mlogfilter mongod.log --thread conn3860


慢查詢

mlogfilter mongod.log --slow 600000 | head -n3


掃描數過多的查詢

mlogfilter mongod.log --scan | head -n3





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2213188/,如需轉載,請註明出處,否則將追究法律責任。

相關文章