利用ngxtop工具对nginx日志实时分析
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用ngxtop工具对nginx日志实时分析相关的知识,希望对你有一定的参考价值。
一、部署
准备:python2.7.3+、SQLite(否则会报错)
编译安装SQLite
cd /usr/local/src && wget #下载安装包,最新安装包请参考
tar xf sqlite-autoconf-3230100.tar.gz && cd sqlite-autoconf-3230100 #解压安装包
./configure --prefix=/usr/local/sqlite && make && make install #自定义路径编译安装
重新编译安装python
cd /usr/local/src &&wget #下载安装包,最新包请参考
tar xf Python-2.7.14.tgz && cd Python-2.7.14 #解压安装
配置setup.py中sqlite路径 qlite_inc_paths = [ '/usr/include', '/usr/include/sqlite', '/usr/include/sqlite3', '/usr/local/include', '/usr/local/include/sqlite', '/usr/local/include/sqlite3', '/usr/local/sqlite/include', ]
./configure --prefix=/usr/local/python2.7 && make && make install #自定义路径编译安装
安装ngxtop
pip install ngxtop
源码编译安装 wget https://github.com/lebinh/ngxtop/archive/1c200d51fbae7824a30159714669146d6b214210.zip unzip ngxtop-1c200d51fbae7824a30159714669146d6b214210.zip cd ngxtop-1c200d51fbae7824a30159714669146d6b214210 python setup.py install
二、使用
帮助help
# ngxtop --help ngxtop - ad-hoc query for nginx access log. Usage: ngxtop [options] ngxtop [options] (print|top|avg|sum) <var> ... ngxtop info ngxtop [options] query <query> ... Options: -l <file>, --access-log <file> 需要分析的访问日志 -f <format>, --log-format <format> log_format指令指定的日志格式 [默认: combined] --no-follow ngxtop default behavior is to ignore current lines in log and only watch for new lines as they are written to the access log. Use this flag to tell ngxtop to process the current content of the access log instead. -t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0] -g <var>, --group-by <var> 根据变量分组 [默认: request_path] -w <var>, --having <expr> having clause [default: 1] -o <var>, --order-by <var> 排序 [默认: count] -n <number>, --limit <number> 显示的条数 [default: 10] -a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output -v, --verbose 更多的输出 -d, --debug print every line and parsed record -h, --help 当前帮助信息. --version 输出版本信息. 高级选项: -c <file>, --config <file> 运行ngxtop解析nginx配置文件 -i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed. -p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase
示例:
ngxtop -c ./conf/nginx.conf -l ./logs/access.log top remote_addr request
参考:https://www.linuxprobe.com/real-analyse-nginx-ngxtop.html
以上是关于利用ngxtop工具对nginx日志实时分析的主要内容,如果未能解决你的问题,请参考以下文章