首页 > 数据库 > NoSQL > mongodb 日志分析工具mtools
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博客 ” ,链接:https://blog.itpub.net/28211342/viewspace-2213188/ ,如需转载,请注明出处,否则将追究法律责任。