首页 > 其他 > 详细

利用ngxtop工具对nginx日志实时分析

时间:2018-04-11 17:01:45      阅读:210      评论:0      收藏:0      [点我收藏+]
参考:通过ngxtop实时监控webserver的访问情况


一、部署

  1. 准备:python2.7.3+、SQLite(否则会报错)

  2. 编译安装SQLite

    1. cd /usr/local/src && wget    #下载安装包,最新安装包请参考
    2. tar xf sqlite-autoconf-3230100.tar.gz && cd sqlite-autoconf-3230100  #解压安装包
    3. ./configure --prefix=/usr/local/sqlite && make && make install  #自定义路径编译安装
  3. 重新编译安装python

    1. cd /usr/local/src &&wget   #下载安装包,最新包请参考
    2. tar xf Python-2.7.14.tgz && cd Python-2.7.14  #解压安装
    3. 配置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',
      		    ]
    4. ./configure --prefix=/usr/local/python2.7 && make && make install #自定义路径编译安装


  4. 安装ngxtop

    1. pip install ngxtop
    2. 源码编译安装
      wget https://github.com/lebinh/ngxtop/archive/1c200d51fbae7824a30159714669146d6b214210.zip
      unzip ngxtop-1c200d51fbae7824a30159714669146d6b214210.zip
      cd ngxtop-1c200d51fbae7824a30159714669146d6b214210
      python setup.py install

二、使用

  1. 帮助help

    1. # 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
  2. 示例:

    1. ngxtop -c ./conf/nginx.conf  -l ./logs/access.log top remote_addr request

    

        参考:https://www.linuxprobe.com/real-analyse-nginx-ngxtop.html 


利用ngxtop工具对nginx日志实时分析

原文:http://blog.51cto.com/nanfeibobo/2096944

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!