nginx實時監視訪問狀態(ngxtop)

發表于:2014-07-08來源:不詳作者:涼白開點擊數: 標簽:軟件測試
ngxtop實時解析nginx訪問日志,并且將處理結果輸出到終端,功能類似于系統命令top,所以這個軟件起名ngxtop。有了ngxtop,你可以實時了解到當前nginx的訪問狀況,再也不需要tail日志看屏

  ngxtop實時解析nginx訪問日志,并且將處理結果輸出到終端,功能類似于系統命令top,所以這個軟件起名ngxtop。有了ngxtop,你可以實時了解到當前nginx的訪問狀況,再也不需要tail日志看屏幕刷新。 1. 安裝ngxtop 1.1 源碼安裝

  # wget https://github.com/lebinh/ngxtop/archive/master.zip -O ngxtop-master.zip

  # unzip ngxtop-master.zip

  # cd ngxtop-master

  # python setup.py install

  ...省略....

  Finished processing dependencies for ngxtop==0.0.1

  //看到如上輸出表示安裝成功,安裝過程需要網絡支持 1.2 ngxtop安裝

  pip install ngxtop

  2. ngxtop使用詳解

  # ngxtop --help

  ngxtop - ad-hoc query for nginx access log.

  Usage:

  ngxtop [options]

  ngxtop [options] (print|top|avg|sum) ...

  ngxtop info

  ngxtop [options] query ...

  Options:

  -l , --access-log 需要分析的訪問日志

  -f , --log-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 , --interval report interval when running in follow mode [default: 2.0]

  -g , --group-by 根據變量分組 [默認: request_path]

  -w , --having having clause [default: 1]

  -o , --order-by 排序 [默認: count]

  -n , --limit 顯示的條數 [default: 10]

  -a ..., --a ... 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 , --config 運行ngxtop解析nginx配置文件

  -i , --filter filter in, records satisfied given expression are processed.

  -p , --pre-filter in-filter expression to check in pre-parsing phase.

  范例:

  All examples read nginx config file for access log location and format.

  If you want to specify the access log file and / or log format, use the -f and -a options.

  "top" like view of nginx requests

  $ ngxtop

  404前十的請求

  $ ngxtop top request_path --filter 'status == 404'

  總流量前十的請求

  $ ngxtop --order-by 'avg(bytes_sent) * count'

  訪問量前十的ip地址

  $ ngxtop --group-by remote_addr

  輸出400以上狀態嗎的請求以及請求來源

  $ ngxtop -i 'status >= 400' print request status http_referer

  Average body bytes sent of 200 responses of requested path begin with 'foo':

  $ ngxtop avg bytes_sent --filter 'status == 200 and request_path.startswith("foo")'

  使用common日志格式分析遠程服務器Apache訪問日志

  $ ssh remote tail -f /var/log/apache2/access.log | ngxtop -f common

  3. ngxtop實例 3.1 實時狀態

  # ngxtop -c /usr/local/nginx-1.5.2/conf/nginx.conf

原文轉自:http://huidu.lanxijun.com/articleDetail.html?id=19619&from=huidu&platform=android

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97