Nginx monitor
為什么80%的碼農都做不了架構師?>>> ??
最近在初步研究了一下nginx的監控,主要是想監控一些和業務相關的信息,發現能用的方案不多,主要有如下:
1????監控解析nginx log:ngxtop
????? ? 官方的解釋是可以像top命令一樣,實時的解析你的nginx訪問日志。源碼在這里github ngxtop,官方給的例子很多,下面主要解釋一下ngxtop的參數:
Usage:ngxtop [options]ngxtop [options] (print|top|avg|sum) <var> ...ngxtop infongxtop [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 logand 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.范例: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$ ngxtop404前十的請求$ 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_refererAverage 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
????????在編譯nginx時添加--with-http_stub_status_module選項,在nginx.conf中開啟stub:
location /nginx_status {stub_status on;access_log off;allow 127.0.0.1;deny all; }
????? ? 不過這個只是一些簡單的統計,針對每個域名虛擬主機的統計卻沒有。
3? ? nginx plus
????? ? 很好很強大的商業版,有個內置的http_stub_status_module模塊可以統計每秒各種狀態、連接數等等。親自申請試用了一下,很贊。雖然用不起商業版的,但是在搜尋過程中發現了Server Density,這可是個好東東,雖然server沒開源,但是client開源了,而且有一大堆插件,可以拿來主義了,地址在:github density
4????python script monitor
????? ? 一系列python腳本,里面有監控nginx的腳本,地址:github script
轉載于:https://my.oschina.net/guol/blog/413629
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Nginx monitor的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C 与 JAVA 的对比分析
- 下一篇: Nginx支持比Apache高并发的原因