ngxtop(nginx實時監控工具)


 

ngxtop(nginx實時監控工具)

 

安裝 ngxtop
yum -y install python-pip(如當前yum源不能找到python-pip,則新增擴展的epel-release擴展源:yum -y install epel-release)
 
pip install ngxtop(如安裝有問題:則 yum install python-setuptools)
 
使用ngxtop
 
1、
監控當前所指定的nginx的實時狀態(根據nginx.conf來進行指定所要監控的nginx信息,需注意:nginx.conf中所配置的日志產生路徑必須是絕對路徑,因為ngxtop是要找到對應的日志文件來進行分析而給出的實時結果)
    ngxtop -c /app/nginx-web1/conf/nginx.conf(默認展示10條信息,或者使用 -n 來指定所要實現的行數,-n 20 表示顯示20行)
 
如上所示:
    其中 74 seconds,表示當前已經監控的時長,單位秒;
    Summary:顯示所有的統計后總結信息;
    Detailed則展示的是所有的請求明細:request_path 表示當前所請求的路徑,count 請求的次數,avg_bytes_send 當前請求所返回的字節,2XX 表示當前請求的返回狀態(200等),3xx,4xx,5xx 等均表示當前請求路徑的狀態碼;
2、
設置只實時顯示,20個最頻繁的請求;
    ngxtop -c /app/nginx-web1/conf/nginx.conf -n 20
3、
實時 統計被請求最多的客戶端IP地址 remote_addr;以及統計各請求status狀態的數量 status;以及統計各請求在對應的時間段的請求數量,time_local
    ngxtop -c /app/nginx-web1/conf/nginx.conf -n 20 top remote_addr status time_local
 
 
 
OK,看完上述兩個使用方式后,接下來將會說明,ngxtop 的語法格式,和各個參數的意義;這樣在后續的使用中,就可以隨心所欲定制符合自身統計要求的實時展示了;
 
NGXTOP的用法格式如下:
 
語法如下:
 
 
    1、ngxtop [options]
    
    2、ngxtop [options](備注:參數) (print|top|avg|sum)(備注:內含的4個關鍵詞) <var>(備注:所要使用的變量:其中ngxtop內置的變量有bodybytessend,http_referer,httpuseragent,remote_addr,remote_user,request,status,time_local)
 
    其中print 表示自定義顯示的變量信息,如:ngxtop print remote_addr status http_referer(表示只實時輸出顯示,remote_addr(表示客戶端請求IP),status等信息)
    
    top 表示    
 
    3、ngxtop info
 
 
所對應的可選參數分別如下所示:
 
Options:
    -l <file>, --access-log <file>  access log file to parse.
    -f <format>, --log-format <format>  log format as specify in log_format directive.
    --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>  group by variable [default: request_path]
    -w <var>, --having <expr>  having clause [default: 1]
    -o <var>, --order-by <var>  order of output for default query [default: count]
    -n <number>, --limit <number>  limit the number of records included in report for top command [default: 10]
    -a <exp> ..., --a <exp> ...  add exp (must be aggregation exp: sum, avg, min, max, etc.) into output
 
 
    -v, --verbose  more verbose output
    -d, --debug  print every line and parsed record
    -h, --help  print this help message.
    --version  print version information.
 
 
    Advanced / experimental options:
    -c <file>, --config <file>  allow ngxtop to parse nginx config file for log format and location.
    -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.
 
可參考鏈接:
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM